This article was first published in the May 2016 issue of WIRED magazine. Be the first to read WIRED's articles in print before they're posted online, and get your hands on loads of additional content by subscribing online. For more ways to use your Raspberry Pi, click here.
There are lots of off-the-peg home automation kits, but for bespoke, the Raspberry Pi is up to the challenge. Tim Leland made his own using a set of radio frequency (RF) chips. After some experimentation, he used the general purpose input output (GPIO) pins as an RF transceiver, controlling two external transmitter (Tx) and receiver (Rx) boards.
For this project, you'll need a set of Etekcity remote switches, a set of 433MHz RF Tx and Rx chips (Leland used SMAKN brand chips from Amazon), a Raspberry Pi (any model with GPIO pins should work) and a power adapter for it. For the Rx board, with the pins pointing towards you, wire 5V to the leftmost pin, Raspberry Pi GPIO 2 to the pin right of that, and ground to the rightmost pin.
For the Tx, with the pins facing you, attach the Raspberry Pi GPIO 0 to the leftmost pin, 5V to the middle, and ground to the right pin. Ground and 5V are from the Raspberry Pi, and the pins may change if using a different Tx/Rx. To increase the range of your Tx, you can solder a wire to the antenna solder-point via soldering or, as Leland did, simply twist a 30cm length of CAT 5 cable in place.
Download Raspbian, and extract the .img file. Image an SD card with this operating system, and insert this into your Pi. Log on to your network via Ethernet or Wi-Fi (Pi 3), and enter "sudo apt-get install git-core". Install WiringPi by typing "git clone git://git.drogon.net/wiringPi". Install Apache by typing "sudo apt-get install apache2 -y", then install PHP with "sudo apt-get install php5 libapache2-mod-php5 -y". Remove the "index.html" file by typing "sudo rm index.html", then create a file called "index.php" by typing "sudo nano index.php". Type "git clone https://github.com/timeland/rfoutlet.git/var/www/rfoutlet".
To find out which six-digit codes are used for each outlet, go into the terminal and type "sudo /var/www/rfoutlet/RFSniffer". Record the codes as well as the received pulse value. If the value is different from 189, edit the codesend.cpp pulse value by typing in the terminal, "sudo nano /var/www/rfoutlet/RFSource/codesend.cpp". Change the line that says "mySwitch.setPulseLength(189)" to specify the pulse value you just obtained. Make sure you're in the "/var/www/rfoutlet/RFSource/" directory, and save the file by pressing "ctrl+x" then "Y" then press "Enter".
Compile by entering the command "sudo make codesend", then move and override the old codesend file by entering "mv f codesend /var/www/rfoutlet". Update toggle.php by entering "sudo nano /var/www/rfoutlet/toggle.php". Finally, enter "sudochown root.root /var/www/rfoutlet/codesend", then enter "sudo chmod 4755 /var/www/rfoutlet/codesend".
Navigate to the Raspberry Pi's IP address on your computer or other device (by either typing "ipconfig" on the Pi's command line, or by looking at connected devices on your router's page). Here you should find a web page with numerical labels and "on" and "off" selectors. If it's set up correctly, you will be able to control each of your connected outlets from this web page. This can be done from outside your network by opening a port on your router or through a virtual private network (VPN) for greater security.
This article was originally published by WIRED UK