Things Gateway, Part 4 - Philips Hue

In this series of postings, I've been setting up, configuring and playing with the Things Gateway from Mozilla.  In Part 1, I talked about my history of controlling devices in my home, while in Part 2 and Part 3, I configured the Things Gateway to control Zigbee and Z-Wave devices.  Today, I boldly enter the world of Philips Hue.
"Never trust anything that can think for itself if you can't see where it keeps its brain."  -- Arthur Weasley: Harry Potter and the Chamber of Secrets, by J K Rowling

I have, heretofore, stayed away from commercial Internet connected smart home products.  It is a matter of trust and I do not grant most manufacturers my trust.

The Philips Hue ecosystem of lights is a fine example.  Their products are both intriguing and expensive.  When it comes down to it though, it is a black box I don't trust.  Philips makes their bulbs tough to use if you do not also purchase the Philips Hue Bridge: a central hub to control groups of Philips Hue products. 

However, if you accept the black box nature of a Philips Hue Bridge, you can still get the lights to work with the Things Gateway through that bridge.  (There is a sneaky way to get Things Gateway to control Hue Bulbs without the Hue Bridge, I'll cover that in the next blog post.)

Goal: Create an instance of the Things Gateway running on a Raspberry Pi that can control Hue lights through a Hue Bridge.  For this posting, I'm giving up on complete isolation of the project from the Internet but I'm not explicitly going to use Internet connectivity.

Requirements & Parts List:

Item What's it for? Where I got it
The Raspberry Pi and associated hardware from Part 2 of this series minus the DIGI X-stick this is the base platform that we'll be adding onto from Part 2 of this series
Philips Hue White and Color Ambiance Bulb Starter Kit This is the Hue Bridge with four bulbs to control Amazon
An iOS or Android phone or tablet The setup of the Hue Bridge requires you to run a controller app I used my existing Android Tablet

Step 1:  This tutorial, I'm not going to build on the Zigbee & Z-Wave version of the Things Gateway of the last tutorial.  Instead, I'm going to set up a Things Gateway that only controls the Hue Bulbs.  In the next tutorial, I'll integrate the Hue Bulbs with the Zigbee & Z-Wave project.

So for this first step, I need a newly created Things Gateway on a Raspberry Pi.  I start at Step 1 of Part 2 of this series and proceeded through Step 6.

Step 2:  I followed the instructions in Philips documentation to set up my Bulb Starter Kit.  When asked to create a MyHue account, I declined.  This means that I cannot control my bulbs with the Hue App when I am away from home.  However, when my phone/tablet is home and connected to my local WiFi network, the Hue App works fine.

Step 3: Going back on the to Things Gateway on a Web browser, I entered "gateway.local" in the URL bar.  The next objective is to enable the add-on for the Hue bridge.  I drilled down  Menu -> Settings -> Add-ons and pressed the "+".


Step 4: I scrolled though the list and selected "Philips Hue".


Step 5: After successfully adding the add-on that support the Hue Bridge, I backed out one level (using the left arrow in the upper left), and then selected "Adapters".  This showed me that the Hue Bridge had already been detected:


Step 6: Now we're ready to link the bulbs with the Things Gateway.  I backed out again using the left arrow and then hit the "Menu" button (the three horizontal bars) in the upper left corner.  From there, I clicked on "Things".  That got me to the pane for adding devices.  I hit the "+" and then pressed the button on the top of the Hue Bridge.  That brought up a list of all the devices connected to the Hue Bridge: my four bulbs and a binary sensor called "Daylight".


I clicked "Save" on each one, and then pressed "Done".

Step 7:  I now had control of all four lights from both the Things Gateway and the Hue App on my tablet.  The bulbs can be turned on and off by clicking the icon of the bulb itself.  The color of the bulbs can be controlled by hitting the "splat" on the upper right of the bulb icon, and then clicking the bar in the left icon to bring up a color picker dialog box:


Unlike the Hue App, this dialog will not instantly change the color of the Hue bulbs as you rotate the wheel or specify a new color.  The "Select" button commits your color choice to the bulb.  If you find you don't like your new color, you'll have the press the color bar again and select a new color.

Step 8: Now that I've gotten the Hue bulbs talking to the Things Gateway, we can set up some rules to control them.  Unfortunately, as the Things Gateway software is still in its formative stages, the Rule System can only turn lights on and off, not adjust the color.  Don't worry, that ability is coming.

The first thing that I tried was the same silly looping circle of lights that I tried in Part 3 of this series.


The Hue Bridge is much faster than the previous example and didn't suffer the same pauses and glitches in behavior.

A more useful rule would be to take advantage of that "Daylight" sensor that was added along with the bulbs.   I had to use the Hue App to initialize the Daylight sensor by going to   Settings (the gear) -> Advanced -> Home location.  Now, supposedly, the Hue Bridge knows where I live and can calculate the sunrise and sunset times.

In the Things Gateway, I then created this rule:


Now when the sun sets, my Hue lamp #4 will light up.  I won't know for a few hours if it works as expected.  However, once I've seen what happens, I'll update this blog page.

What's Next?:

In my next part of this series, I'll show how to by-pass the Hue bridge entirely and just use the Hue lights themselves with the Zigbee adapter configured in Part 2 of this series.