Wireless Power Outlets

Rf 433mhz raspberry pi

Thanks Wired MagazineLifeHacker & HackADay for featuring my post. If anyone has questions please leave a comment below and I’ll be happy to help!

Have you ever wanted to wirelessly control power outlets from your phone? You could buy a Belkin WeMo Switch for over $40 for 1 outlet or build your own with 5 outlets for under $35 if you already own a Raspberry Pi. Hopefully this post will guide you in the right direction.

Voice Control Outlets (Follow up Guides)

Hardware Needed:


  1. Connect wires to Rf transmitter and receiver chips(wiring diagram). See this article for more info on gpio pins. If you would like to use different pins check out Ninjablocks 433Utils   GPIO Pin Layout                                                                    
  2. Install Rasbian on Raspberry Pi (If using Raspbian Jessie use /var/www/html/rfoutlet for all paths below)
  3. Install Wiring Pi
  4. Install Apache and PHP on the Raspberry Pi
  5. Clone web files
    1. Make sure you have git installed. If not, type: sudo apt-get install git
    2. Type: sudo git clone https://github.com/timleland/rfoutlet.git /var/www/rfoutlet
  6. Use RFSniffer to find RF codes for your devices
    1. Type: sudo /var/www/rfoutlet/RFSniffer
    2. Record all 6 digit codes for on/off for each outlet
      1. Update toggle.php with your codes and pulse
        1. Type: sudo nano /var/www/rfoutlet/toggle.php
        2. If the Received pulse is different than 189, you should edit line 38 to your pulse length
        3. Edit lines 6-27 wth your codes
        4. If you’re using a different pin than 0, Edit line 35
        5. Use ctrl + x then “y” to save your file
  7. Change permission of codesend program so sudo isn’t required:
    1. Type: sudo chown root.root /var/www/rfoutlet/codesend
    2. Type: sudo chmod 4755 /var/www/rfoutlet/codesend
  8. You should now be able to turn the outlets on/off from the command line.
    1. Type: ./codesend 349491 -l 198 -p 0
    2. -l is for pulse length and -p is for different pins
  9. Browse to Raspberry Pi ip address ‘http://<your-pi-ip>/rfoutlet/ App demo
  10. Now you should be able to power on/off your outlets from a web browser. If you would like more range you can add an antenna to the transmitter chip. I cut a 12 inch wire from a cat 5 cable and it worked great.
  11. If you would like to schedule the outlets on or off you could use crontab. Here is an example to run everyday at 8pm.
    1. 00 20 * * * /var/www/rfoutlet/codesend “code number”

Let me know if you have any questions in the comments below.

Also published on Medium.

767 thoughts to “Wireless Power Outlets”

  1. Thanks for great little project.
    I was able to get this working on first attempt following step by step instructions. Only issue was the default web path being /var/www/html/rfoutlet required altering a few commands.
    Has anyone made progress to have codes sent by just calling web page using http get and json? I am looking to connect this to my SmartThings hub.

    Thanks again


    1. Absolutely. You’ll just need to modify the toggle.php to include additional codes, and add extra button commands to the web page.

  2. First of all, thanks for putting together a great article.

    I am a R-pi beginner and am trying to create a python program that controls my Etekcity outlets.

    I understand that once everything is setup, you use the codesend file & arguments to turn each outlet on/off (I believe).

    Is codesend a linux executable file? Would I be able to call it from a python script on my raspberry pi (or is there a better way to approach this..)?

    Any help/advice would be greatly appreciated!

    1. Thanks glad you like it! Yes codesend can be run just like any command line application. You should be able to call it from Python.

  3. Hi, guys I am in this green, I loaded everything i work with some pilots but I remotes which reads the code “1364 pulse 326” help as you type? Google translator.

  4. I have read elsewhere that you shouldn’t send 5V data signals to the Pi’s GPIO pins, however in your wiring diagram I didn’t notice any resistors or devices to drop the 5V signal to 3V before the GPIO. Should I add something in to drop the voltage?

        1. It looks like that receiver is different then then one I used in this guide. I’ve had mine running for over a year and haven’t had any issues.

  5. Help,

    I seem to have things operational manually. I am able to send the codes manually as long as I move to the directory first. Using ./codesend…… does not work unless I am in the directory /var/www/html/rfoutlet
    I believe that I have set all the permissions. The web page buttons are not functional. Any help with this would be great. Dogs keep eating my remotes so once I get this working no more need for the remotes!!!!

    Thanks again this is awesome

      1. Tim,

        Thanks for the quick response!!!

        You may have to stick with me here Im not sure what I should be looking for. I see that whenever i click the controls from the web page, the toggle.php is executing or at least it is added to the requests. When I manually enter the command i can toggle the switch. EX /var/www/html/rfoutlet/codesend 4199740 -l 189 -p 0
        But when I use ./codesend 4199740 -l 189 -p 0 this cannot see the file or directory. Not sure if that will help to narrow it down. Thanks again for the help

          1. Ok I have tried many variations of the $codeSendPath= ‘/var/www/html/rfoutlet/codesend’; $codeSendPath= “/var/www/html/rfoutlet/codesend”; all within the toggle.php file and none are working. As for the POST information for chrome development tools, i am not to sure how to see where it is completing step seven. I googled the post information and results tell me its the form data. When i click a button on the webpage i see the toggle.php come up and when i select it in the form data section i see OutletID = 1 OutletStatus = ON. Thanks again for your help with this. I am not experienced with coding and debugging side of these projects and looking to get a handle on this one to start learning more about it.

          2. Tim

            I got it working, I am a complete bozo ahah never followed ur directions and forgot to install the PHP when I did apache. Everything is working now. Just goes to show you gotta follow directions fully. Thanks for your support. Have a great day!!!

  6. In your research to do this, did you come across any 230v devices? I need to control a 230vac 13amp air conditioner.


  7. Hi Tim,

    I’m having a few issues transmitting the codes. I’m able to use RFSniffer to detect the codes for all of outlets, but I am having a horrible time getting codesend to work. It is very inconsistent and can take numerous attempts for the outlet to pick up the transmission. I have to run the command 20-30 times, and sometimes more, to get a single success.

    I’ve tried many of the basic debugging steps. I attached a 12in wire to the antenna hole. I’ve moved the transmitter within 6 inches of the outlet. Still, effectively no success.

    Could this be a issue with my transmitter, or is there something else I could try?

      1. Good afternoon Tim love the work you have done on this topic and the help you have given others I wonder if you or nay one else hear would help me with a project I am working on at the minuet ?
        I have you program running but was wondering if you have had any joy controlling the home easy sockets etc with the learn function? any help would be great thanks in advance.

  8. Hi Tim,

    First of all thank you for thia amazing tutorial !!!

    But I am geeting trouble with the sniffer’s part. I can’t get any output. I’ve tried why your pin and with other pins (btw I’ve chance the source code in those cases, according to wiringPi), but the reault is always the same…
    So after that, I was thinking that it was an hardware problem, but The transmitter is working, and I have nothing at home to test the Receipter…

    Have you any ideas about the problem origin ?
    I am using the raspberry Pi 3.

    Thanks for all, you’ve done a very nice work!

    1. If the transmitter is working, then don’t bother sniffing. Use my code above. Pick anything to start, and it will generate the rest for you. Then use the app and the button on the side of the outlets to reprogram.

    2. Thank you for a well-written article. I’m using the same receiver type that you show and am able to get wiring pi and rfssniffer running on a Pi 3. I’m a little confused about the GPIO 21/27 and what port that should be connected to on the Pi 3. I’m new to using a Pi and would really appreciate any advice.

        1. Again, really great job with this post, Tim!

          If anyone’s looking for the GPIO 21/27 on the Raspberry Pi 3, you need GPIO 27, pin #13 on the Pi 3 pin diagram here: http://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/
          GPIO 17 is pin #11 on the diagram.

          Also, if you’re using Raspbian Jessie, HTML files are served from /var/www/html not /var/www so you can just move the rfoutlet directory to /var/www/html.

          These may be very obvious suggestions but I’m new to the Pi and thought I’d point those out in case it’s helpful to anyone else.

  9. Hi Tim,
    I am not able to get RFSniffer to work at all.
    This is how i have connected RF transmitter and receiver in the breadboard:

    But after step 1-5, I’m stuck at the sniffer. It does not give any response. Just blank.
    Any idea what i could be doing wrong?
    I removed all wires and connected them again two times. Still no luck ( i also verified that the pre-requisites are installed fine)

  10. Hey i got the web page to work and i can manually put in the codes to turn the outlets on and off but i cant get the web page to send the commands, when i ran a log on the apache it says this : wiringPiSetup: Must be root. (Did you forget sudo?) im pretty new to linux but do i have to give permissions to wirepisetup and if so how?

  11. Hey I followed your tutorial and when i manually send in the command then the outlet works but when i try through the webpage it doesnt work. I check the apache log and it gives me this error : wiringPiSetup: Must be root. (Did you forget sudo?) . Does anyone have advice?

  12. Hi Tim,

    Nice project there. My issue is when running “sudo /var/www/html/rfoutlet/RFSniffer” I got:
    “/var/www/html/rfoutlet/RFSniffer: error while loading shared libraries: libwiringPi.so: cannot open shared object file: No such file or directory”. Any idea what i’m missing?

    Thanks in advance for your help.

    1. I ran the sudo /var/www/html/rfoutlet/RFSniffer command and opened the page at the same time. I tried pressing all buttons a few times and I could not see any output in rfsniffer. When running the command I just gives me an empty line and I have to exit with Ctrl+C, I don’t know if that is how it is supposed to work.

      1. Hey Tin, It’s hard for me to know if it’s the outlets or something is not configured correctly. When you run rfsniffer it just waits for it to detect a signal. Double check that everything is wired correctly.

        1. Is there a way to check if everything is wired correctly? I am using an rpi zero with jumper wires, so maybe one of the contacts went bad. Is there a command to check if anything is connected to the pins?

          1. I tested the setup on my Pi2 and it was working so it seems the pins on the zero weren’t snug enough. Anyway it is working now.

            Would it be possible to trigger a socket from my phone using a widget or a tasker action?

          2. Thanks, I’ll try that! I would also like to increase security, as I am using this to turn my pc on when I am not home. So far I managed to setup https using LetsEncrypt free SSL certificate service. Would it be possible to implement a required password, similar to how Jeremy Blum did it here? https://github.com/sciguy14/Remote-Wake-Sleep-On-LAN-Server/blob/master/index.php

            I have never written a single line of php in my life and I only have very basic HTML skills so I don’t really know what I am doing. At the moment I am struggling with letting the toggle.php file know that I entered the correct password. I added an if ($approved) { above the foreach ($codesToToggle as $codeSendCode) {

            I have a small php part in the index.html file that checks the entered password with the hash i provide (refer to lines 111 to 121 in the link above), but if i set $approved to true toggle.php still doesn’t recognise the variable. Does it have to be sent through the java script like data-outletId and data-outletState? If that is the case, how do I do that?

            Or am I getting it all wrong?

          3. You would have to send me your code so I can see what you are trying to accomplish. I would be careful exposing your pc or raspberry pi to the internet. I would write a script on your pi that checks an external source. When the external value is set to true, then the pi tries to turn on your pc.

  13. I ordered 2 sets of the EtekCity 5 packs and they both came with different codes so all unique

    just saying that they are not all the same all the time

  14. I may have missed the answer to this on here but just in case in order to get the more recent versions of wiringPi working as non-root with apache2 enter the following in the

    /etc/apache2/envvars file


    this solves the following error message

    wiringPiSetup: Must be root. (Did you forget sudo?)

  15. Thank you Tim.
    I have 2 rPis for rf control at different area with the same network.
    I’ve tried to connect two rPis through ssh auto login (ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.0.x).
    So ssh 192.168.0.x /var/www/rfoutlet/codesend xxxx is working.
    But web ui button for the other rPi is not working with the php file
    $output = shell_exec('/var/www/rfoutlet/codesend xxxx');
    echo "$output”;
    I assume this happens because of permission issue.
    Can you please advise me?

  16. Thank you Tim
    Can you please help me to control another raspberry pi rf through web ui?
    I’ve tried auto ssh with a command : ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.0.x (working in ssh)
    But failed with php on web ui :
    $output = shell_exec('sudo ssh 92.168.0.x /var/www/rfoutlet codesend xxxx');
    echo "$output”;

      1. Thank you for your reply.
        Do you mean the JavaScript as the file named script.js ?
        I am sorry I am not familiar to the script.
        So if you have some time in the future give me more details please.
        One raspberry pi should control not only it’s rf transmitter but also the others’.

        1. Actually each raspberry pi has different rf transmitter, one is 433mhz the other is 315mhz.
          At first I wanted two transmitters on one rPi but had no idea.
          I have made two rPis each. Each works fine with your instruction.
          Now I want one combined web ui.
          Thank you in advance.

          1. You could have your javascript post to both raspberry pi’s. Just add the ip address of the other pi. Or you could have the first pi send a request to the second pi using something like curl

  17. Man… this is a long and popular page.
    Can this be done with a normal Windows computer (with installed bash/linux subsystem)? I have an Intel NUC permanently on and would like to use that instead of investing for a Rasberry.

    Any help is appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *