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.

763 thoughts to “Wireless Power Outlets”

  1. Hi Tim.

    Thanks for the great post and tutorial.
    Quick question: do you work, know or recommend a python library for this same approach?



  2. Hello,

    First of all, thank you for this awesome software and guide! We recently set this up at our office to control outlets via Slack. It’s amazing how simple it was to set everything up! The only issue we are running into though is that the outlets do not come on consistently. This seems to get worse when more than one rf outlet is used. We’re seeing this when we run our Slack command, but this is also the case when we run the command from the command line. It eventually fires, but it also sometimes doesn’t work. We also noticed that the RFSniffer is recording different pulse lengths whenever we use the remote. It usually ranges between 182 and 189. Could this be a problem since the toggle.php requires a specific pulse length? We also tested the outlets in close proximity to the Raspberry Pi and that doesn’t seem to make a difference. Also, we hooked up a light to the transmitter and it consistently lights up whenever we run the codesend command from the command line, but the rfoutlets don’t turn on consistently! Any ideas on this one? Thank you again for the great guide and software!

    1. Thanks glad you like it! Sounds like a neat project using it with slack. The rf outlets can be tough to trouble shoot bc they don’t respond if they’re on/off. You could try send the signal multiple times to get it to be more consistent. I’ve had trouble using the remotes and have had to press the button multiple times

      1. Hi Tim,

        Thanks for the reply. Just to be clear, when we use the remotes that came with the rf outlets, they consistently turn the outlets on and off. It’s only the the codesend command that is inconsistent with turning them on and off. It’s very strange because as I said, when a light is connected to the transmitter, it consistently turns on when the command is used on the CLI. We’ve tried adding multiple shell_execs to toggle.php but it doesn’t seem to make it better or worse. So strange! We’re so close to making it work…

          1. hello,
            how can I use /var/www/rfoutlet/codesend 12345678 in a python script with conditions??

            if somthing is true then /var/www/rfoutlet/codesend 12345678

        1. I followed this post and got the whole thing working on a new Raspberry Pi 3 in a few hours. Thanks Tim!

          The I got into the exactly same situation as Travis: While my remote control can turn on/off the outlets consistently, using ‘sudo ./codesend -l ' started failing. Even more strangely, the script has a higher success rate of turning off than turning on the device.

          It happened after I tried two things, not sure which one might've caused the difference: (1) I plugged in a second outlet, and (2) I installed HA Bridge and added one device.

          1. Great job for getting it to work! Can you try moving the pi and outlets closer to each other and ensure nothing could be interfering with the signal.

          2. Yes, it started working again once I moved the transmitter closer to the outlet. Guess I’ll need to add an antenna to extend the range. Do you know where can I find instructions on how to do it myself?

          3. I just used an old cat 5 cable wire and wrapped it around the antenna hole. Soldering would hold it more securely but mine has worked for years without soldering.

          4. CAT 5 wire wrapped around the antenna hole worked great. Now I can control my family room light from upstairs. Thanks again Tim!

  3. Hi Tim,
    in the mean time its working as following, still need to fine tune the script a little more.

    #!/usr/bin/env python3
    import datetime
    import os
    import pifacedigitalio
    from time import sleep

    while True:
    now = datetime.datetime.now()
    Now = now.hour * 60 + now.minute
    timewindow1_ok = (19*60+00) <= Now < (20*60+15)

    if timewindow1_ok : # valve 1
    os.system("/var/www/rfoutlet/codesend 11365380") # on
    sleep(1800) # time for sprinkler
    os.system("/var/www/rfoutlet/codesend 11365377") # off

      1. Yes, but I am still experimenting just with the switch and a LED until the code is working ok.
        Got the switch working yesterday (eMylo 6V).

  4. Hi
    Thanks for the great post!
    I wanted to control the power outlets through raspberry pi3 but not manually. Specifically, I want to feed in some code which tells the pi under what conditions it has to switch on the lights and under what conditions it has to switch it off.
    How do I make sure of that?
    Please help..

  5. I want to control the lighting of a room depending on whether or not there is someone present in the room. I am using a Raspberry Pi module and Octave for detecting people and want to control the lights without using a phone accordingly. How can I achieve that based on the information presented in this article?

  6. Hi,

    I’m following the instructions and having trouble getting RFSniffer to work. Each time I run RFSniffer with sudo /var/www/rfoutlet/RFSniffer, I get the following error:

    /var/www/rfoutlet/RFSniffer: symbol lookup error: /usr/local/lib/libwiringPi.so: undefined symbol: pthread_create

    I’ve done some searching online and I think the issue is with my compiler, but I’m a bit lost. Do you know what the source of this issue could be?

  7. I’m really having a blast with your library Tim!

    One thing that might be helpful for other newbies like myself is that both the transmitter and receiver *must* be wired up. Once I had recorded my outlet codes with my breadboard, I didn’t think I needed the receiver on my proto board. Spent a few hours running down my mistake 🙂

    Thanks to this, I’ll have internet-controlled sous-vide in a few hours!


      1. Hi Tim,

        Yes, the transmitter wouldn’t work without the receiver. Is that surprising? I can confirm later to make sure it wasn’t user error on my part if you’d like.



          1. You’re absolutely correct, the transmitter may not have been close enough during my initial testing. Cheers!

  8. Hi Tim love the project ! How can one do this project for 220v outlets (air conditioner) ? Which remote control works best to buy ?

    Thank you in advance

  9. I’m attempting to get this working and have been able to record the code and pulse from my RF receiver but have not had any success sending those codes with the RF transmitter. I bought these RF Outlets not the exact same ones but were on the same page. https://www.amazon.com/gp/product/B01N5JSAHM/ref=oh_aui_detailpage_o04_s00?ie=UTF8&th=1
    I may very well be doing something dumb but the codes that I’m getting from the remote are around 5330236 with a pulse width of about 180. Your guide has been pretty cool so far but it’d be nice to figure out my problem

      1. They are about 10 feet with line of sight. But I reseeded my wires in my bread board and magically it began working? Seems as though I will continue my endeavors to get homekit integration now.

  10. Hi Tim! I’m really enjoying playing around with this project, thank you so much for making it available to everyone! However, I am sort of stuck, I have followed your instructions step by step but I am stuck at a point where things are looking strange. First, whilst the Apache homepage loaded fine, after setting up php etc. along with the rfoutlet files, when I search “” I get Error 404 not found which is strange because when I go in the file browser and look under var then www then rfoutlet, all the files are there. Furthermore, when I type the command “./codesend 10176012 -l 172 -p 0” I get the response “bash: ./codesend: No such file or directory” which is kinda frustrating. I was really hoping that you could help me out as I’ve followed these instructions 3 times and keep getting stuck at the same point which is a shame because I was really enjoying the rest of it. I’m sure this hiccup is due to my lack of knowledge when it comes to Raspberry Pis and Linux operating systems and I would really appreciate some help from anybody. Thanks in advance, Tommy.

      1. Hey thanks for the reply! I’ve tried that out and it didn’t seem to make a difference. Not to worry though as I followed your guide to control the RF outlets via Homekit and that works perfectly! Thank you once again for providing this guide as it’s made a real difference to my home!

      2. Pulling up a bit of an older reply, but I’m having this same issue, tried it both using localhost/www/rfoutlet and without www on the PI and tried via IP on the PC, both get 404 not found. If I just go to the IP, I do get the apache page. any other suggests? I feel like I’m missing something obvious.

        Thanks for this, using it to hopefully jazz up my game room with a cool control panel

          1. No dice, still The requested URL /html/rfoutlet was not found on this server. Seems so close yet so far away, thanks for the quick reply. Open to any other suggestions and thanks again.

          2. That worked, copied to the wrong folder, missed the HTML.

            Next question, not directly related….I’m using it to toggle on/off video games in my basement, any idea on coding to get it where I can have picture 1 which powers on outlet 1 and then switches to picture 2. When picture 2 is pressed, it turns outlet 1 off and switches to picture one.

            Been hunting for several hours and tried a bunch of stuff but fail miserably.

          3. New question, I have a second set of outlets but they use a different pulse, is it possible to have it control more outlets but with a different setting?

  11. Hi Tim. I’ve gotten pretty far. I can press a button on the remote and view the signal in piscope: https://i.imgur.com/t9e5oJr.png (pulse length 335 us). And when I use codesend with a pulse length of 300+ it does show up in RFSniffer. However, RFSniffer does not show the codes from the remote (model APA3-1500R). Do you know what could be wrong?

    1. Sounds like it should be working. It could be the difference in the remote models. Another issue could be how close are the remotes to the receiver? Without an antenna, the range is limited.

      1. Hey I figured it out! RFSniffer doesn’t recognize the protocol used by klikaanklikuit brand outlets, but I have been able to record the timings of the pulses, and then reproduced the signal to toggle the outlet succesfully! The signal looks like pulses of 335us long, with long and short pauses in between, which seems to be a code of 64 bits long. I got the timings by making histogram of the durations between pulses. Here’s the programs I made to record and send the codes:


  12. Tim,

    Great article. I’ve actually followed this myself and have it running. I’ve gone a step further and integrated this with my Google Home. All I have to do is say “Turn on my living room lamp” and it will power on my lamp. To do this I created my own applet using https://ifttt.com/ .. google assistant and webhooks. (it basically runs the publicly accessible php code, I made a separate php for each codesend)

    It makes a fantastic addition to the home. I’ll be following your articles for more great projects. You are very creative. Feel free to reach out to me if you want more details about how I got this to work with my Google Home Mini.


  13. By installing task spooler
    sudo apt-get install task-spooler

    and prefixing “tsp” to the command line statements, the raspberry will be able to handle multiple simultaneous requests much better. It basically queues them up and makes sure only one runs at a time.

  14. Great article, and bravo for still replying to comments three years later. Are there any modifications from your original design that you recommend? I see a lot of comments with different tweaks too, I wonder if you have considered writing an updated version of this article addressing some of those ideas?

    FYI your ‘backup link’ for the RF chips is to an Amazon product that is no longer available.

    1. Thanks! My outlets still work great and accomplish everything I need them to do. I am working on another project using the 433mhz and temperature sensors. I’ll update the link.

  15. Great work. I started with another similar post but noticed your name in the link to rfoutlet. Following your procedures did the trick. I do have a question – must I keep the Pi linked by ethernet? It doesn’t seem to work with a wifi connection alone, and I know the wifi connection works because I can access the pi through putty with the ethernet disconnected. TIA for an answer.

      1. Thanks. I should have phrased my question better. I see two hassbian connections in my browser web interface, one for wired, the other for the wireless, different IPs. So I believe it’s at least partially working. My real question is how to use just the wireless connection for my rfoutlet control and not have to be wired to my router/switch. Do I need to edit one of the configuration files? If so which one and how. Thanks for your reply and Happy New Year.

          1. Thanks. Worked this time, don’t know why it didn’t work earlier. Probably something to do with the WiFi router I just replaced.

            BTW, I’m going to setup a Plex server on another Pi 3, not running hassbian. Where might I find instructions on how to replicate my current home assistant switch setup on a non-hassbian flavor? That way I won’t have to use a Pi as a dedicated computer just for the RF switching.

  16. Hey Tim,

    For the receiver (Rx) to Pi hookup, could you clarify the diagram? I don’t understand what to do with the two center pins.


  17. Hey Tim,

    Excellent write up! Earlier this week I was able to get this up and running and was able to turn my lights on and off via http:///rfoutlet/ when I was on Raspbian Wheezy. I just upgraded to Raspbean Jessie through a clean install, and am able to turn the lights on and off via the command line, and I am able to view the index.html page at http:///rfoutlet/ but when I select the buttons, nothing happens. I also made sure to use /var/www/html/ for all command line prompts. I am not sure what I am missing here, and was wondering if you had any suggestions as to what the problem might be?


          1. Hi Tim, I checked and I am not seeing any errors in the developers tools. Also when selecting Network in dev tools and pressing a button, I see that toggle.php is running, but nothing happens at the physical outlet. I am able to view the same information on my laptop that is connected to the local network, and see the same result. Through the command line I am able to turn the outlets on and off, using ./codesend command you mentioned in your write up.

            I put the SD card that has Wheezy installed on it in, and checked the dev tools and I am not seeing anything different between either of the two, except that I can control the outlets via the localhost/rfoutlet on the Wheezy installed SD card, and not on the Jessie installed SD card. I also followed through with the full installation via your write up for both, I didn’t copy over any files.

            Sorry for all the questions, I am throughly confused. Thank you for your time!

          2. Since you can call codesend from the command line but not php it most likely is a permission error. Take a look at step 7 and make sure you set the permissions correctly for codesend.

          3. I re-ran the commands in step 7, without error, although I am still not getting a response from the browser. I do get an error when attempting to run:
            [email protected]:~ $ ./codesend 349635 -l 188 -p 0
            bash: ./codesend: No such file or directory
            But when I go to the directory and run the command it works:
            [email protected]:/var/www/html/rfoutlet $ ./codesend 349635 -l 188 -p0
            I double checked and this is true on the Wheezy SD card as well. Is there another permission required?


          4. Sounds like it should work. You could try manually calling the codesend program from php directly in the command line. That may tell you an error.

          5. I can give that a try, sorry I am not sure how to manually call the codesend program from php, what command should I use? I am very new to this, thanks again for your help!

  18. Alright everything is working wonders – I have new $codes from RFSniffer and an updated PulseLength, but when I run ` ./codesend 5527308 -l 194 -p 0` from the command line on my pi, I get a bash error of No Such File or Directory. Any guess?

      1. My apologies, I had PHP installed, removed it for something else, and forgot to put it back. Everything seems to be working as you had intended it. Great work by the way. Now to set it up with an Amazon Echo and Siri.

  19. Very nice tutorial although I have one problem: I cannot get the transmitter to turn on my outlet. RFSniffer picks up the signal from my remote, but not from the transmitter. I have placed the transmitter on top of my outlet to make sure any signal doesn’t get lost. I have a raspberry Pi B+. Since I use GPIO17 for the transmitter, I use “-p 0” in the codesend function. I am very confident that the wiring is correct. Any suggestions are highly appreciated. 🙂

Leave a Reply

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