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.

770 thoughts to “Wireless Power Outlets”

  1. Hi Tim,

    Great article and I’ve successfully set this up, I’m wanting to take it forward and wondered what config you had to put in your homebridge config.json for this to work and if any other steps were necessary? I’ve already got homebridge up and running on my pi I just need to combine these two together.


      1. Wow, thanks Tim. I’ve just had a quick look through your new article and this is exactly what I was trying to achieve. I’m off to have a play… 🙂

  2. My keyboard has alternate keys you can assign programs to. Here is a working C# thing that sends POST data to toggle stuff. Yall can download visual studio to compile it. Now I don’t even have to navigate to the webserver to toggle my lights and fan. Thanks Tim!

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices;
    using System.Net.Http;

    namespace ConsoleApplication1
    class Program
    static void Main(string[] args)

    static async Task mainasync()

    using (var client = new HttpClient())
    var values = new Dictionary
    { “outletId”, “4” },
    { “outletStatus”, “off” }
    var content = new FormUrlEncodedContent(values);
    var response = await client.PostAsync(“http://lights/toggle.php”, content);
    var responseString = await response.Content.ReadAsStringAsync();



  3. Hi nice guide!
    I have one problem
    1: I have 2 outlets with only 4 digits
    2: The RFSniffer gives me diffrent pulses everytime
    Can you please help me

    1. Thanks! Are you using the outlets from the guide? Is the pulse drastically different? Mine isn’t always the exact same number. You may just be able to use the average of all the numbers.

      1. on=
        Received 1361
        Received pulse 314

        Received 1364
        Received pulse 313


        Received 4433
        Received pulse 310

        Received 4436
        Received pulse 314

        Another controller
        on= 1381717
        Puls 438

        Received pulse 439

        Received 1381716
        Received pulse 438

        Received 1394005
        Received pulse 440

        Received 1394004
        Received pulse 438


        on 1066321



  4. I am getting ‘Not Found The requested URL /rfoutlet was not found on this server.’ error while trying to access /rfoutlet. I can get to without any issues. Any pointers would be greatly appreciated.

      1. I was following your post about integrating with google home via IFTTT and had to step back to the set of instructions on this page. The path to my /rfoutlet/codesend was not “/var/www/html/rfoutlet/codesend” which is what the subprocess was expecting it to be. Anyway, I ended up removing the apache2 install and have google home voice command working to control my rf switch. Thanks for the awesome instructions and for responding.

    1. Hi Aago, not sure if you still have issues with the index file not found.I fixed this issue by modifying the sites-enabled configuration file -> sudo nano /etc/apache2/sites-enabled/000-default.conf
      I replaced the DocumentRoot /var/www/html line 12) with DocumentRoot /var/www

      1. Hi Tim,

        I bought that set and connected them up, and i was able to use RFSniffer to receive the codes from my 315Mhz remote just fine:
        Received 13446
        Received pulse 1175
        Received 13574
        Received pulse 1176

        when i tried the following:
        $ ./codesend 13446 -l 1175
        Sending Code: 13446. PIN: 0. Pulse Length: 1175

        it would show up on RFSniffer, just as if i had pressed the remote, but not actually effect the outlet. I only had a 6″ wire handy for the antenna, so that is what i put on for the moment, but i put the outlet about 6 inches away from the antenna, so I’m thinking that isn’t the issue…

        i’m open to whatever suggestions you have!

          1. I’m not sure what this would accomplish, but i figured more data couldn’t hurt…

            i set up one pi with the receiver running sniffer, and the other with the antenna using codesend, and got the same results as before…

          2. I finally read through all 8 pages of comments, and it looks like I’m in the exact same boat as RY here from back in june

            perhaps he was on to something with the protocol?
            i tried reading through the source code, but i really wouldn’t know what to change…
            i tried changing “this->setProtocol(1);” to “this->setProtocol(2);” in RCSwitch.cpp and recompiling, but that didn’t seem to do the trick…

  5. Great guide and interesting project, but i don’t get any codes using the sniffer and the receiver, just blank after i run the RFSniffer command. I have the exact same receiver as you, tried with three different pieces, connected to gpio 27 and a nexa outlet. Any ideas what might be wrong here?

  6. Tim,
    Awesome guide, this is a really cool idea.
    I can manually control my outlets using codesend on the command line, however, I cannot access the website from my PC, as the connection times out. Any ideas?

    1. Thanks glad you like it! Verify that you ran step 7 from the guide. It may be a permission issue and php isn’t able to call the codesend executable.

    2. Nevermind, got it fixed. Pi was only allowing connections on Ethernet, which was disconnected. Changing my static IP in /etc/dhcpcd.conf solved it.

  7. Hi Tim,
    thanks for the great installation guide.
    Nearly everything is running fine… nearly…
    As I push the command “codesend …” on the CLI, the plugs are switching on or off, depends on the code…
    The website is shown, but the buttons are “dead”… there is no action after clicking on/off.
    I’ve already edited the toggle.php with my codes and also edited the path from
    $codeSendPath = ‘./codesend’;
    $codeSendPath = ‘./var/www/html/rfoutlet/codesend’;

    Any ideas why the website is not working??
    Thanks for your help!

      1. not yet… but I just solved the issue a few minutes after my post here… it took me half the day to find the error, then I write here and 5 minutes later it was fixed 🙂
        I’m not quite sure what fixed the issue in the end, but now it’s working:

        I used:
        sudo cpan install JSON
        sudo apt-get install libjson-perl

        After a reboot it worked 🙂
        Now I’m glad 🙂

      2. I seem to have the same issue. Everything works great with 315mhz transmitter (codesend) but the developer console returns “Failed to load resource: the server responded with a status of 405 (Not Allowed)” for toggle.php and the POST commands in my apache version all paths incluce http could it have something to do with that?

          1. I fixed it. It seems I somehow installed another http server (nginx) along together as some dependency. Great article!

          2. Thanks! Glad you got it to work. Make sure you check out the follow up articles on using Siri, amazon Echo and google home to control the outlets with your voice.

  8. Great guide Tim, thanks.
    Got it done in a RPi B model without issue.

    I’m also able to control the lights from widgets in my Android home screen with an app called Hot Button, which connects to the pi via ssh and sends the command /var/www/rfoutlet/codesend XXXXXX in case somebody would like to try it

  9. What are the limitations of the values used for code and pulse if we might want to have the outlets respond to non-default code and pulse? The outlets can be reprogrammed. I’d like to know if anyone knows what the values can be. Thanks.

      1. Thanks, Tim, I bought these same outlets and they work perfectly. I just want them to be reprogrammed with something other than the well-known default settings and was wondering what those settings can be.

        1. I’ve posted a detailed breakdown of the code signals. You can set the header and channel portions to anything you’d like, but the ON/OFF portion or the code has to be correct of course.

    1. Do a decimal to binary conversion on all RFSniffer responses and you see each button generates 23 characters. First 9 are identical 101010001. Position 10-20 identify each button, limited testing suggests 10-20 consist of 5 pairs of 01, 11, & 00 in any combination but only us 11 once (e.g. button #1 10-20 : …0101010011…, button #2: ….0101011100.., etc). Last 4 digits On=0011, Off=1100.

      Outlets can learn to respond to more than 1 code so you can teach multiple outlets a code that has no physical button but will respond to codesend 5526723= 10101000101010011000011

  10. Hi Tim,
    Great article. Lots of useful information. But I have one question. Im from UK and Etekcity doesn’t produce UK style power outlets. Do you know any other product compatible with UK plugs?
    I know I can still use a power adapter to plugin my appliances to this outlet but it would be neat to have a UK compatible wi-fi outlet.

    1. Thanks! Yes I think some people have been able to get it to work with other outlets. Just make sure they are 433mhz. Read through the comments.

  11. Hi Tim,

    the whole setup works really well.
    But after a while something seem to stop responding.
    The webpage with my buttons is without function and if I login with SSH and type codesend… manually there is also no function.

    The only way to fix this issue is to reboot the Pi.
    Now the question: is there a way to check if there is a special service (used for codesend…) which is broken and could be restarted automatically?
    Sometimes the setup works for days and sometimes I have to reboot twice an hour…

    Best Regards,

    1. Hmm I wonder if it’s something else causing it to lock up. Codesend is not a service that is running. I don’t have to restart mine. Is everything up to date?

      1. I would check your power supply is rated to supply the Pi you are using. Also SD cards often fail and can cause this sort of behaviour.

  12. Hi there
    Going to try this but I’m not that bothered about the web interface, as my Pi has a zero-config VPN (zerotier), which I use over SSH-so could I use this via command line? The idea is to be able to turn off and on a device remotely (router), using the Pi, but only if the Pi fails a simple WAN UP bash script (it pings periodically and it no response), when connected to said router by Ethernet.


    1. Yes that should work. All you need to do is call the codesend program and pass your outlet code. See step 8 in the post. Let us know if you get it to work.

      1. Ahh-this is so cool. Got a job lot of 3 x 443Mhz plugs off ebay (for £5.00!). Already had Apache on a Pi for something else, couldn’t get it to work, so wiped it and rebuilt using a back up image. Done as instructed, now turning lights on and off at will in the next room, via the Pi! Command line or web, both work.
        Thanks for a great tutorial 🙂

  13. Hi Tim,
    When I run RFSniffer I dont get any out put. What might be wrong? Would be my circuit? One thing I noticed is that Im using a different version of a Pi than yours and I notices a Pin number in your code (currently 2). Should it be changed?

  14. Hi Tim, thank you, this is a great post. One question, though: on the image (or “wiring diagram”) you mention GPIO 21/27 and point to PIN # 2 on the Receiver. Wired.com’s version says GPIO 21/27 but points to PIN #3 on the Receiver.

    Yours: http://i1.wp.com/timleland.com/wp-content/uploads/2014/12/Rf-Wiring-1.png
    Wired: https://wi-images.condecdn.net/image/PxqdnRzYBzq/crop/810

    The photos you have taken don’t show the wiring in any meaningful way. So I’m a bit confused, does that mean that Receiver Pin #2 goes to GPIO 21 and Pin #3 goes to GPIO 27? Or does GPIO 21 / 27 need to be spliced together and then connected to Pin #2 (or #3 according to Wired)? Or are you saying that either 21 or 27 is acceptable? And if so, does that mean that you can’t use other GPIO spots?

    Thank you. Btw, I think real Fritzing wiring diagram would be very helpful. Once I get this small hiccup solved, I would be happy to throw one together for you to place on this post.

    1. Hey Adam glad you like it! Check out http://wiringpi.com/pins/ for an explanation of 21/27. It is confusing but I believe it’s labeled that way b/c of different revisions of the board. Follow my example over the one in wired. You don’t need to splice them together.

      Feel free to send me a diagram and I’ll update the post.


  15. Hello Tim!! Thank you for your time and great posts!!! I am new with Raspberry Pi ad that’s why I am a little confused about this article. I’d like to know the “best way” to get control of powered outlets plus voice command to activate those switches and also open web pages, etc… Here is where I don’t understand if you can do this with a USB mic in the Raspberry or it is necessary Siri, Google or Alexia thru another device. It is cloud operated, it could be a voice service in the Pi…? Please help me to understand. Regards!!!

    1. Glad you like it! Yes you could use a mic from the pi but you would need to use some software that is listening for voice commands. Using Siri, google home or Alexa makes it easier bc they are designed for voice commands. I think you’ll have a better experience using one of those devices.

  16. Great guide! Successfully installed and running on a Raspberry Pi model 1B.
    However, my SD card became corrupted due to hardware damage, and in the process of rebuilding the installation, I have not gotten the ./codesend command to work. The transmitter and receiver are hooked up to the same default pins that they were before the corruption, and RFSniffer works successfully. Neither toggle.php nor ./codesend gives an error, they simply fail to toggle the outlets. The outlets are in the same locations relative to the transmitter as they were before, which leads me to believe that this is a configuration issue. Any ideas?

      1. Yes, Wiring Pi was installed successfully. Using the stock Raspbian Jessie OS without a GUI. Should I reattempt Wiring Pi installation?

          1. Done, no change in function. Any other possibilities? Is there a way to save the waveform from the RF receiver as a file, and broadcast that file when the website is triggered?

Leave a Reply

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