- Learn Linux
- Learn Electronics
- Raspberry Pi
- LPI certification
- News & Reviews
I get fed up with having to crawl under the Christmas tree and getting to turn the tree lights on and off, so this year I decided to use a remote control socket so that I didn't have to crawl under the tree. But why stop there when I could control it from a computer instead? So this year my Christmas Tree turns on fully automated, with wireless manual override from a smartphone. This is achieved using a Raspberry Pi and an Energenie Pi-mote electrical socket remote control.
The pi-mote plugs into the back of the Raspberry Pi and then sends commands using a wireless signal to the power sockets.
I have written my own web app using Python which allows the lights to be turned on using a simple remote control interface that can be accessed on a computer or mobile phone on the local wireless network (see Raspberry Pi Energenie blog post). With suitable configuration on your wireless router you can even add the Christmas Tree to the Internet of Things (IOT) so that it can be controlled from anyway on the Internet. I have not added any authentication to the page though, so if you do connect it to the internet then anyone could potentially turn your Christmas tree lights on and off. There's not much risk with Christmas Tree lights, but you wouldn't want to allow anyone to control anything more important without first verifying who they are.
I added a second power socket which is located in the garage and turns all the outside Christmas lights on and off. These can be turned on separately using switch number 2 (so that the Christmas tree lights can be on during the day when the outdoor lights are not), or all at once using the all devices option (switch 0 in the code).
I have also added another socket which is registered to button one. This third socket is in my daughters bedroom and means that the Christmas tree in her bedroom turns on and off at the same time as the tree downstairs.
Download the code from pi-power-0.1.tgz. Extract the files using
tar -xvzf pi-power-0.0.2.tgz
follow the rest of the instructions in the included install.txt file to copy the appropriate file to the startup directory.
As well as being able to control the lights from the app it's possible to automatically turn the lights on and off on the Raspberry Pi using crontab. This uses the same web app and a command line tool wget to 'download' the page that requests the appropriate action. I have used this to turn the lights on automatically in the mornings and off in the evenings. You can even add different rules to turn the lights on at different times on weekends vs weekdays or on specific days (eg. Christmas day).
The following shows some simple rules to turn the lights on and off automatically.
# m h dom mon dow command 0 8 * * 6-7 wget -O/dev/null http://127.0.0.1/switchon?socket=0 30 15 * * 1-5 wget -O/dev/null http://127.0.0.1/switchon?socket=2 0 23 * * * wget -O/dev/null http://127.0.0.1/switchoff?socket=0 0 9 * * * wget -O/dev/null http://127.0.0.1/switchoff?socket=2
Note that the -O option (capital o) is used to output the download to a file. In this case /dev/null is used which effectively means "save it no-where".
The Energenie sockets provides a convenient way to control the Christmas Tree and outdoor Christmas lights without having to get to sockets in awkward to reach places. It can also be automated to turn the lights on and off at certain times.
More details and latest updates are available from Raspberry Pi Energenie power project page.