I just authored a cool little Gem that allows for automatic discovery of, and control over, the pretty nifty Phillips Hue lightbulbs. I decided to name it Huey, since I love nothing more than cute and silly names. I only spent a few hours tonight hacking it together, so I’m sure there’s a lot of room for improvement, but it works and does everything it’s supposed to and seems fairly fault tolerant; so I thought, why not announce it and fix problems when I wake up tomorrow?
Huey uses SSDP to discover the IP of the Hue hub the first time the code is run. I wish I could take credit for the EventMachine code that went into making this work correctly, but actually I largely cribbed it from Turboladen’s upnp library. I would’ve just included it as a Gem dependency but for some reason it’s not released as a Gem, which is pretty frustrating for situations like this.
I chose a pretty boring UUID for Huey to use:
'0123456789abdcef0123456789abcdef'. This works just fine, but if you want to change it Huey is ultra-configurable and you can do so either in a block or directly:
1 2 3 4 5
The first time you issue a request to the Hue hub, you’ll likely see an attractive error message like this:
Unfortunately, the first time any request is sent, Hue needs to validate the new client by you actually walking over and touching the link button on the hub. But once you do that, you can just resend the request and it should work fine. Then you can use the whole gamut of the Hue API:
1 2 3 4 5 6 7 8 9
I think Huey is pretty cool and I definitely intend to make a lot of use out of it. I’ll be updating it constantly as I do so to support more and better features, so follow the repository and let me know what you think.