Skip to content

Instantly share code, notes, and snippets.

@segphault
Created November 29, 2012 07:26
Show Gist options
  • Save segphault/4167366 to your computer and use it in GitHub Desktop.
Save segphault/4167366 to your computer and use it in GitHub Desktop.
Adjust brightness of Hue bulb
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