-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhue.py
43 lines (35 loc) · 1.54 KB
/
hue.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
import requests
import time
if __name__ == '__main__':
# the base URL
base_url = 'http://192.168.0.201'
# if you are using the emulator, probably the base_url will be:
# base_url = 'http://localhost:8000'
# example username, generated by following https://developers.meethue.com/develop/get-started-2/
username = 'd4tyEfajszSSnyy8sy0Wi559yv8gdSCo-MwMDE2C'
# if you are using the emulator, the username is:
# username = 'newdeveloper'
# lights URL
lights_url = base_url + '/api/' + username + '/lights/'
# get the Hue lights (as JSON)
all_the_lights = requests.get(lights_url).json()
if type(all_the_lights) is dict:
# iterate over the Hue lights, turn them on with the color loop effect
for light in all_the_lights:
url_to_call = lights_url + light + '/state'
body = {'on': True, 'effect': 'colorloop'}
# to set the red color
# body = '{ "hue" : 0 }'
# more colors: https://www.developers.meethue.com/documentation/core-concepts
requests.put(url_to_call, json=body)
# wait 10 seconds...
for i in range(0, 10):
time.sleep(1)
print(10-i)
# iterate over the Hue lights and turn them off
for light in all_the_lights:
url_to_call = lights_url + light + '/state'
body = {'on': False}
requests.put(url_to_call, json=body)
else:
print('Error:', all_the_lights[0]['error'])