Implement Philips Hue in your project
You might have heard about the Philips Hue? It is a connected light bulb controlled, locally or remotely, from an app on your iOS or Android device.
Lately people have shown interest in the product outside of its ‘commercial use’. The aim of this post is to shed some light (pun intended) on the possibilities of the Hue as well as getting started implementing it in a project.
The Hue is exclusive to the Apple Store and can be bought as a Starter pack or Single pack. The starter pack includes a bridge and three bulbs. A bridge can control up to 50 bulbs, hence the possibility to buy the single packed bulbs. These bulbs needs to be paired to the bridge of a starter pack. This is the way Philips intended its users to go about extending their collection of lights. However, if you for some reason have multiple starter packs, with bulbs connected to different bridges, it is possible to rewrite the pairing through a nifty little software called LampStealer. Note that while the app was made by Philips employees it is not an official Philips software.
The lamps plug into any standard light fitting and the bridge is connected to a local network. Lamps can be spread further away from the bridge due to the fact that they can communicate with each other through the Zigbee protocol. However, long distances may cause delay, since the signal needs to jump between bulbs. The easiest way to make sure the bulbs works is by downloading an app for a iOS or Android device. Play around with the colour picker or surprise the person next to you with a magic trick. While mesmerizing it gets old fairly quickly.
Programming the bulbs requires one part knowledge in setting up a host and one part knowledge of PHP script. If you do not have this knowledge, fear not! Follow these steps to set up an Apache host using XAMPP for OS X or Windows.
The Hue is still a young product. There is no official SDK, but the Hue community have open documentation of the API that can be of help. An example can be found here*. Note that details such as username and IP address have been replaced with “—————————————”.
The .php file is placed in the ‘htdocs’ folder(…/XMAPPP/htdocs/index.php). To test the setup use any browser and point to the URL (http://localhost/index.php).
The bulbs can be controlled saparately or in groups by extending the URL like such:
-
http://localhost/index.php?l=X-R-G-B-A-T
- X = Bulb (X targets all bulbs and 1,2,3 are specific IDs)
R = Red (0-255)
G = Green (0-255)
B = Blue (0-255)
A = Alpha (0-255)
T = Transition (0-10 seconds)
Turning the first bulb Red with half brightness over three seconds looks like this in Processing:
-
loadStrings(“http://localhost/index.php?l=1-255-0-0-127-3”);
At last, the Hue lamps can come off as expensive light bulbs, but if one trusts the dedicated development team it can be used for “very long”. That is 50 years of very long. If you dream of a ‘connected society’ or just want to play around with behavior of light it is a great opportunity to be on the frontier.
*Credits to Jurriën Gosselink and Niels Laute for providing the php script.