-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_bulb.py
33 lines (27 loc) · 1.12 KB
/
test_bulb.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
import rest
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://www.developers.meethue.com/documentation/getting-started
username = '5UsL1ptHh6tp2M0yDdJDXJtOG4J9UO1bYbhpz2Cd'
# if you are using the emulator, the username is:
# username = 'newdeveloper'
# lights URL
lights_url = base_url + '/api/' + username + '/lights/'
# get the Hue lights
all_the_lights = rest.send(url=lights_url)
print(all_the_lights)
#if (all_the_lights) is dict:
light_id = input()
url_to_call = lights_url + light_id + '/state'
body = '{ "on" : true, "hue" : 0 }'
# to set the red color
# body = '{ "hue" : 0 }'
# more colors: https://www.developers.meethue.com/documentation/core-concepts
rest.send('PUT', url_to_call, body, {'Content-Type': 'application/json'})
time.sleep(5)
body = '{ "on" : false, "hue" : 0 }'
rest.send('PUT', url_to_call, body, {'Content-Type': 'application/json'})