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                                                                       
  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.

722 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!

Leave a Reply

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