-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
61 lines (43 loc) · 1.16 KB
/
index.py
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
from phue import Bridge
from time import sleep
from flask import Flask
# 100% = 254
bridge = Bridge('192.168.178.28')
ROOM = 'Room'
connected = bridge.connect()
state = bridge.get_api()
app = Flask(__name__)
LIGHTS = bridge.get_light_objects()
@app.route('/room-on')
def roomOn():
bridge.set_group(ROOM, 'on', True)
return 'on'
@app.route('/room-off')
def roomOff():
bridge.set_group(ROOM, 'on', False)
return 'off'
@app.route('/room-toggle')
def roomToggle():
if(bridge.get_group(ROOM, 'on')):
print('is on')
bridge.set_group(ROOM, 'on', False)
else:
print('is off')
bridge.set_group(ROOM, 'on', True)
return 'toggle'
@app.route('/room-up')
def roomBrightnessUp():
for light in LIGHTS:
light.brightness += 25
return 'brightness up'
@app.route('/room-down')
def roomBrightnessDown():
for light in LIGHTS:
light.brightness -= 25
return 'brightness down'
@app.route('/room-scene/<sceneName>')
def roomScene(sceneName):
bridge.run_scene(ROOM, sceneName)
return 'Running scene: ' + sceneName
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=9094)