It’s useful to be able to turn mains electricity on using a computer program. Whilst it’s not hard to create an electronic circuit that can switch mains voltages, if not done correctly it can be dangerous. This is where the remote control sockets can be used to create a physical barrier between the low voltage electronic circuit and the dangerous high voltage electricity in the socket. Whilst it would be possible to create a radio transmitter to control the sockets yourself I wanted to keep this simple so that it is something that could be made easily by anyone. In an earlier project Home Automation using the Raspberry Pi I opened up a remote control and used relays to emulate a button press.
Energenie Raspberry Pi remote control board (Pi-mote)
Since I created the circuit by hard-wiring across the buttons on a remote control, Energenie has created a Raspberry Pi add-on board which allows one to switch power sockets on and off using the Raspberry Pi. The board is plugged into the GPIO port of the Raspberry Pi making it easy to send messages using software.
I bought the Raspberry Pi add-on board separate to the sockets which were in a pack with a standard remote control. I did hope to use the remote control and the Raspberry Pi to be able to control the same socket. This would allow me to use the Raspberry Pi for timed and/or Internet control, but then a traditional remote when that was convenient. In the sockets that I bought it appears to work with the Energenie Pi board or the remote control, but not both at the same time. I have been informed by Energenie that this should be possible, but I believe that I may have bought an older model of socket which does not support dual-remote controls. Fortunately there is a switch on the remote as well (which is useful if you’ve “misplaced” the remote, and it is possible to overcome the limitation by using the Pi-mote board configured as a virtual remote control (eg. on a mobile phone).
The products currently available from Energenie are sockets or a power strip, whereas some other suppliers also provide light switches which I found useful. The main advantage of the Energenie sockets is that this is the only supplier to provide this as an add-on board for the Raspberry Pi which is much easier and more reliable than hacking a remote control.
One thing about the Energenie remote controls is that I believe that all the remote controls (including the pi-mote) are registered using a unique identify code. Whilst this prevents having multiple controllers for each socket it does have the advantage that a neighbour using the same system cannot accidentally interfere with your sockets. I don’t believe it adds true security as it would still be possible to create your own controller board that monitors the wireless signal and then sends the same signals it does protect against accidental triggering. To do so would be pretty difficult and it’s unlikely that anyone would try and spoof a wireless remote control to turn your lights on or off.
I think that the Energenie product is much better than the one I was using before, dual remote feature is useful (included in new models) and it would be even better if there were some more home automation adapters in future (I have been told that there will be an extended range in future).
Adding an aerial
One thing I did do to the Energenie Raspberry Pi board was to add an aerial. Without the aerial the furthest I had it working was about 2 meters which is not particularly useful. The manufacturers state that it can have a range of up to 25 meters through open air. My limited range may be due to interference due to other signals; I do suffer from poor wireless signal strength in my house as well. Soldering a 135mm long piece of wire to the board extended the range considerably, this is easy to do as there is a hole for standard through-the-hole soldering.
The instructions for the Energenie includes some example python code. The code is not particularly easy to use so instead I used the Pi-remote code python module written by Amy Mather (whilst on work experience with Raspberry Pi foundation). This code makes it very easy to program the Energenie Pi-mote board using Python.
The power control web interface
I created a web interface which uses the python module mentioned above and the Python bottle web framework. The bottle web framework is a simple way to create a web application with a built in web server rather than needing a separate web server such as Apache.
To install the code first install the python-bottle package. Unfortunately the one supplied with Raspbian is an old version, but it’s easy enough to install using PIP.
sudo apt-get install python-pip
sudo pip install bottle
My web interface code can then be downloaded using
or: Download pi-power.tar.gz and copy it to the Raspberry Pi home directory.
Unzip the file using
tar -xvzf pi-power.tar.gz
change to the pi-power directory
cd pi-power and then run the software using:
This will start the web interface and you can then connect to interface using the IP address of the Raspberry Pi in a web browser (use
ip addr on the Raspberry Pi to find your IP address). It should be possible to connect from a Raspberry Pi, PC or mobile phone and click the appropriate button to turn the socket on and off.
You do need to register the socket with the controller (if not already done using the Energenie demo code). This may vary with different sockets; for the model I use involved starting with the socket in the off position (press green button until the LED is off) then holding down the green on/off button for a few seconds (until the LED starts flashing) and then using the on button on the remote.
Please note that there is no security included in the software I created. This means that anyone on the local network (eg. your home wireless network) can turn the sockets on and off. If you only provide WiFi access to your family then the WiFi passkey should be sufficient to protect your local network, but if you intend to make the remote control accessible over an insecure network (eg. the internet) then I recommend that you add an additional authentication step to the code.
As the pi-mote is controlled from the Raspberry Pi it would be possible to add other triggers to switch the sockets on and off. Using other software it would for instance be possible to use sound/voice activation (using an additional microphone) or with additional hardware based on the temperature of the air or of a liquid.
Whilst the pi-mote add-on board does not use all the pins of the GPIO port it does not make it easy to connect any other devices onto the GPIO board if using a standard model A or B. The model A+/B+ would be easier to add sensors as some of the higher GPIO ports could be used. An alternative (that the Raspberry Pi foundation used for a sous-vide project) is to create a PCB with a connector that the pi-mote can be plugged onto.
Using Engergenie sockets with the pi-mote Raspberry Pi add-on board makes it easy and safe to create a project that switch mains powered devices on and off. It does have some limitations including not being able to easily access the available GPIO ports, but the simplicity of connecting this to the Raspberry Pi is a big plus.