-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlights.py
More file actions
executable file
·66 lines (54 loc) · 2.43 KB
/
Copy pathlights.py
File metadata and controls
executable file
·66 lines (54 loc) · 2.43 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
64
65
66
#!/usr/bin/python3
"""This module controls my Philips Hue lights."""
import sys # import system functions
from phue import Bridge # import Bridge from phue
BRIDGE = Bridge('10.0.0.215') # connects to the philips hue bridge
# If no arguments, print intro
if len(sys.argv) == 1:
print('\033[94m\033[1mConnected to Philips Hue Bridge\033[0m\n')
# Check light status, display right info
if BRIDGE.get_light(1, 'on') is False and BRIDGE.get_light(2, 'on') is False:
print('None of your lights are on.\n')
elif BRIDGE.get_light(1, 'on') and BRIDGE.get_light(2, 'on') is False:
print('Your kitchen light is on.\n')
elif BRIDGE.get_light(1, 'on') is False and BRIDGE.get_light(2, 'on'):
print('Your bedroom light is on.\n')
elif BRIDGE.get_light(1, 'on') and BRIDGE.get_light(2, 'on'):
print('All your lights are on.\n')
# Ask for lights to modify and how
WHICH = input('\033[1mWhich lights? (Both, Bedroom, or Kitchen) \033[0m')
STATE = input('\033[1mOn or off? \033[0m')
elif len(sys.argv) == 2: # if it has arguments, set them
STATE = sys.argv[1]
WHICH = 'both'
BRIGHTNESS = 255
elif len(sys.argv) > 2:
WHICH = sys.argv[1]
STATE = sys.argv[2]
try:
BRIGHTNESS = int(sys.argv[3])
except IndexError:
BRIGHTNESS = 255
except ValueError:
BRIGHTNESS = 255
if STATE == 'on' or STATE == '1' or STATE == '': # if on, ask for brightness
if len(sys.argv) == 1:
BRIGHTNESS = input('Brightness? (1-255) ')
if BRIGHTNESS == '':
BRIGHTNESS = 255
if WHICH == 'both' or WHICH == '2' or WHICH == '':
BRIDGE.set_light([1, 2], 'on', True)
BRIDGE.set_light([1, 2], 'bri', int(BRIGHTNESS))
elif WHICH == 'kitchen' or WHICH == 'kit' or WHICH == 'k' or WHICH == '1':
BRIDGE.set_light(1, 'on', True)
BRIDGE.set_light(1, 'bri', int(BRIGHTNESS))
elif WHICH == 'bedroom' or WHICH == 'bed' or WHICH == 'b' or WHICH == '2':
BRIDGE.set_light(2, 'on', True)
BRIDGE.set_light(2, 'bri', int(BRIGHTNESS))
elif STATE == 'off' or STATE == '0':
if WHICH == 'both' or WHICH == '3' or WHICH == '':
BRIDGE.set_light([1, 2], 'on', False)
elif WHICH == 'kitchen' or WHICH == 'kit' or WHICH == 'k' or WHICH == '0':
BRIDGE.set_light(1, 'on', False)
elif WHICH == 'bedroom' or WHICH == 'bed' or WHICH == 'b' or WHICH == '1':
BRIDGE.set_light(2, 'on', False)