I’ve mentioned elsewhere that I have a lamp timer and was finding it frustrating to have to manually change the on/off times throughout the year as the length of the day changes. One option I suggested using a computer to to give more flexibility and control.
Well I’ve been running with a setup that does use a computer for a few months now and it seems to be working well, so well that it’s controlling my Christmas lights too. In the end I didn’t wait for a Raspberry Pi (I already have a small Linux server that’s on 24/7, so just used that instead).
In my other article I posited using something like X10 to control it, but X10 plugs and controllers are fairly expensive. I had a set of three remote controlled plugs already and a bit of searching found that they could be controlled remotely. I got the set for free, but you can pick up similar ones in supermarkets and DIY places from as little as £5. Just be sure they adhere to one of the standards (such as Bye Bye Standby or Home Easy, which seem to be the most common in the UK). To send on and off signals I settled on a simple USB stick from a Swedish company to do just that.
The Transmitter
I opted for the Telldus TellStick, which isn’t cheap (though it’s the cheapest of their range), but it had good support on multiple platforms (including Linux) and saved me soldering or whatnot. It cost me £54.60 (inc VAT and postage) from Audon Electronics.
The unit is underwhelmingly small and looked a little disappointing when I opened the pack, but I plugged it in and followed the instructions to download and install the application and within minutes I was able to switch a socket on and off through the control centre software.
I was thinking of using the automation as an exercise to play about with Python, but I know PHP better and there seemed a fairly simple way to get that to work (plus I already had everything installed so could get a web front-end working no problem).
A few more minutes and I had a rough web page with some links I could click to trigger the socket. A static web page was never going to be enough for me though, so after a few quick scribblings to get my head around the design I knocked up a database to store the device details and some on/off timer settings.
Then I wrote a couple of simple functions to poll the timers’ table for any that were due, checked the current status of the device and switched it on or off accordingly. I set up a script to call these every minute using a cron job and voila I had a working timer.
A few more lines of code and I’d added functionality to support weekday, weekend and everyday timers so I could limit events appropriately. Continue reading…