Created
November 29, 2012 07:26
-
-
Save segphault/4167366 to your computer and use it in GitHub Desktop.
Adjust brightness of Hue bulb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, urllib2 | |
CLIENT_IP = "xxxx" | |
CLIENT_ID = "xxxx" | |
def build_url(endpoint): | |
return "http://{0}/api/{1}/{2}".format(CLIENT_IP, CLIENT_ID, endpoint) | |
def send(endpoint, value): | |
url = build_url(endpoint) | |
data = json.dumps(value) | |
opener = urllib2.build_opener(urllib2.HTTPHandler) | |
request = urllib2.Request(url, data=data) | |
request.add_header('Content-Type', 'application/json') | |
request.get_method = lambda: 'PUT' | |
output = opener.open(request).read() | |
return json.loads(output) | |
print(send("lights/3/state", {"bri": 0})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment