Philips makes a series of wireless controlled, multicolored light bulbs which I recently purchased. In the month or so I’ve had the bulbs I’ve fallen in love with them! It now seems fully old fashioned to have to get out of bed or off the couch to control the lighting, and even the different colors of white have a marked effect on mood and productivity for the task. Video conferencing is made more fun by always having a flattering shade at hand. As my apartment is fully wired music wise (6 sets of speakers able to be wirelessly controlled) the music has company. The LED lights are fully energy efficient, etc. etc.
Best of all, they have a great API integrated which makes them much more fun than your typical light bulbs for a computer programmer like myself. After plugging in the bridge, connecting it to my wireless router, and plugging in the bulbs I can control them fully with Philips’ native iOS client from my iPhone or iPad, where I renamed the bulbs. The app works via a REST API, and there’s an iOS SDK you can use to interact with this easily via Objective-C. The future of really is made of JSON! They also have an easy way to get started learning the API and controlling your bulbs straight from your web browser.
In this post I’ll give a shorter overview of what is gone through in great detail in Philips’ documentation. Discover your bridge’s IP address via a UPnP discover app, inspecting your router’s DHCP table, or conveniently http://www.meethue.com/api/nupnp. Then create a new user by POSTing with a body of
{"devicetype":"test user","username":"newdeveloper"}
to http://yourbridgeip/api via e.g. cURL or the conveniently provided console at http://yourbridgeip/debug/clip.html. Press the link button on your bridge, to confirm you have physical access, post again and you are ready to issue commands from http://yourbridgeip/api/newdeveloper (or whichever username you choose.
GETing http://yourbridgeip/api/newdeveloper/lights My bulbs look like this:
{ "1": { "name": "Bedroom" }, "2": { "name": "Office" }, "3": { "name": "Living room" } }
And we can look at a current state (just set all to blue) by GETing http://yourbridgeip/api/newdeveloper/lights/1
{ "state": { "on": true, "bri": 224, "hue": 46600, "sat": 254, "xy": [ 0.1727, 0.0512 ], "ct": 500, "alert": "none", "effect": "none", "colormode": "xy", "reachable": true }, "type": "Extended color light", "name": "Bedroom", "modelid": "LCT001", "swversion": "65003148", "pointsymbol": { "1": "none", "2": "none", "3": "none", "4": "none", "5": "none", "6": "none", "7": "none", "8": "none" } }
Really fun stuff! The first thing I noticed in the iOS app was the lack of a way to cycle the colors of the bulbs, but this functionality was present in the API under effect:colorloop no handrolling of loops required. Naturally as an iOS developer, I decided to modify the SampleApp included in the SDK to support a simple toggle ON/OFF to put each bulb in my house into the colorloop effect, and return it to its previous state when the “party” was over on a quick toggle. As you can see in this linked gist, the code was pretty simple due to the fact that Philips has a great Objective-C interface to the API.
You can see more, including a demo and a greater overview of hacking up the app in a short period of time in my YouTube video (sorry for the shaky camera work, I didn’t have a hacking partner in crime around to film):