Home automation using the Raspberry Pi
The idea is that we wish to control mains power devices using the GPIO (General Purpose Input/Output) pins on the Raspberry Pi. We would like to do this without using anything that involves wiring 240V AC (Opto-relays are available for those who wish to do this, but we want something that’s safe enough for everyone to use).
The kit used here use microwave senders and receivers to send packet trains which tell our mains plugs to switch on and off. The plugs have built in receivers and a remote control is usually used to switch the plugs on or off. We want to use the Pi to do the work.
Using Mains control plugs from dbtech 25 UKP for 5 from Amazon.co.uk. I wouldn’t necessarily recommend using the dbtech plugs. I’ve had two plugs go bad on me (stuck relays). I would recommend using the Homeeasy plugs instead which have a definite on/off state and appear to be of a better build quality: http://www.amazon.co.uk/Home-Remote-Control-Socket-Silver/dp/B003EGMFA0
Here is my code to control them using the same codes as the remote: http://reversemidastouch.com/code/homeeasy.zip Git Hub code
and 25 UKP circuit boards from Noisepower: http://noisepower.co.uk/mains-control-raspberry-pi/
Downloading the code
Direct from Noisepower: http://noisepower.co.uk/downloads/
If you want tng’s modifications to the code (list out the 1’s and zeros) http://reversemidastouch.com/code/NOISEPOWER.zip Git Hub code
tng’s main C program for toggling the dbtech is 1_on.c
Compiling the code
sudo apt-get install gcc make
Download the Broadcom bcm2835 library, build and install it.
gcc -o toggle -l rt ./1_on.c -l bcm2835
Running the code
The executable takes two arguments:
-
A set number (0..15) which is unique to the set of plugs you have ordered.
-
A plug number which is stamped on them (1..5).
Up to 80 plugs can be controlled from one board!
root@raspberrypi:/usr/local/bin# ./toggle 13 1 fixed is 1746944 x is 29009926 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110 1101110101010100000000110
(Sends a 25 bit string 16 times), which set 13, plug 1 recognises as it’s toggle code. The same string is repeated to help ensure that the signal is detected.
root@raspberrypi:/usr/local/bin# ./toggle 13 5 fixed is 1746944 x is 29011456 1101110101010111000000000 1101110101010111000000000 root@raspberrypi:/usr/local/bin# ./toggle 13 4 fixed is 1746944 x is 29010304 1101110101010100110000000 1101110101010100110000000 root@raspberrypi:/usr/local/bin# ./toggle 12 4 fixed is 1746944 x is 26913152 1100110101010100110000000 1100110101010100110000000 root@raspberrypi:/usr/local/bin# ./toggle 1 1 fixed is 1746944 x is 3844102 0001110101010100000000110 0001110101010100000000110
As can be seen, the first 4 bits determine the set number and the last 11 bits (the very last bit is not used) control the plug number.
Building a Django interface
Code available from tng, but deployment is outside the scope of this talk: http://reversemidastouch.com/code/django_plugsocket.zip
A cheaper option for those on very tight budgets and with more time
The Noisepower circuits use the 433MHz transmitters from cool-components.co.uk @ 2.75UKP http://www.coolcomponents.co.uk/catalog/link-transmitter-434mhz-p-810.html
The same codes as for switching the Noisepower board can be used, but the timings of the ones and zeros need playing with. I would recommend the Noisepower board as it’s simple to use and produces a nice clean signal. I would also recommend getting an oscilloscope or having lots of patience with Audacity and a line-in.
Discovering packet trains without an oscilloscope
433MHz receiver@ 3.30UKP http://www.coolcomponents.co.uk/catalog/link-receiver-4800bps-434mhz-p-867.html
On a traditional PC – with a line-in port.
# sudo apt-get install audacity
Run audacity, record from the line-in. Note that plugging into the Mic socket may destroy your PC/Sound card.
Zoom in using the spyglass on one of remote control presses:
A long up period followed by a short down period corresponds to a 1.
A short up period follwed by a long down period corresponds to a 0.
This translates to:
1101110101010100000000110
Which corresponds to our 13:1 Set:Plug. Wahey! Happy days. This could be handy…..
Expansion possibilites
Homeeasy plugs:
http://reversemidastouch.com/code/homeeasy.zip Each plug has an On and an Off state. My plugs look like this:
1ON = 1gap22213131232221312231313123 213 2221 1OFF = 1gap22213131232221312231313123 222 2221 2ON = 1gap22213131232221312231313123 213 2212 2OFF = 1gap22213131232221312231313123 222 2212 3ON = 1gap22213131232221312231313123 213 2131 3OFF = 1gap22213131232221312231313123 222 2131
433MHz, 315MHz and 868MHz are used for loads of home automation hardware – having learned how to sniff packets, it is possible to control central heating boilers, light switches. UPDATE: 30-Sep-2013. I got the boiler on /off codes working:
http://reversemidastouch.blogspot.co.uk/2013/09/work-in-progress-controlling.html
All the code here and for controlling boilers is now in github:
https://github.com/tommybobbins/Raspi_433
Loads more exciting possibilities exist: http://jeelabs.org/ 315MHz receiver http://www.coolcomponents.co.uk/catalog/link-receiver-4800bps-315mhz-p-901.html