Philips Hue Wireless LightingThis page shows how to use RESTful Web services to access to the Hue Led Lamps. OutlinePhilips Hue lights use a bridge to configure the lights, via a wireless connection. The bridge itself connects to an Ethernet connection on the wireless router. A user is added to /api/username, where username is the name of the user. If we try an invalid name we get: import json import requests import time ip="http://192.168.0.11" headers ={'Content-type':'application/json','Accept':'text/plain'} url = ip+'/api/fred' data ={'devicetype':'test user','username':'newdeveloper'} This will return: [{"error":{"type":1,"address":"/","description":"unauthorized user"}}] Now we can register the user with: import json import requests import time ip="http://192.168.0.11" headers ={'Content-type':'application/json','Accept':'text/plain'} # Setup new user r = requests.get(url) print r.text url = ip+"/api" r= requests.post(url,json.dumps(data),headers=headers) print r.text # Get information on lights url = ip+'/api/newdeveloper/lights' r=requests.get(url) print r.text As you will see, we need to press the button on the bridge to register the new user. Before we press the button we get: [{"error":{"type":101,"address":"","description":"link button not pressed"}}] {"1":{"state": {"on":false,"bri":254,"hue":0,"sat":0,"effect":"none","xy":[0.4350,0.4050],"alert":"none","colormode":"hs","reachable":true}, "type": "Color light", "name": "LivingColors 1", "modelid": "LLC010", "manufacturername": "Philips","uniqueid":"00:17:88:01:00:c2:2c:b6-0b", "swversion": "66009461", "pointsymbol": { "1":"none", "2":"none", "3":"none", "4":"none", "5":"none", "6":"none", "7":"none", "8":"none" }}, "2":{"state": {"on":true,"bri":254,"hue":1000,"sat":254,"effect":"none","xy":[0.6711,0.3236],"ct":153,"alert":"none","colormode":"hs","reachable":true}, "type": "Extended color light", "name": "Hue Go 1", "modelid": "LLC020", "manufacturername": "Philips","uniqueid":"00:17:88:01:01:13:46:17-0b", "swversion": "66014378", "pointsymbol": { "1":"none", "2":"none", "3":"none", "4":"none", "5":"none", "6":"none", "7":"none", "8":"none" }}} And then after it. The bridge returns: [{"success":{"username":"newdeveloper"}}] {"1":{"state": {"on":false,"bri":254,"hue":0,"sat":0,"effect":"none","xy":[0.4350,0.4050],"alert":"none","colormode":"hs","reachable":true}, "type": "Color light", "name": "LivingColors 1", "modelid": "LLC010", "manufacturername": "Philips","uniqueid":"00:17:88:01:00:c2:2c:b6-0b", "swversion": "66009461", "pointsymbol": { "1":"none", "2":"none", "3":"none", "4":"none", "5":"none", "6":"none", "7":"none", "8":"none" }}, "2":{"state": {"on":true,"bri":254,"hue":1000,"sat":254,"effect":"none","xy":[0.6711,0.3236],"ct":153,"alert":"none","colormode":"hs","reachable":true}, "type": "Extended color light", "name": "Hue Go 1", "modelid": "LLC020", "manufacturername": "Philips","uniqueid":"00:17:88:01:01:13:46:17-0b", "swversion": "66014378", "pointsymbol": { "1":"none", "2":"none", "3":"none", "4":"none", "5":"none", "6":"none", "7":"none", "8":"none" }}} Next we can configure the lights: mport json import requests import time ip="http://192.168.0.11" headers ={'Content-type':'application/json','Accept':'text/plain'} url = ip+'/api/newdeveloper/lights/2/state' try: while True: pdata = {"on":False, "sat":255, "bri":255,"hue":1000} r = requests.put(url,data=json.dumps(pdata),headers=headers) print r.text time.sleep(2) pdata = {"on":True, "sat":255, "bri":255,"hue":1000} r = requests.put(url,data=json.dumps(pdata),headers=headers) time.sleep(2) print r.text except KeyboardInterrupt: print "End" Demo |