Introduction
There is a remote power control solutionremote power control solution for home use by a company called Energenie, that provides radio-controlled mains socket adapters for UK use. These are intended for use with small radio-controlled handset, like a TV remote; I wanted the ability to use them with any microcontroller board. This is a short post about my findings. The aim was to control these sockets:
with this:
What about Europe, US, Asia, etc?
Unfortunately I don’t believe they have a product for some other regions (I could be wrong) – which is a shame. For other regions you may want to consider Watts Clever or Elro CoCo or Brennenstuhl products since colleagues here have already reverse-engineered these - a popular topic!
Raspberry Pi Control Board
A while back Energenie came out with a small board intended for the Raspberry Pi (RPI) (sold in a pack pack or separatelyseparately), to allow remote control directly from the RPI. They supply Python code to switch up to four sockets on and off independently. This is great, but sometimes you may want to use a different board other than the RPI.
I’m not familiar with Python, so it was interesting to try to understand the code, to make it platform agnostic. The information here should allow the Energenie RPI module to be used with any microcontroller dev-board in any language.
Hardware and Software Detail
The first step was to take a look at the Energenie documentation (PDF). They provided a lot of information; clearly the documentation is written by an engineer. It is great to see the level of openness. This is the block diagram from their documentation:
The next step was to look at the hardware. Here is a photo of the board:
Out of curiousity the circuit was examined briefly. There are two ICs on the board, and the datasheets are available on the Internet. An approximate circuit diagram from the two datasheets was created below; the left side shows the transmitter (containing a PLL locked to a fixed multiple of the crystal frequency – i.e. just a single channel), and the right side shows an encoder device to generate a stream of data. As can be seen, it is basic (but sometimes this is all that is required). It is better than some circuits which rely on lower-cost transmitters without a PLL to shave some cost. The dual-mode (ASK/FSK) capability is also nice.
The encoder has some values d0..4 brought out as signals as shown in the circuit above, but also some signals c0..19 are internally hardware-assigned a random value (the sockets can learn using a button on them). The diagram below shows the frame format from the encoder:
Based on this and the diagram in the Energenie datasheet it was straightforward to understand the circuit. Once a code has been set up on d0..4 (to select which socket needs to be powered on or off – there is a reference table in the Energenie documentation) then the Enable pin needs to go high briefly. The Mode signal is kept low (the sockets use ASK, not FSK mode). When the Enable pin goes high, the data is repeatedly burst out until the Enable pin is brought low.
How would one go about debugging this sort of thing? With an oscilloscope, the information between the encoder and the modulator could be probed. I didn’t perform any such capture due to lack of time. If you need to play with ready-built radio modules just to get going but are not interested in much detail, then a low-cost solution is to use a radio receiver (it could even be a $10 SDR dongle plugged into a PC); you’ll hear the output, and then you know that at least part of the solution is functioning to a degree. I was in a hurry and I didn’t use anything more exotic than a radio receiver. A low-cost used radio that covers useful spectrum can be obtained for about £40-50.
The next step was to create a small adapter cable (or just use jumper cables) to plug into the Energenie module, to allow it to be connected to non-RPI boards. I used a FRDM board as a quick test. Any board including an Arduino could be used (but make sure that the supply and signal levels are 3.3V, not the default 5V that the usual Arduino offers).
Finally the python code was translated. There is not much to it – it is so short it is self-explanatory.
Here is some example code which would work on FRDM boards; this code switches a socket on and off repeatedly. Refer to the Energenie documentation to see the d0..3 combinations for controlling additional sockets.
#include "mbed.h" #define sock0_on d3=1;d2=1;d1=1;d0=1; #define sock0_off d3=0;d2=1;d1=1;d0=1; DigitalOut d0(D0); DigitalOut d1(D1); DigitalOut d2(D2); DigitalOut d3(D3); DigitalOut mode(D4); DigitalOut enable(D5); DigitalOut led(LED_RED); int main() { mode=0; enable=0; wait_ms(100); while (true) { sock0_on; wait_ms(100); // apparently needed according to documentation enable=1; led = !led; // toggle led wait_ms(250); // transmit for 250msec enable=0; wait_ms(5000); sock0_off; wait_ms(100); // apparently needed according to documentation enable=1; led = !led; // toggle led wait_ms(250); // transmit for 250msec enable=0; wait_ms(5000); } }
With this code you can hear the socket switching on/off (i.e. there is presumably a relay inside).
Summary
This was just a quick post to show that using the Energenie module it is possible (in the UK and other countries with similar sockets) by directly interfacing to 3.3V logic circuitry or microcontrollers in order to safely control home mains power to appliances. This opens up possibilities such as using Arduino, TI CC3200 or BeagleBone Black or other devices rather than the RPI. To achieve a similar solution in other regions, check out the blog posts from mcb1, fvan and crosseyejack mentioned earlier in this post.