-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathlight_control.py
More file actions
63 lines (50 loc) · 1.34 KB
/
light_control.py
File metadata and controls
63 lines (50 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# import phue library
from phue import Bridge
import time
# add ip address of your router
ip_address = ''
#establishing connection
connection = Bridge(ip_address)
list_of_lights = connection.lights
#Switch on all lights
def switch_on():
for light in list_of_lights:
light.on = True
light.hue = 15000
light.saturation = 120
#Switch of all lights
def switch_of():
for light in list_of_lights:
light.on = False
#Toggle specific light
def toggle_light(name):
light = connection.get_light(name)
if light.on:
light.on = True
else:
light.on = False
#Set Timer to on or off
def setTime(hour,minute,On):
T = time.localtime()
curr_hour,curr_minute = T[3],T[4]
if curr_hour >= hour and curr_minute:
if On:
for light in list_of_lights:
light.on = False
else:
for light in list_of_lights:
light.on = False
#Dim light according to the time of day
def naturalLight():
T = time.localtime()
curr_hour = T[3]
if curr_hour >= 6 and curr_hour <= 18:
for light in list_of_lights:
light.on = True
light.hue = 15000
light.saturation = 120
else:
for light in list_of_lights:
light.on = True
light.hue = 150
light.saturation = 50