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:

Steps:

  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.

657 thoughts on “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.

    Thanks

      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)
    {
    mainasync().Wait();
    }

    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

        off=
        Received 1364
        Received pulse 313

        2

        on=
        Received 4433
        Received pulse 310

        off=
        Received 4436
        Received pulse 314

        Another controller
        1
        on= 1381717
        Puls 438

        Receive
        Received pulse 439

        offf=
        Received 1381716
        Received pulse 438

        2
        on=
        Received 1394005
        Received pulse 440

        off=
        Received 1394004
        Received pulse 438

        3=

        on 1066321
        330

        off
        1066324
        330

        Thanks

  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 192.168.1.6 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:
        on=
        Received 13446
        Received pulse 1175
        off=
        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
            https://timleland.com/wireless-power-outlets/comment-page-7/#comment-4095

            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’;
    to:
    $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 🙂

  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.

  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,
    Stevel

    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 8.8.8.8 periodically and it no response), when connected to said router by Ethernet.

    Thanks
    cabs

    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 🙂

Leave a Reply

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