My wife's weather station had been crashing occasionally, and we are heading out on summer vacation soon, so she asked me for a way to power-cycle the weather station controller remotely. I already own some smart switch sockets, but they're controlled by a remote handset, not by a computer.

I researched hacks of these power outlets and did find some rather complex solutions that involved replicating the 433MHz radio protocol commands, but to put something together quickly I came up with a really simple hack: I simply wired a relay so that it straddled the push-button switch on the remote, and I simulated the button press by closing the circuit with the relay. The relay is connected to a Raspberry Pi which is a simple to use network-connected device that can drive the I/O pins needed to turn the relay on and off.

This seems almost too simple, but it really works! This technique ought to be easy to do with almost any handheld remote.

I know that I could avoid using a relay by driving one side of the button high or low with an appropriate voltage and a pull up or pull down resistor - but working out all the correct parameters and wiring is complicated, whereas adding a relay is easy.

For my wife's purposes, turning the power socket off and on via a linux shell command is quite sufficient, but it's also very easy to connect the Raspberry Pi to an Amazon Echo and control it by voice from within the house - FabricateIO's Instructable has all the details. It took just a few minutes to install the software and make a small mod to have it issue the shell commands to turn the socket off and on.

I've used an 8-channel relay module as I had one handy, but a two-channel relay module would be good enough. With the 8-channel board, I can actually use four of the five buttons on the remote and control four separate devices. This turns out to be a pretty cost-effective method of doing home automation with the Amazon Echo,

Step 1: What You'll Need...

Etekcity Wireless Remote Control Electrical Outlet Switch for Household Appliances, White (Learning Code, 5Rx-2Tx) - kit contains 5 outlets and two remote controls. (Usually $30. Sometimes discounted to $21.50)

8-channel relay module ($5) or 2-channel relay module ($1.50) Don't worry that these are all advertised as 5V devices. They'll switch just fine on the Raspberry Pi's 3.3V signal.

jumper wires ($1 - $2)

Raspberry Pi connected to your home network ($35 - $45)

Soldering equipment.

Step 2: Prepare the Remote

What you're doing here is simple and can be done on most remotes. Just locate the switch that is pressed and connect a wire to either side of the switch. I'm only going to do one device here, so I'm using 4 wires - two for the 'on' switch and two for the 'off' switch. If you want to control more devices, just wire up more switches.

A little reminder if you don't do a lot of soldering: put some solder on the ends of your wires before you try to attach the wires to the remote. (It's called "tinning" the wires.) When there's solder on both parts, they attach to each other much more easily.

If you'll look at this remote, you'll notice it's powered by a small 12V battery. It's not really obvious what voltage is used across the switches. An alternative to using a relay would have been to connect one side to Vcc or the other side to Gnd and to use a pull up or a pull down appropriately and of course you'll need an appropriate value of resistor for whichever connection is used. That is all doable, but it's complicated and every remote will be different - but by using a relay to physically emulate a button press, we know that whatever the logic is that is needed to activate the remote, it'll be correct!

Step 3: Connect the Relay

(Before you proceed, make sure you don't have any devices attached to your test outlet - you'll be switching it off and on a lot while you're testing)

For this project I just needed to control one device, however I happened to have an 8-channel relay module already, so I used that, giving me the option of adding three more devices later. (Each device has a separate on and off switch, so two relays are needed per device)

If I wanted to control all 5 devices that are available on the remote, I could add another 2-channel module, or I could have used just a 2-channel module (if I had one) to control one device.

The relay has a strip of pins with GND at one end and VCC at the other, and IN0, IN1, etc in between them. Connect GND to 0V on the the GPIO and VCC to 3.3V on the GPIO. Attach IN0 and IN1 to two free GPIO pins. I used BCM16 and BCM26 on my Pi2, but you can use any two GPIO outputs that you have free.

Your 8-channel module may have a jumper and another connector with GND/VCC on it. Leave it jumpered and do not connect those. They're for systems where the other VCC and GND and not strong enough to drive the actual relays - by removing that jumper you can use one pair of VCC/GND for controlling the logic and the other pair for driving the mechanical relays. You could if you wish use 5V for that purpose but to keep things safe and simple, I recommend ignoring the relay driving power and just use 3.3V on the default pins. (If this doesn't make sense to you, just ignore this whole paragraph)

Finally, note that these relays have 3 connectors each. Connect one of the two wires to each switch to the center of the three connectors. The other wire goes to the connector which is open-circuit when the relay is powered off. You can easily check which is which using an ohm-meter, but since there's only two to chose from it's easy enough just to try each. The worst case if you get it wrong is that the remote button will appear to be pressed all the time while you're testing, in which case just disconnect it. We're wiring these relays so that when the system powers up, the relays are not activated.

Step 4: Program and Test!

Create these three simple programs in /usr/local/bin (or write your own). There's a setup command you have to execute once (most easily by putting it in /etc/rc.local) and there are separate commands for 'off' and 'on'. I've named my commands "zap5" because the devices are labelled "Zap" (although that's not what they're called in the Amazon ad) and the one I'm using is on button #5.


# ON switch: BCM 16 (phys 36)
echo 16 > /sys/class/gpio/export 2> /dev/null
echo out > /sys/class/gpio/gpio16/direction
echo 1 > /sys/class/gpio/gpio16/value
# OFF switch: BCM 26 (phys 37)
echo 26 > /sys/class/gpio/export 2> /dev/null
echo out > /sys/class/gpio/gpio26/direction
echo 1 > /sys/class/gpio/gpio26/value


# press the on button for a second and then release
# 0 is circuit-made  1 is circuit broken
echo out > /sys/class/gpio/gpio16/direction
echo 0 > /sys/class/gpio/gpio16/value
sleep 1
echo 1 > /sys/class/gpio/gpio16/value


# press the off button for a second and then release
# 0 is circuit-made  1 is circuit broken
echo out > /sys/class/gpio/gpio26/direction
echo 0 > /sys/class/gpio/gpio26/value
sleep 1
echo 1 > /sys/class/gpio/gpio26/value

That is all you need to control the relay from the command line. However for a tiny little effort more, you can control it from an Amazon Echo as well!

Follow the instructions in FabricateIO's Instructable to configure your Raspberry Pi to impersonate a Wemo, and modify example-minimal.py as follows:

Near the top, add:

from subprocess import call

and then modify procedure 'act' to look like this:

def act(self, client_address, state):
         print "State", state, "from client @", client_address
         if state:
             # turn on
             # turn off
         return True

Run the python file and once your device has been located, issue the command "Alexa, turn on device" and "Alexa, turn off device"

It should work! (It worked for me, first time. Took literally 10 minutes to set up)

If you're away from home, connect in using ssh and issue "zap5-on" or "zap5-off" at the command line. (You may need to use 'sudo' - depends on your device permissions and what groups user 'pi' is in)

Step 5: Things to Watch Out For...

I mentioned earlier that sometimes it may be necessary to use the secondary power option on the 8-channel relay module. I actually had a problem related to that - the pi was making the light on the relay go off and on, but I never heard the click that meant that the relay had switched. However in my case, even by driving the relay from 5V power, I wasn't able to make it switch. The problem was that my Pi was being driven from the USB-out of my Frankenputer, and it didn't have enough power to run the pi, drive the relays, and operate the four other sensors I have attached to that Pi! I worked around the problem when I discovered that the two relays at each end of the strip worked OK even though the others did not, and the problem went away entirely when I moved the relays from the Frankenputer to a stand-alone Pi dedicated to this task.

Another problem I had was that even though I was successfully triggering the remote control, the power outlet was not going off and on. The fact that I could see the red light on the remote when the button was (virtually) pressed confirmed that the problem was not with the relays, but with the remote itself. It turned out to be a simple matter of what orientation the remote was held in (or in this case, taped in, on the lid of my Frankenputer). When I moved the whole rig to a stand-alone pi and placed the remote in a more sensible location, it started working beautifully. I'm fairly sure that the problem is in the 'lobes' of the remote's built-in radio antenna.

Anyway, I don't expect you'll hit these problems - this is actually a pretty simple build. I'm looking forward to hearing what uses other people can put it to.

Ordered an echo on prime day. Had a raspberry pi sitting around. I just got this working. Original idea was to mimic button presses on a scene remote control for my home automation system. Currently using to start my car. Using transistors to switch instead of relays so I don't have to worry about relay bounce. Want to attach to the scene controller now. I have multiple programs setup to run the different goip pins for each scene controller button, and they work from command line. How do I add more devices to call the scene programs individually from echo. Can't figure that part out. Was able to change the device name and add extra devices to run the same program.
<p>I upgraded my system a couple of weeks ago to support all 5 devices - the version of fauxmo.py at https://github.com/makermusings/fauxmo works fine with multiple devices.</p>
<p>this is a great project, I have been able to get it to work with the 2 buttons as in the instructions however I am at loss how to get all 5 devices to work, would you be willing to share your code?</p>
you might want to have a look at ha-bridge by Bwssystems
<p>I'll take a look at it, thanks</p>
<p>you might want to have a look at ha-bridge by Bwssystems. can create multiple devices through a nice Web GUI. much easer to use than fauxmo</p>
<p>I'm using the ha-bridge and it is quite easy. My setup is a Broadlink RM Pro, Raspberry Pi, Android device and Echo Dot. The Broadlink can reproduce the 433mhz... I plan on getting rid of those switches as they only control lights. Replace the switches with Cree Connected light bulbs since they are Echo supported and cheap. I also plan on getting rid of Broadlink and run ir from the Raspberry Pi. Have you checked out the Google Home?</p>
<p>Thanks, I'll look into ha-bridge. ( http://bwssystems.com/ , https://github.com/bwssytems/ha-bridge ) Also I found a device called 'Hook' yesterday (which I've already ordered!) that looks better than what I implemented at the same cost ($50) - they clone the RF signals rather than using relays: http://www.hooksmarthome.com/</p>
<p>Followup on the Hook after a couple of weeks of using it: Pro: you can control a _lot_ more devices with it; Con: it is nowhere near as reliable as the original remote at turning the devices off and on. The number of failed attempts is so high that I've just about given up on it and plan to revert to using my own design soon, possibly with mrlewis93's mod of using optocouplers and a Pi Zero to get the size down.</p>
<p>@gtoal: thanks for the fauxmo update link :)</p><p>I gonna try to get my setup working within the next days</p>
<p>Actually I haven't yet added a second device so I can't advise yet - it's something I plan to do but with other commitments it may be about a month or so before I can work on it. You'll probably have worked it out yourself before I do! One (rather poor) solution that springs to mind - if there isn't a more sensible one available - would be to attach multiple IP addresses to your Pi and determine which device to enable based on which IP address it was accessed under. Whether that could be done by one listener on all IPs or whether you would need multiple copies of the listener, I'm not sure.</p><p>Thanks for the heads-up on relay bounce - I guess it will be an issue for remotes where the key toggles something - with this remote it just reissued the same command, and two 'on's are still just an 'on'. The remote has separate on and off buttons.</p><p>By the way have you seen this? https://hackaday.io/project/6820-amazon-echo-voice-command-automation</p>
<p>Thanks for Instructions, but i have a problem.<br>I made the same changes like you<br>but when i do a &quot;Alexa, turn on device&quot; i get this error:</p><p>DEBUG:root:Listening for UPnP broadcasts<br>DEBUG:root:got local address of<br>DEBUG:root:UPnP broadcast listener: new device registered<br>DEBUG:root:FauxMo device 'device' ready on<br>DEBUG:root:Entering fauxmo polling loop<br>DEBUG:root:Responding to OFF for device<br>CRITICAL:root:Critical exception: act() takes exactly 3 arguments (4 given)</p><p>do you have any ideas why?</p><p>thx</p>
could you execute these commands please, so I can work out what the problem might be:<br><br>cd /usr/local/src/echo/echo-master<br>fgrep act\( *<br>
<p>Sorry for the poor photos, didn't want to disassemble it much further. So as I said I made this using optocouplers and managed to squeeze it all into this small project enclosure. In the box is a Pi Zero, with the power supply and WiFi adapter coming out from the side, and two small circuit boards. One of the circuit boards controls the 5 on buttons and the other controls the 5 offs. The GPIO on the Pi turns on the photo-diode side of the optocoupler with the photo-transitor side being used to short across the controller buttons when the Pi output is high. Using the optocouplers got around the problems I originally had using just transistors by keeping both sides of the circuit isolated with their own power supplies and grounds, instead of there being a common ground for both the controller and Pi. Finally I built the controller into the lid of the enclosure so that the controller buttons can be used to control the switches like a manual override should there be any problems with the Echo control. Thanks again for this tutorial, and hope this helps.</p>
<p>That's great! I'm looking forward to the day when Pi Zeros or equivalent are something you keep several of in a drawer for use in projects like this and are not premium items that are so hard to get hold of! (Really, having to get a single unit airmailed from the UK is just ridiculous). Using the Zero here has really made your version of this project much neater. Thanks for posting.</p>
This project is massively overkill. You can buy a 433mhz transmitter for &pound;2 and control that via your pi. It will do unlimited amount of remote sockets, much less wiring and only uses 1 GPIO pin for data transmit.
Depends where you want to put the effort in. *Building* what you suggest is trivial, I could do it in 10 minutes and in fact I do have the hardware. (transmitters and receivers for both frequencies, plus an SDR for debugging). However programming a system like that is quite another matter. I got the software for my system up in an afternoon. If I had to reverse engineer the remote control signals and duplicate them, I would imagine that would take considerably longer.<br><br>In point of fact, I recently bought a &quot;Hook&quot; system which is a professional implementation that does what you suggest. Originally I built this the relay way because it was a lot easier than learning how to generate the correct signals for the wireless; now I prefer that it uses the original remote, because it turns out that even the professionally implemented Hook is far less reliable than the original remote - there appears to be a problem duplicating the control signals accurately. When I turn on half a dozen lights with the Hook, it's very seldom that all of them turn on, whereas I've never had a failure with my own implementation.
<p>Great tutorial, I just got this working on a Pi Zero to control all five sockets using my Echo. I used the new version fauxmo.py to get it working with all five sockets, just simply gave them different names and ports, and added the necessary script to tell it which GPIO to use to turn each socket on or off. Instead of using relays though I used optocouplers, making the whole project much smaller and allowed me to fit all the circuitry into a small project enclosure. I even built the controller into the lid of the enclosure so that it could be used as a physical backup to turn the sockets on or off. Couldn't have done it without your tutorial.</p>
<p>I appreciate you letting me know - it makes the effort writing the project up worthwhile when someone actually builds your project! Any chance you could upload a photo of yours (with the &quot;I made one&quot; option) - I didn't know optocouplers were smaller - had assumed they were the same package as relays. I'ld like to see your compact version. I found an old 1960's mechanical switch controller (looks like an alarm clock) that I've gutted and am working on squeezing mine into!</p>
If you connected a bunch of these remotes in parrallel, so that one relay pushed the &quot;on&quot; on all the remotes, then used the other relays to connect and disconnect the remote power supply, you might be able to use 6 remotes with 8 relays! Good Job
<p>Yep, the idea is definitely expandable. I'd probably use something like http://www.ebay.com/itm/CD74HC4067-16-Channel-Analog-Digital-Multiplexer-Breakout-Board-Module-Arduino/121817976911?_trksid=p2047675.c100005.m1851&amp;_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D35389%26meid%3Da5d8654b1ec14a5b8c8036186854e900%26pid%3D100005%26rk%3D5%26rkt%3D6%26sd%3D161724821543 to select the remote...</p>
<p>In case anyone expands a system like this, that was the wrong board above - this is what I should have linked to: http://www.ebay.com/itm/262136732889</p>

About This Instructable




More by gtoal:Easiest RGB LED Strip With Raspberry Pi! Deleted Instructable Control any remote from a Raspberry Pi (and Amazon Echo!) 
Add instructable to: