by prof_hobart · 10y ago · 0 comments
I've got a couple of wifi-controlled Philips Hue lights. There isn't a simple "on" or "off" for these - they can be set to just about any colour and brightness. One, for instance, is set to wake my daughter up with an artificial sunrise over the space of about 15 mins in the morning, is off automatically during most of the day when there's no one in the house, and goes a very dim red at night.
As my wife has a habit of forgetting that they switch themselves off, she still fairly frequently physically switches it off at the wall. If it's still of at the point that the "dim for the evening" program is due to run, then it doesn't get triggered and I have to dig out my phone app to kick it off.
So I've just built a little switch using a Pi and a very cheap (in both senses of the word) touch screen running a web page with buttons on it that triggers various actions on the light such as setting the dimmer colour.
I'm waiting for the day when there's a cheap and good off the shelf switch that does this kind of thing properly for home automation.
But at a high level, it's pretty straightforward, and there's also almost certainly far better ways of doing it.
The key components are
- a Philips Hue light
- The Openhab[1] open source home automation server (currently running on an old Windows box that's always on for various other reasons). This controls the lights.
- Apache, also running on the same box. This provides a very simple web UI for the Pi.
- A Raspberry Pi - it's one of the original Pi model Bs.
- Firefox (Iceweasel version) on the Pi - the built-in one didn't seem to run the jquery that I needed.
- A cheapo touchscreen [2] attached to the Pi.
The OpenHab server has a plugin for Hue lights, and you can write scripts to make it do various things, such as switch on/off at a particular time, or on getting a command from somewhere else. It also has a REST API interface.
It's this API interface that the web app is calling. That's made up at the moment of 3 buttons (on, off and dim), and when one is pressed it sends a jquery REST call to the OpenHab server to trigger one of the commands. Technically, what it's doing is setting one of 3 OpenHab "buttons" to ON. This triggers the OpenHab rule to change the light.
The touchscreen attaches straight onto the Pi's GPIO pins. I pointed Firefox at the Apache on my server and set it to full screen mode. The screen's not great - it feels as cheap as you'd expect for £16 - but it works, and most importantly my daughter loves it.
Like I say, there's almost certainly better/simpler ways to achieve some of this - I suspect I could run the entire thing on the Pi for example, or replace the Pi with an old iPhone that I've got lying around. The OpenHab software also allows you to build a custom UI itself. But I like playing, and there's a bunch of tech things that I wanted to try out, and this seemed like a fun and useful project to test them out on.
My next plan is to get an Arduino and connect some dials to it to allow direct control of brightness and RGB.
[1] http://www.openhab.org/ [2] http://www.amazon.co.uk/dp/B00YE0UPES