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


Thanks for reading. Make sure you follow me on Twitter to stay up to date on the progress of my side projects T.LYWeather Extension, and Link Shortener Extension. If you are interested in the tech I use daily, check out my uses page.  

815 thoughts to “Wireless Power Outlets”

  1. Awesome! Almost works perfectly… I can run codesend from the command line to toggle my switch on and off, but it doesn’t work from the web… I updated the toggle.php as noted but my code is 7 digits vs 6. (Also changed the privileges on the codesend app)

    Any ideas, thanks for the awesome work! Also, any chance to see the code for RF Sniffer and Codesend?

    Thanks,
    Rich

    1. I have gotten this all to work multiple times but mu PI Sdcard got corrupted so i had to redo everything.

      The only difference is this time i had to put everything in /var/www/html/rfoutlet (raspian Jessie build)

      I felt like i changed all the paths accordingly but i cannot get it to work from the web. THe web page comes up and the buttons are there. THe do not work. I updated my toggle.php and as long as i use /var/www/html/rfoutlet/codesend xxxxxxx it works. I also updated my path in toggle.php to include the html directory.

      Any ideas?

    1. Dumb issue on my end… didn’t realize I had the paths different inside of the toggle.php!

      Thanks for the awesome tutorial!

  2. Thanks for the excellent guide, my wireless outlets are working great! After adding an antenna my transmitter has no problems controlling outlets on the second floor of my house.

    I did run into one small issue though. I wasn’t able to get the transmit module working until I swapped the 5V and ground pins to the opposite of what you show in your photo. The wiring I ended up using matches the silk screening on the transmitter board.

    Is there a mistake in your image or am I missing something?

    1. Thats awesome Sam! There could be a mistake. Ill take a look and see. You could also be using a different transmitter. Glad you were able to get it to work! Let me know if you have any other questions.

  3. You my good man, are an absolute legend. I’d add some notes about the path, because this also made me question why it wasn’t sending from the web but would work fine from the command line.

    Other than that, your coding from RFSniffer & codesend are much better than the 433Utils, it detects the pulse patterns over and above the standard – so remotes that I’d written off as not going to work, no work fine.

      1. Hey Tim,
        How about this one then for weird, so I have 7 Electric sockets, 4 are Mercury, 3 are Byron.
        All of the units work fine from command but only the Mercury work from the WebPage.
        I’ve tried creating two separate Toggle.php’s with 3 Referring to Toggle1 and 4 referring to Toggle2.
        The codes not working are 20, 21, 4116, 4117, 16405 & 16404. The ones that work are 349491, 349500, 349635, 349644, 349955, 349964, 351491, 351500, 357635 & 357644. The obvious answer is that the codes are 6 digits and not 2, 4 & 5 but I can’t see why this would make a difference using PHP, can you?

        1. The shorter codes may be getting converted into 6-digit codes with leading zeroes, like 000020, 000021, 004116, etc. Then, the leading zero can cause certain languages to interpret them as octal numbers (32, 33, 2126, etc.) which would be wrong.

  4. code send doesn’t work from terminal, only from the web,
    what am i doing wrong? how can i easily control a single output at a time.
    sorry if this doesn’t make sense im, still learning.

  5. Does “gpio 21/27” mean wire it to either of those, or both of those? I’m pretty new to this. A schematic or a picture showing how it’s wired up would help me out greatly

      1. I’ve got the new RaspBerry Pi 2. I’ve no clue at to which pin the Reciever should go to on the Pin-header. Tried 3 different positions. Can’t wait to get this running.
        Great work!

  6. I followed your directions exactly, but when I try to run codesend I get an error message:
    /var/www/rfoutlet $ codesend
    -bash: codesend: command not found

    I already had 433Utils installed. Would that be messing things up? Any ideas? I can’t get it to work over the web either.

    Thanks.

      1. The codesend and RFSniffer files are there but both say command not found when I type them in. In 433Utils there are several other files that go along with them. Do I need those? I just have 6 files in that folder:

        /var/www/rfoutlet $ dir
        codesend index.html README.md RFSniffer script.js toggle.php

          1. yes.

            I can get codesend and RFSniffer to run if i go into the 433Utils directory with them, but it doesn’t work anywhere else. I ran:
            sudo chown root.root /var/www/rfoutlet/codesend
            sudo chmod 4755 /var/www/rfoutlet/codesend

            So I believe that should run the codesend in the rfoutlet from any directory, but I always get “command not found” even if i go into the rfoutlet directory. Any thoughts?

            Also, as I said, I can get the 433Utils version to run, but it won’t activate my outlet, so I’m not sure my RF transmitter is working. Is there a way to run codesend and RFSniffer at the same time to check the transmitter?

            Thanks!

          2. I got the 433Utils codesend and RFSniffer to run at the same time and it does pick up the transmitted code, but I still can’t activate the outlet. This is driving me crazy.

            Is there any difference between your codesend and the 433Utils codesend? Maybe I could modify their version to match yours since I can’t get yours to work (so weird).

          3. The main thing different with mine is i set a different frequency for the power outlets i used. Using my rfsniffer you should see the frequency of your outlets and change your codesend to match. Hope this helps

          4. So I ran “make all” and that make codesend and RFSniffer executable. I guess I needed that spelled out for me in the instructions. Whatever frequency change you made to codesend works. I am now able to get everything working.

            Thanks.

        1. Tim:

          I’m trying to use a 315 mhz RF transmitter and receiver kit with the Etekcity outlet kit. The Etekcity 5 outlet kit operates at 433 mhz. RFSniffer from your repo appears to run ok, although I’m not getting any output from it when operate the Etekcity remote. I suspect my problem is that my devices are not operating on the same frequency. Thoughts?

          Regards

  7. Hey Tim,
    A well explained tutorial but the issue I have is the code sent from the remote itself. It sends a 9 digit code. I can use the RFSniffer and is received by codesend up to 8 digits. The RFSniffer picks up the 9 digit code from the remote but it looks as though codesend doesn’t send 9 digits so both the RFSniffer and the power outlets don’t receive the code sent from the Pi.
    Any ideas?
    Cheers

  8. Thanks for this writeup. I have followed every instruction but as soon as I try to use RFsniffer, nothing happens. Cursor just blinks on the line below. Am I missing something?

      1. I attempt this but nothing appears. I will check to ensure that I wired everything correctly, hoping I don’t have a defective receiver…

          1. Thank for the drawing but Im still clueless. What pin # are you talking about? IC out names, WiringPi #, Motherboard pin # or the pin # of the breadboard???
            Totally clueless… I’m using the new Raspberry Pi 2. A nice wiring diagram would be nice… I have just burned out my 433MHz sender…

      2. I’ve run into another wall, and I hope its not something very basic again. While I can receive codes just fine, sending codes does not seem to work. I have run the codesend from the command line, and my command is followed by a response “sending code[1381683]” However, nothing appears to happen. (Ran RF Sniffer at the same time on another terminal window and it would not detect a transmission, but if I click the remote itself the codes show up on RFSniffer.) Ive tried different cables and different RF Transmitters to make sure it wasn’t a hardware defect, but im stuck.

          1. Make sure you have the transmitter chip wired up correctly. That would be my first guess. Its also possible you got a bad transmitter chip.

          2. So I finally got it to work, took a closer look at my transmitter chip itself and I noticed that it had ground listed on the furthest right pin. Looking at your picture, it appears to be the same picture, but you have it listed as 5v and thats how I wired it. When I switched the 5v and the Ground positions, it worked just fine 🙂

  9. Please note that in my Arduino code using RCSwitch I had to call setPulseLength() (to 190 in my case), for it to work correctly. It may be that not all remotes use the same pulse length.

    It would be nice if you updated the git repository with the source code for the modified codesend and added a note about the pulse length.

    I will see if I can develop a native application that calls your PHP script, it should be relatively simple. Since PHP has a built in web server, it would also be possible to just run the script standalone without Apache.

    Thank you for documenting this work!

  10. Good article! Got it working on a B+. Had to use gpio readall to figure out the real io’s. Funny on an Arduino, I could get RFSniffer to work, but could not transmit the signal.

  11. Hi Tim,
    Thank you for your RF power outlet control write up. I am noob and trying my best to control rf outlets using your information. I purchased all equipments as you remanded. Able to run RFSniffe and gather codes for all 5 buttons.

    I noticed all my sniffe output has codes with 7digit number than 6 digits you mentioned in toggle.php :
    Received 1332531
    Received pulse 184
    Received 1332540
    Received pulse 184

    I tried with both 7 digit codes and also with 6 digit codes by eliminating 1st digit 1 and run codesend from console as well as webpage. None is working. Please advise, where i am doing wrong?

    Thanks & regards,
    Vijay.

    1. Its possible you got a different model of outlets.

      First double check you have the transmitter wired correctly. If that doesn’t fix it, try change the codesend program pulse to 184 instead of 189. mySwitch.setPulseLength(184); I added the codesend source to the github page. To compile the codesend.cpp program use the command ‘make codesend’

      Hope this helps.

      1. Thank you Tim for quick response!!
        please include the following files to github page :
        #include “RCSwitch.h”
        #include
        #include

        with out these files, i am not able to compile codesend.cpp

        Also, advise which 6 digit code i need to use – Received 1332531:
        is it 332531 or 133253 ??

          1. Tim, the RCSwitch.h isn’t included in your git
            I tried grabbing from 433Utils to compile and I get errors.
            can you upload your modded version to your git?

            also your toggle.php is pointing to codesend in /home/pi/www/rfoutlet/codesend
            not /var/www/rfoutlet/codesend

            and lastly my tekcity remote uses 7 digits, not 6. i can receive codes correctly
            but transmitting does not work.. any Idea on where I can check/change code?

          2. Will thanks for the comment. I added all the files to this folder. I was able to compile codesend on my pi by using this command ‘make codesend’

            I also changed the toggle.php file. My home directory had a reference to www. Thanks for letting me know

            When using the RFSniffer what is the pulse length? You could try a different pulse length in the codesend program or buy these

          3. I have the same etekcity units as you, not sure why mine push out 7 digits, I have 2 different orders and both have 7 digits.

            I tried changing the pulse code to match what the sniffer said (187) but still no dice.

          4. So RFSniffer can read the 7 digits but codesend isn’t working? With two terminals open run codesend and RFSniffer at the same time. See if RFSniffer can see your codes from codesend

        1. Tim,
          It worked with my 7digit codes. No modification to codesend required. I am now able to control power outlets from console window. Still not able to control from webpage toggle.php. Any suggestions??

          1. Thats good to hear. If you still need the other files you can get them from here

            If you can’t get it to work from the php make sure you set the right permission.
            Run: sudo chown root.root /var/www/rfoutlet/codesend
            Run: sudo chmod 4755 /var/www/rfoutlet/codesend

            Also inspect your web traffic using google chrome

      1. Thanks TIm!

        I was able to get everything to work except for one button. I noticed that the pulse can change from 189-190 sometimes. This happens more often for button #2 and the others seem to be ok. Have you experienced this on your end?

        1. Could it be the location of the #2 outlet? Yes I’ve noticed the pulse changes and isn’t consistent. Does button #2 never work even using the remote?

          1. Outlet #2 is one of the closest to the pi and works well with the Etekcity remote. The rfoutlet webcontrol for Outlet #2 takes several retries but eventually works when it wants to (I assume whenever it pulses 189). I suppose a workaround would be to modify codesend to try pulsing 189 and 190. What do you think?

  12. Excellent Project! I plan on using a secondary processor to pass the commands via TCP/IP or UDP to the Pi. Is this possible? What would the string look like? Any special port. I do not have the ability to access the PHP within my App but can pass strings via Ethernet.

    Many thanks,

    Mike –

  13. Any option for Europeans ?
    What would be an alternative for Etekcity 5 Pack ? A setup that offers 220V and EU plug outlets ?

    My options:

    mumbi Funksteckdosen Set: 6 x Funksteckdose + 2 x Fernbedienung / Funkschalter Plug & Play – 1000 Watt: Amazon.de: Baumarkt
    http://www.amazon.de/mumbi-Funksteckdosen-Set-Funksteckdose-Fernbedienung/dp/B0051GIWBC

    Home Easy HE815S Funk-Dimmer und Schalter-Set (ein Funk- Dimmstecker, drei Funk- Schalter und eine Fernbedienung): Amazon.de: Baumarkt
    http://www.amazon.de/Home-Easy-HE815S-Schalter-Set-Fernbedienung/dp/B004NTHOBW

    Wireless UK/AU/EU/US Plug Remote Control Socket Switch AC Power Outlet Mains Socket with Remote Controller: Amazon.fr: High-tech
    http://www.amazon.fr/Wireless-Remote-Control-Socket-Controller/dp/B00SXVGA16

    Set of 4 Wireless Electrical Sockets With Remote Control Power Switch Outlet up to 40m Range: Amazon.co.uk: DIY & Tools
    http://www.amazon.co.uk/Wireless-Electrical-Sockets-Remote-Control/dp/B00QSG9LN2

    1. Yes its possible. I actually bought another set of the Etekcity 5 Pack. I thought they would use different codes but they didn’t. You can set multiple outlets to the same code. For ex. all my living room lamps use the same code. I press one button and they all go off. You could try a different brand of outlets.

  14. In your picture, you show a bunch of wires hooking up the RF transmitter and receiver along with another module.

    However in your materials required, there are no wires, bread board or separate blue module like the picture shows. Also, your directions do no specify how to wire everything up like you have shown in the picture.

    Could you clarify all the required components to be used for wiring it together as well as instructions how to do the wiring?

    Thank you!

    – Aaron

  15. Hi,

    I have 6 remote senders. I can rfsniff all of them except 2. They are both of the same brand.
    These 2 remote senders work ok when I use them. However I want to rfsniff to resend it’s codes via commandline.

    Any ideas what I can try? I both tried 433Utils and rfoutlet…
    Nothing is shown in console when sniffing

  16. Got a link to SMAKN’s company home page? Google can’t seem to find anything for them, nor can I seem to find a valid source to buy their products (Amazon’s ordering procedure makes it impossible for me to purchase anything from them)

  17. Thanks Tim for the write-up, very interesting indeed. I’ve been looking to start a home automation project utilising a Pi for a long time and this has given me a good push to get on with it seeing how easy it looks 🙂

    Just wondered is there any limit to the number of outlets that this could control, assuming all of them have a different code? I would be looking to control almost everything in our house with them, particularly the electric heating so I’ll likely modify the outlets to be a hard-wired solution for several devices.

    I’m in the UK (with 230v and 13A 3 pin plugs) so not sure which brand of outlets to look for but I’m sure I’ll find something useful. Do you also know if it is possible to change the code on an outlet if I ended up getting one or more with the same code, maybe by an internal selector or potentiometer or something? I haven’t yet got any to play with so not sure what the innards are like.

    Interestingly, I’ve just seen this kit, the Pi-Mote which is available in the UK although I’d rather use your solution, building it from scratch is half of the fun 🙂 https://energenie4u.co.uk/index.phpcatalogue/product/ENER002-2PI

    1. I’m not sure about finding a solution for the UK but I did buy 2 sets of the Etekcity 5 pack outlets thinking I they would use different codes. They actually use the same codes as the other 5 pack. You could probably buy a different brand of outlets and they may use different codes.

      The Etekcity brand allows you to program the outlets to the same code. For example I have all my lamps in my living room on the same code. Hope this helps

  18. Following my previous comment, just wondering how difficult it would be to make my own outlets, I’ve got plenty of stripboard knocking about and quite handy with a soldering iron. I’m aware of the risks/dangers of mains electricity. Apart from a 433 receiver and a hefty relay and a suitable enclosure I’m wondering what else might be required. Some sort of enclosure like this would be useful for the permanent fixtures https://www.entryphone.co.uk/eshop/images/products/P_PLATE_72_340.jpg

    1. Does it allow you to control 433mhz transmitter and customize the codes? It looks more complicated then what’s need to control outlets. I wanted this guide to be simple

  19. I’m in the process of building a blog of Raspberry Pi projects that one can use in your house. The link to the blog is http://raspberrypihomeautomation.net.

    I think your article will make a very great addition to it.

    If you are willing to allow me to publish your article on my blog please reply to my email so that we can discuss it further.

  20. Has this team tried to create their own codes. The remote only has 5 codes by default. That would only allow for 5 zones. Have we sniffed the RF coming from the remote and changed the digits slightly and then pair the plugs to the PI’s RF Transmitter with the new made up codes?

    Potentiallly, we could have an unlimited number of zones (activitation codes).

    I can;t try this until my new pi comes this week…. Tee Hee….

    Mike-

    1. You are right.
      I captured all the codes from my remote. (a 415MHz 5 outlet set from Ivation bought on Amazon.)
      Anyway, what i disccovered was that the ON/OFF code pairs have a relationship.
      Ex. Switch #1 has an ON code of 7069721 ON code with corresponding OFF code 7069713( numerically 8 below the ON code)
      The other thing, at least in my case was there was a separate code pair for ALL ON and ALL OFF.

      I changed the codes by a bit and also by alot. In both cases the as long as the numeric relationship
      between the codes is maintained you can pair the new codes to the outlets.

      I used this to pair several outlets to the same codes to control my Christmas lights from a cron job. It worked very well.

  21. Hi Tim,
    awesome work and I need a help from you please.
    I can send the codesend via ssh terminal but I have to add ./codesend 83029

    pi@raspiweb /var/www/rfoutlet $ ./codesend 83029
    sending code[83029]

    but if i run just the word codesend, it doesnt work and this is the error message

    pi@raspiweb /var/www/rfoutlet $ codesend 12345
    -bash: codesend: command not found

    what can I do to fix this? it also doesnt work via the web.

    Thanks

      1. Hi Tim

        I managed to get it working by simply following your post with more detail again. I must have missed a step there.

        Can we integrate this with other open source home automation such as openHAB or homegenie? If would be awesome if you can schedule an automatic on/off a particular switch.

        Thanks heaps!

          1. Hi Tim
            Thanks, that would be great if we can incorporate it with home automation system.

            The cron job, unfortunately im not too familiar with bash programming. How can you set one up?
            my code below at 8pm everyday, turn light on
            crontab -e
            0 20 * * * /var/www/rfoutlet/codesend “code number”

            But it doesnt seem to work, can you please help.
            Thanks

          2. Hi Tim,

            Please disregard my previous comment saying it didnt work, as a matter of fact it did work. the cron tab rule. you could use the crontab rule in your post, that might help others.

            Cheers

  22. Hi,

    I am running into some problems: the program doesn’t enter the if statement ‘available’ so I don’t receive any data from the sniffer. At first I thought I connected the receiver incorrectly to the pi, but I verified that I was using the correct pi pin by hooking up a led and doing a simple gpio write command. I also verified my receiver by hooking up a led to the data pin and I can see it blinking when I press a button on my remote, so it seems to be working. It’s driving me crazy, because everything seems to be working, I just don’t enter that ‘available’ statement. I have tried it both on my new pi2 and my older pi, but they give the same result..
    I am using wiringpi version 2.25.
    Any help would be very welcome.

      1. It seems to be installed correctly. Also the pintest command which is supplied with the wiringpi install seems te be working (meaning the pin can be used as input. Just ruling out that it’s not a hardare issue of the pi.) I did notice that when I hook up a led to the data pin of the receiver, it seems to glow a little, so it’s definately not off. When I use a remote the led blinks brightly a few times, but is never completely off. Is this normal behavior? Maybe the receiver is broken.

      2. Ok, when I use the sniffer and send a command with the codesend command, it is detected. So I think the problem is with my remotes. It’s probably pulseLength related. I’ll mess aroung with it a bit 🙂 thanks for the quick reply.

          1. I am guessing that my remotes are sending codes that are more than 8bits long. Is there a way to have the sniffer be able to detect a full code of unknown length?
            Thx

          2. My only experience is with the sniffer is using these outlets. I would recommend buying them and everything should work. You could also check out this post. He was able to use my project and convert the codes into binary.

  23. Thanks a lot, Tim 🙂
    Yeah I guess I’ll need some other outlets. I’ll first poke around in the rfswitch code somewhat, maybe some things could be extended somewhat. If I find anything out, I’ll keep you guys posted. But I haven’t played around with RF a lot so far, so.. No promises 🙂

  24. Tim:

    I am getting this error while trying to run RFSniffer:

    pi@raspberrypi ~ $ sudo /var/www/rfoutlet/RFSniffer
    /var/www/rfoutlet/RFSniffer: error while loading shared libraries: libwiringPi.so: cannot open shared object file: No such file or directory

    Any ideas?

    Thank you,

  25. Hi, I got everything working, and it always successfully turns off the outlet, but it only turns on the outlet once every few runs, and even though I’ve got it doing five attempts, it still doesn’t always work. I have the pulse set to 181, but with RFSniffer, the pulse sometimes changes to 182, 183, etc.

    1. It’s probably the range of the sender. I wrapped a small wire around the antenna hole and it works consistently. Let me know if this helps

      1. I’ve tried that, and it appears that it still isn’t very consistent, because it doesn’t work on extremely close outlets (~3 feet away). However, it seems that the “off” switch works pretty consistently, it just doesn’t turn on consistently.

  26. I can’t get RFSniffer executable to work on a pi B or B+. AFAIK, I’m using the correct pin (physical 13, GPIO-27 on B+, wiringPi pin 2 – all describe the same pin, right?) .

    I’m not using the same 433MHz radios you are ( they’re marked RXB1, Rev.03), but I don’t think that’s the problem. I downloaded the RCSwitch code for arduino from the ninjablocks poster and I can read the remote codes fine on an Arduino with those radios. However, running RFSniffer on a B+ doesn’t display anything, just blinking cursor as an earlier poster mentioned – as if the wrong pin is being used.

    I downloaded your git Feb 23, which was after your made the “added 433util source” change. Is it possible something got broken in the update process then?

    I don’t know if there’s some assumed, unspoken action required on my part, like “enable interrupts on the pi” or some such. This looks like it should “just work”.

    Any guesses?

    TIA

    1. A little more info…
      I used the arduino version of RFSniffer to decipher the codes. Then, used codesend from the command line on the raspberry pi and that worked. So, just RFSniffer seems to be non-functional on my pi B or B+.

        1. I tried another receiver, which physically looks much more like the out-of-stock SMAKN model you recommended. The new receiver worked with no changes to the wiring. The old receiver was, I think, about 3 years old. Both are 433MHz. So, if folks are having trouble with the RFSniffer program, try a different receiver…

          Thanks for a great write-up and a useful project!

  27. This is GREAT information. I was able to compile the code and send and receive RF signals. However, my remote seems to transmit at 315mhz. The RFSniffer program is able to receive the signals (as 5 digit codes and 4 digit pulses). When I use the codesend program to transmit the signal (after I modified the pulse number and recompiled), I can verify the signal was properly sent (using RFSniffer), but the RF light switch does not activate. Any suggestions? Thanks. Chuck

    1. How far away are the outlets? The range is very limited without an antenna . I used a 12inch wire from a cat 5 cable and wrapped it around the hole on the sender chip. Try that and let me know what happens

      1. Thanks for the advice. Unfortunately, I tried using a 12 inch wire as an antenna and I placed the RF transmitter within a foot of the RF lamp switch… no luck. I think the problem is that my Woods 13569 uses 315 MHz and the 433Utils is for 433 MHz. The odd thing is that the RFSniffer can read the remote control signal and the sendcode program seems to sends the identical signals (as evidenced when I use RFSniffer to read the signal). I may need to find some 433 MHz RF light switch units.

  28. Hey Tim. I had great joy in making this switch work. I bought some switches from a German company (which fits in Denmark as well). I had to change the pulse to 432 to get it to work, and read all the comments to find clues on how to do it, maybe you could add a section to your guide with help to change the pulse, to help future beginners like me.

    Change pulse:

    sudo nano /var/www/rfoutlet/codesend.cpp

    and change the line: mySwitch.setPulseLength(184);
    save the file and compile with:

    sudo make codesend

    Best regards.
    Mikkel

  29. Great tutorial, thanks Tim. I managed to get it working with these ByeBye Standby sockets I had. Not sure they are making them anymore, but just had to alter the pulse length on codesend.cpp and it worked great.
    Thank you.

  30. So i have 2 remotes (315mhz), 6 outlets (315mhz), and a TX and RX (315mhz). I installed RFsniffer and wasnt able to to get it to post any codes. Is this because RF sniffer is created for 433mhz? Or am i not using the correct data pin on my RB pi. Im using GPIO 27 for the reciever (pin 13). Since ihavent gotten this working im not sure if RFsniffer will output codes in terminal or if it puts them in a file for code send. I would really love to get this working.

    Thanks,

    Ed

  31. UPDATE ***

    I got RFSniffer to show codes received on 315Mhz with my 315Mhz remote.

    Codes:
    1-On: 13378 PW range 1170-1188 (not sure if you guys show a consistent pulse width)
    1-Off: 13346 PW range 1170-1188
    and so on

    I changed the codes and PW in codesend.

    I am able to transmit via Webserver and the codes are received by RFSniffer with the correct codes and range of PW but the outlets do not respond. They will respond to the controller.

    Any thoughts? Should i put a zero in front? making them 6 digit? or is it a PW issue?

    Again im using all 315Mhz tx, rx, 2 remotes and 6 outlets.
    Thanks,
    Ed

    1. I haven’t tried it with the 315mhz chips but other people have commented that they’ve been able to get it to work. If you can’t figure it out I’d recommend using the 433mhz described in the post.

          1. Well I give up. Unless I get an oscilloscope or have a way to to test RFSniffers output for accuracy another way when using 433mhz.

  32. Hi Tim. Awesome post!

    I am having issues sending codes. I am able to receive from the remote, but not from the transmitter.
    I did notice that when I run codesend, the remote doesn’t work (interference) so the module does something because decreasing the pulse length does not create interference for the remote. I am sure I got the wiring correctly, so I don’t know what else to check.
    Do you think my transmitter is defective?

  33. They are definitely not touching each other. I tried different output pin and 3.3v, still same result.

  34. I’m am completely new to the world of Raspberry Pi.

    Out of curiosity, is there a way to do this with USB RF receiver? Actually, first, I suppose I should ask, does such a thing even exist?

    1. I’m not sure if that exist. This project uses the gpio pins on the raspberry pi. Follow my steps and this project is almost be as easy as plugging in a usb cord

  35. I wonder if the outlets could be programmed to accept a different code from the Pi using the learning function built in. This could possibly allow for more than 5 channels of outlets.

    1. I tried and wasn’t able to get them to work with other codes besides the 5 the remote used. Let me know if you figure out a way to do it this. Thanks

  36. Hello Tim,

    I loved your post and all the details made it so easy for me to do. Quick question. I know you have to type the hosts ip address followed by “/rfoutlet” to access the application. My question is how can I customize it so I can enter anything after the forward slash. So basically I want to replace “/rfoutlet” with anything I want. I tried poking around the rfoutlet folder and tried finding the file to do this but I couldn’t. Any help would be appreciated. Thanks!

  37. I got this to work! Actually I bought 2 packs of these, for a total of 10. What needs to be changed in the codes to make possible to use ten buttons instead of five?

    Also, what is the way to label these? for example, “living room” instead of 1.

    Thanks so much!

    1. Glad you got it to work Andrew! I bought 2 packs also bit was unable to get more then 5 codes. If you figure it out let me know.

      To change the labels, edit the index.html file and change the

  38. Great tutorial Tim, appreciate all the info–works very well. Are you aware of any issues with creating more buttons in the “controller HTML” for buttons which will create certain light “scenes” (i.e.-ALL On/Off, All Kitchen On/Off, etc)? I like keeping all my outlet switches at different codes so I can individually address them, but I can’t figure out how to send several codes all at once (rapidly sequentially).

    I created a button “6” in the HTML to turn on/off ALL outlets, and edited the PHP file to send all the on codes with a “sleep(1);” between each, but it doesn’t work. I’ve glanced through the C++ source, but can’t find any immediately apparent reason it shouldn’t work. Any ideas? PHP Link: http://pastebin.com/Y85ehueK

      1. Thanks for such a quick response Tim–what a gigantic help–my PHP is very dusty, so I really appreciate it. Just tested, and it works flawlessly. For anyone else who is curious, I was able to get the sleep timing between code sends down much lower than 3 seconds shown in the pasteBin–that was just an initial test. Down to about a half of a second pause between each second works well. Lower than that, and some lights stopped occasionally responding to the codes, which makes sense.

        Additional anecdote: I’m using a simple 12″ piece of 18-gauge wire soldered to the antenna connection on the transmitter chip, and having no range problems up to at least 40 feet, through multiple walls.

  39. Thank you, I’m very new to the Pi and after a few false starts got everything working. You’ve provided a great starting point for some projects I have had in mind.

  40. Thank you for this – this is a great project and was loads of fun to implement!

    I’ve finally figured out how to increase the number of devices, by editing both toggle.php and index.html, as I have different sets of devices. However, these groups transmit at different pulse lengths, therefore only 1 group can be used, unless multiple RasPis are purchased.

    Is it possible to send to edit the toggle.php file, so that when an on/off button is pressed, it also send the pulse length as well as the code? If this is not possible, can multiple RFOutlets be installed, one for each pulse length, all of which could be referenced on one index.html?

    My html and php knowledge is essentially non-existent, so any guidance would be greatly appreciated!

  41. Edit:

    …Is it possible to edit the toggle.php file, so that when an on/off button is pressed, it also sends the pulse length…

    1. Yes this is possible but you would have to edit toggle.php and codesend.cpp. You would have to rebuild codesend.php and change it so that the pulse length would be an additional parameter.

      The new command would be /var/www/rfoutlet/codesend rfCode pulse

      Hope this helps.

  42. Tim,
    I love this tutorial, I have all the parts ordered, and they should be in tonight and I will start experimenting

    Here is my questions.

    Is there a simple way to remove a wall light switch, and replace it with something that transmits the 433 code?
    The next obvious home automation step after controlling outlets with your pi using 433, is to have the existing light switches also transmit 433. I can picture how to do it by going 120v ac step down to 5v dc and then power an arduino in the wall that transmits when the switch is activate. But that seems overly expensive to put an arduino between every switch.

    Most 433 touch panels look like they receive instead of transmit, but I guess that would work too, just transmit the pi to the switch and end up with the same effect – but again – way more expensive then $7 an outlet.

    Any ideas?

  43. works great, except i have to run codesend upto 6 times to turn the outlet on, is there a way to auto repeat the signal code so it works everytime.
    thanks

  44. Seems to work better at more than a meter distance, is there a way to repeat the code send , say 5 times automatically to be more consistent
    Thanks for the quick reply

  45. Tim –
    There’s a new Arduino IDE (hacked) version that includes a board description for the ESP8266. Using this, you can upload programs with most of the functionality of Arduino (eg., no PWM) directly to the ESP8266 and run the ESP8266 stand-alone. NO Arduino or Raspberry Pi needed!

    I modded a sketch to work with the RCSwitch library via a Web Server and code running on the ESP8266.

    See my github entry for some details and a very quick and dirty demo:
    https://github.com/thisoldgeek/ESP8266-RCSwitch/blob/master/esp8266_rcswitch.ino

  46. Thank you for the tutorial! Do you know if this would work with a programmable remote? http://www.amazon.ca/Ivation-Programmable-Wireless-Remote-Control/dp/B00N5157LI

    Basically you first pair each outlet to 1,2,3,4, or 5 on the remote. Would the software you’ve provided be able to work with it after it’s been set up this way? Apparently it doesn’t work with another remote after you’ve paired to the one it came with? This model seems cheaper here in Canada, which is why I ask.

    Thanks!

  47. Hi Tim

    Thank you so much for the work you have put in on the 433Utils code. I have finally got RFSniffer and codesend to work using your version.

    I notice that the codesend is able to send any length code, however if you send anything over 8 digits then RFSniffer does not respond. I presume the limitation lies within the RFSniifer code. I would like to use RFSniffer to read codes sent from the Friedland (Honeywell) range of 433Mhz PIR’s, which I know use transmit more bits than the typical 433Mhz devices.

    Would you have any idea where the limitation may lie in the RFSniffer code, so that I may extend the length of the code received?

    Many thanks in anticipation.

    Kind regards
    Simon

    1. Glad you enjoyed it Simon. I’m not positive but the issue maybe because the value of the code is set to an int variable type. You could try using long variable in the rfsniffer code

  48. Would or should apt-get upgrade break anything? I did it earlier and now the rfoutlet page does not look right and the toggles are not working.

  49. Hi Tim

    I would like to receive the variable mySwitch.getReceivedValue() from RFSniffer.cpp into Python in order to use it to trigger events when I receive 433Mhz codes. I have got it working by editing RFSniffer.cpp and writing the value to a text file when it changes. I then read the same text file from within Python and receive the codes. The problem is it misses data and is therefore not reliable enough.
    I have been trying for the last 3 days to understand the concepts around wrapping a C++ file as an extension for python, but it really is beyond my capabilities. I have tried using both cython and boost to wrap RFSniffer.cpp but cannot get it working.
    Do you have any experience yourself or know of anyone I may be able to talk to who may be prepared to help?

    Many thanks
    Simon

    1. What do you mean by “misses data”? You should be able to do all your logic in the python code. Can you give me more details on what your’e trying to accomplish?

      1. Hi Tim

        I would like to read the codes from within python by importing the RFSniffer code. At the moment RFSniffer is a C++ application that runs in the background with no way of reading them in python. I have edited the RFSniffer code to write the codes to a text file. I then read the same text file from python, but it is a slow process and I don’t always receive all the codes in python.
        Do you have a sample python script that calls the variable that contains the codes being received?

        Kind regards
        Simon

  50. Hi Tim, Wonderful Tutorial. I was just wondering, I bought a outlet that operates at 433mhz but I also bought a Light bulb socket which operates at 315mhz, I got the transmitter and reciver kit for 433mhz and a separate on (same manufacturer) for 315mhz. Is it possible to get the code to work for 315mhz? Thanks Again!

  51. Tim, I’m still using my set of 5 outlets set up with your tutorial, and I love it! I’m interested in getting a second set of 5 additional outlets from a different company, but which also communicate @ 433mHz. Since this other brand will most likely (hopefully) use a different code number and pulse length, would it be theoretically possible to use RFSniffer on the same Pi to grab the pulse length for the second set, and make a “codesend2” based on that set of outlets? Then in my PHP, and wherever else necessary, I could call that “codesend2” with the additional RF codes?

    Just milling over it in my head makes sense, but curious if you see any limitations to doing that. I’m cool with throwing out $15 on the second set of outlets I found for the sake of testing too.

    1. Also, I’m curious if anyone has pulled one of the outlet receivers apart? It seems possible to me to control a built-in light fixture or really any device from these, since they seem to be just a relay. I won’t be messing with mains power anytime soon, since I’m obviously not very experienced, but wonder if it would be possible after altering the device in some relatively minor way.

    2. Yea that should work. You could modify codesend to accept and additional parameter and use the same codesend for both sets of outlets

  52. Hi, great tutorial.

    But still one question, do I need a level converter since we are working with 5V here ?

    Sounds like a bad idea to wire 5V to the gpio pins ?

    Robert.

      1. I was talking about the receiver part. That puts a 5 volt on the gpio pin. That can’t be good. It might fry your Raspberry Pi.

        The Transmitter is no problem cause it receives a TTL logic high.

        But don’t have a clue what level shifter to use.
        Anyone any suggestions ?

        1. Ciao,

          I’m following this “guide” to build my wireless garden irrigation system using the “LED strip remote receiver”.
          I connected as you suggested and is working, but now, “studying” another part (using the same transmitter to create a wireless flowmeter, that at the beginning I would like to “read” directly from the raspberry to understand what to expect) I came to the same conclusion: the GPIO pins are 3V3 tolerant and so is not “safe” to connect to a 5V (i.e. TTL) device.

          But looking at the datasheet of the transmitter (is written also on your Amazon link)
          https://quadmeup.com/fs1000a-and-xy-mk-5v-433mhz-rf-modules-overview/
          seems that we can power the transmitter 3V-12V. So maybe is enough to change the GPIO pin to power the transmitter, moving from 2 or 4 to 1…

          This weekend I’ll try and let you know.

          Thanks,
          Matteo

  53. Great post. Your crontab example, however, is wrong in the sense that the entry will run every minute while the hour is 20. If you only want to run it at 20.00, use 00 20 * * * /var/www/rfoutlet/codesend “code number” instead.

  54. Seems cool and all, but I honestly can’t think of much of a use to control outlets (I don’t have a single lamp). I really just want a way to control all the lights in the house for less than $15 per switch. Get on it. =P

      1. Unfortunately anything switch related is way more expensive than $15. I don’t get why outlets are so much cheaper.

    1. Great find! Though the more I thought about it, the more I realized those would probably just add too much length to existing bulbs in my house and it appears their max is 60 watts and i think most of mine are 65 (though they might just be 65w equivalent (I should check).

    1. nevermind, just realized that when using bulb options, you won’t be able to then turn the light on or off with the regular light switch. You would have to keep in on all the time and control it simply with the app. Correct? Grr, thought I was so close to a solution with the $15 GE Wink bulbs. =/

      1. only issue with the bulb ones too is they don’t have 2 buttons for on/off , just one. so you would have to modify code. i’ve been slowly tweaking Tim’s code for my own project. My first iteration is here: https://github.com/xillwillx/433Mhz , the second one will be using a sql db, ill be posting it sometime soon. I want to update the toggle codes to something more modular and using arrays

  55. Thanks for sharing! Can you share schematics and/or image showing where all the jumpers should go? Thanks!

  56. Hello,

    I have done what the guide said, and i am able to send a signal with codesend but i rarely pick up the signal with RFSniffer, sometimes it reads it when i spam send it. But piscope show it is send and received perfectly: http://i.imgur.com/WzHlCTT.jpg

    Also when i try to send a signal from a remote, the receiver is receiving is (i can see that in piscope) but RFSniffer isn’t reading it.

    Does anyone know how to fix this?
    http://www.reddit.com/r/raspberry_pi/comments/38eeis/rpi2_433_mhz_receiver_can_someone_help_me/

  57. Hi Tim, cool project indeed!

    I’m having issue with the RFSniffer. It can’t detect any pulse.
    Im using this and this for the transmitter and receiver.

    How did you wired it up? I have no experience in wiring it up, pretty stuck here.

    Much Thanks,
    Jerry

    1. Hmm first thought is that the chip you are using in 434mhz not 433mhz. That could be the issue. Can you detect the code?

      1. the operating frequency is supposed to be from 433.67 – 434.17, with the type of 433.92 which i think falls under the switch transmission frequency. Do i need to change the PIN number in RFSniffer.cpp?

          1. Thanks Tim! It worked!
            The only problem now is just most of the time the frequency didn’t reach to the switches in one time run(codesend.cpp). Any suggestion what might caused?

          2. Glad you got it to work. I had to attach a small wire to the antenna of the sender chip to increate the range. It now works throughout my entire house. Hope this helps!

  58. Hey Tim,
    Just had a quick question regarding wiring up the receiver and transmitter. I’m new to all this but I’m using a Raspberry Pi B+ and there is no GPIO pin 21/27 on my RPi GPIO T-Cobbler. I have separate pins for 21 and 27. Does it matter which pin to use?
    -Thanks

  59. How well is the range on the transmitter/ receiver with the antenna connected? I wanted to have the rf outlets in different rooms of the house . The Raspberry pi would be located in a centralized location. Also, would you be able to tell if the outlet is on or off?

    1. The range with antenna is pretty good. I’m able to control outlets anywhere in my house. Without modifications you would not be able to tell if the outlets are on or off. There is no response, so the raspberry pi will not know the status.

      1. I think I might actually try replacing the RF receiver with an esp8266 so that I can check status and also add a temperature sensor. This way I have a nice case and temp sensor for each room and just as a bonus, be able to remotely control the outlet. Seems to be enough room in the cases. Just have to duplicate whatever data the RF receiver is sending the the onboard MCU.

  60. This tutorial is great. I do want to learn how to get the two way feedback somehow. Like Honeywell wireless rf alarm door contacts. They supposedly sniff at certain intervals to determine if the door/window is open or not, thus updating the system. I have no idea how this works but I want to find out how to do it for controlling lights.

  61. Do you know any way to find out the code for a socket if I don’t have the original remote? I’ve got 3 sockets branded “Mercury Wireless Remote Control Socket”. They look old and dated and the sticker states they are 433MHz, They don’t appear to be reprogrammable, I’ve tried all sorts of button combinations but can’t get it into any sort of learning mode or anything. It’s these ones: http://www.yourspares.co.uk/parts/ys88460/rf-remote-control-mains-socket-set-5-sockets-350114UK.aspx

  62. hi Tim

    I have been using your solution for a while now and it’s working great with my 3 piece RF outlets.

    So I went and bought a wireless power board (different model to my current working one) it says 433.92Mhz (http://www.ejoy.com.au/gaf-rcs102-4-outlet-with-remote-surge.html)

    When I tried to capture the code with RFSniffer, it didnt print any result. Do you think the RF signal is encrypted or something? Is there any other way to find the codes?

    Thanks

  63. Hi,

    I am planning to build this on Onion Omega rather than the Raspberry Pi. Can you tell me how would I get the WiringPi libs.

    1. I don’t have any experience with onion omega but I don’t think you would need wiringpi since it’s only for the raspberry pi. I think you would just need codesend and rfsniffer to be able to interact with the gpio ports. Hope this helps.

  64. I started some work on this project using an SDR. I was able to record the transmission and start to decode the commands.

    Always sends 25 bits.
    s = short pulse, L = long pulse. all pulses start at about a .0008 spacing.
    s is about .000238 + .000562 pause
    L is about .000604 + .000196 pause

    Headers (I have 3 different remotes with these numbers on the back, each has a different header):
    0923 = s s s s s L s L s L
    1420 = s L s L s L s L s L
    1548 = s L s s s L s L s s

    Channels (all remotes have the same channel codes):
    Ch1 = s L s L s L s s L L
    Ch2 = s L s L s L L L s s
    Ch3 = s L s L L L s s s s
    Ch4 = s L L L s L s s s s
    Ch5 = L L s L s L s s s s

    Commands (same for all etekcity remotes):
    On = s s L L s
    Off = L L s s s

    Control Bits (not 100% positive about this part, but ** I can confirm are always the same):
    1 = s **
    5 = s
    6 = L
    7 = s
    8 = L
    9 = s
    12 = L **
    14 = L **
    16 = L **
    25 = s **

    1548 Sample Ch1 On Code
    [ header ] [ channel ] [Command]
    [ 1548 ] [ Ch 1 ] [ On ]
    [s L s s s L s L s s] [s L s L s L s s L L] [s s L L s]

    1548 Sample Ch1 Off Code
    [ header ] [ channel ] [Command]
    [ 1548 ] [ Ch 1 ] [ Off ]
    [s L s s s L s L s s] [s L s L s L s s L L] [L L s s s]

    I’m sure those timings could be more accurate, but I’m getting all this info without any analyzer from looking at recorded wav’s in Audacity.

    Any chance you know the correct timings or have any more insight?

      1. My hope wasn’t to simply make it work. I’m more interesting in the beginning to end details of reverse engineering the entire process which I can then use on any other RF communication devices.

        That being said, it probably would help to take a look at what this RFSniffer script captures and compare it to my manual results. Would you mind sharing your results from RFSniffer?

        1. Do you want my codes?
          $light1 = [349491, 349500];
          $light2 = [349635, 349644];
          $light3 = [349955, 349964];
          $light4 = [351491, 351500];
          $light5 = [357635, 357644];

          1. Ahh! Thanks!

            If you convert your numbers to simple binary, the 1’s and 0’s match up exactly to the ‘L’ONG and ‘s’hort pulses that I found in my WAV recordings.

            Would the remote you used to generate those happen to have a “923” sticker on the back?

          2. Interesting. You 0343 code is the same as my 0923. Did you sniff your 1573? I’m wondering if only the last digit is significant.

          3. Nah. If that were the case then there would be no need to sniff anything. And I’ve already found three unique sets of codes. I guess you COULD just use one set of codes, but then you wouldn’t be able to expand beyond 5 devices. You need a different remote group to add another set of 5.

            I broke down and bought the receiver/transmitter set (since I needed a transmitter anyway). Going to see if I can just make up headers and have the outlets “learn” my codes. I’ll post results early next week.

          4. Finally put everything together and loaded up my new Pi 2..

            As I suspected, you absolutely can make up the remote identification header portion of the code. Any combination of 10 bits, followed by a proper channel and command, will give a valid code that can be learned by the outlet.

          5. Sure. Let’s take your channel 1 ON code 349491.

            Converted to binary = 1010101010100110011

            Now let’s break it up to identify the parts.
            [10101] [0101010011] [0011]

            The first part identifies the remote group. It’s really 10 bits long, and the transmit code pads the empty bits with leading 0’s when it sends. So the actual header or remote group portion would be 0000010101. This is of course the same value converted to decimal.

            The second part is the channel. 0101010011 is used as CHANNEL 1 by these outlets. I originally posted not knowing how to distinguish 1’s and 0’s other than by short and long pulses. So if you look above, I have all 5 channels listed, but with s and L instead of 0 and 1. Again, the transmit code you use turns this back into short and long pulses.
            So here again are the channels in binary:
            Ch1 = 0101010011
            Ch2 = 0101011100
            Ch3 = 0101110000
            Ch4 = 0111010000
            Ch5 = 1101010000

            And finally, the last bit is the ON/OFF command.
            ON = 0011
            OFF = 1100

            You can take your remote group + any channel + any command to get all of the codes you sniffed. Let’s try Channel 3 OFF just as an example.

            Header 0000010101
            Ch3 0101110000
            OFF 1100
            Full command = 000001010101011100001100
            Converted to decimal = 349964, which matches what you sniffed.

            You can change the 10 header bits to be anything you want, and the outlets will learn your code just like from any remote. Let’s try 1100110011 and use Ch3 ON
            110011001101011100000011
            Converted to decimal = 13424387

            The OFF command is always +9 in decimal
            110011001101011100001100 = 13424396

            You can press the learn button then send the new ON command we created with a completely made up header, and it will accept it. Now send the ON or OFF commands, and it will work like any remote.

            After further testing, I’ve also found that you can make up channel numbers with any combination of 10 bits for the second section. The 5 channels I list are standard among the ETEKCITY remotes, but you can make up anything for those also.

          6. You could also clean up your toggle.php so you only need to input the Channel1 ON code, and figure out the remaining codes programmatically.

  65. Tim – Thank you for this great tutorial! My 7yr old daughter and I used this as our first RPi project and have both outlets and light sockets working. Our next steps are to plug into our alarm system and garage door opener but they are apparently on different frequencies (392mhz and 315mhz respectively).
    We have a 315mhz receiver/transmitter kit but haven’t had much luck sniffing… Do we need to adjust RFSniffer and Codesend and recompile? I’ve read ALL of the comments but no luck yet. Any advice would be greatly appreciated!
    Thanks again!

    1. Hey I’m glad you enjoyed the tutorial! I don’t think code send will work because it designed for 433mhz. Check out the source here. Most likely your garage door opener has some type of encryption. You may have more luck buying an extra remote and wiring it up.

      1. Thanks Tim! As far as the garage door goes, we may actually move the Pi into the garage and hardwire to the opener with a relay module.

        Off topic – we also have magnetic sensors we can use but when inspecting the opener we found it already has open and close limit sensors in place with terminals. Any thoughts on how to leverage those directly rather than plant additional sensors?

          1. So we got it wired up. It turns out the limit switches were low voltage (we put a 10k resistor online just in case though). We wired up each sensor (1 open, 1 closed) and used pushup on the gpio input to detect open, closes or in between.

            Your post got us motivated and confident enough to tackle this project! Thank you!

  66. Much obliged Tim! To the extent the carport entryway goes, we might really move the Pi into the carport and hardware to the opener with a hand-off module.
    Off subject – we likewise have attractive sensors we can utilize yet when assessing the opener we discovered it as of now has transparent farthest point sensors set up with terminals. Any musings on the most proficient method to influence those specifically instead of plant extra sensor
    Professional Door Entry Systems

  67. So I’ve been at this for a day now, but my RF Receiver never seems to get a signal. Ive double and triple checked the wiring to the Pi B+, used different GPIO pins, even bypassed the Pi Cobbler just in case it was that, and nothing appears on the terminal. I know that my breakout cable and GPIO pins are working because I’ve tested a few LEDs on the system.

    Having two terminals open and one recieving the RF signal and the other transmitting with codesend does not work either. Any help?

      1. Nope, nothing appears in the terminal. Its as if the Reciever is fried. I ran pintest as part of wiringpi to make sure my GPIO pins were functional and they all come back as “OK”

        1. Make sure that the sender and receiver chips aren’t touching. It’s also possible they’re bad. Did you get them on Amazon? I’d send them back and get new ones

      2. I also just added an LED to the circuit, with + on the Data pin. It is dim, but never changes its intensity when a button is pressed near the receiver.

          1. Yes. Plus, the box does state 433.92MHz and the remote has a 0360 sticker as once mentioned above. I did try codesend with some of the noted RF codes above with no luck. With an LED placed on the data pin of the transmitter, it stays lit full brightness and does not flicker when told to send the code.

          2. I’ll be replacing it and get back to you. The receiver was very hot once I came back to it a minute ago and does not seem normal… on top of the other problems.

          3. Good news. The replacements worked perfectly. I have not soldered a wire to serve as the antenna yet (just coiled through the hole and twisted together), but the outlets are now working perfectly through the Raspberry Pi. I’ve also taken to heavily modifying the original code and incorporate HTML5 voice recognition through Google Chrome, that way I have the button interface and voice commands if say I were walking around hands free.

            Doing some poking around, this is nearly exactly what is promised by the “Hook” device on Kickstarter/Indiegogo… only its much more satisfying to do it yourself.

          4. Glad you got it to work! I like the voice recognition feature. I’ve never heard of hook. Strange they started their campaign a couple months after this post…

  68. @ROBOTICJ – I had the same exact issue with my receiver initially. I returned it to Amazon and had to order a new set. Once I received the new set everything worked exactly as intended. Good luck!

  69. lol.. it didn’t like the tags. lets try again:

    $rfPath = ‘/var/www/rfoutlet/codesend ‘;
    $outletLight = $_POST[‘outletId’];
    $outletStatus = $_POST[‘outletStatus’];

    // enter any captured remote rf code below. can be an ON or OFF command from any channel 1-5. //////
    $CapturedCode = 4527411;
    /////////////////////////////////////////////////////////////////////////////////////////////

    /////////////////////////////////////////////////////////////////////////////////////////////
    // no need to change anything below this line ///////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////////
    $Channel1 = 5424; //0 1 0 1 0 1 0 0 1 1 0 0 0 0
    $Channel2 = 5568; //0 1 0 1 0 1 1 1 0 0 0 0 0 0
    $Channel3 = 5888; //0 1 0 1 1 1 0 0 0 0 0 0 0 0
    $Channel4 = 7424; //0 1 1 1 0 1 0 0 0 0 0 0 0 0
    $Channel5 = 13568; //1 1 0 1 0 1 0 0 0 0 0 0 0 0
    $TurnOn = 3; //0 0 1 1
    $TurnOff = 12; //1 1 0 0

    // this sets all bits in the last 14 positions to 0, leaving only the remote group header. //
    // there isn’t a ‘NOR’ command in PHP, so we ‘OR’ to turn on all the bits we want to clear //
    $RGroup = ($CapturedCode | 16383);
    // then we subtract the value of all of those bits to clear them out.
    $RGroup = ($RGroup – 16383);

    if ($outletLight == “1” && $outletStatus == “on”) {
    $rfCodes = array($RGroup + $Channel1 + $TurnOn);
    } else if ($outletLight == “1” && $outletStatus == “off”) {
    $rfCodes = array($RGroup + $Channel1 + $TurnOff);
    } else if ($outletLight == “2” && $outletStatus == “on”) {
    $rfCodes = array($RGroup + $Channel2 + $TurnOn);
    } else if ($outletLight == “2” && $outletStatus == “off”) {
    $rfCodes = array($RGroup + $Channel2 + $TurnOff);
    } else if ($outletLight == “3” && $outletStatus == “on”) {
    $rfCodes = array($RGroup + $Channel3 + $TurnOn);
    } else if ($outletLight == “3” && $outletStatus == “off”) {
    $rfCodes = array($RGroup + $Channel3 + $TurnOff);
    } else if ($outletLight == “4” && $outletStatus == “on”) {
    $rfCodes = array($RGroup + $Channel4 + $TurnOn);
    } else if ($outletLight == “4” && $outletStatus == “off”) {
    $rfCodes = array($RGroup + $Channel4 + $TurnOff);
    } else if ($outletLight == “5” && $outletStatus == “on”) {
    $rfCodes = array($RGroup + $Channel5 + $TurnOn);
    } else if ($outletLight == “5” && $outletStatus == “off”) {
    $rfCodes = array($RGroup + $Channel5 + $TurnOff);
    } else if ($outletLight == “6” && $outletStatus == “on”) {
    $rfCodes = array(($RGroup + $Channel1 + $TurnOn), ($RGroup + $Channel2 + $TurnOn), ($RGroup + $Channel3 + $TurnOn), ($RGroup + $Channel4 + $TurnOn), ($RGroup + $Channel5 + $TurnOn));
    } else if ($outletLight == “6” && $outletStatus == “off”) {
    $rfCodes = array(($RGroup + $Channel1 + $TurnOff), ($RGroup + $Channel2 + $TurnOff), ($RGroup + $Channel3 + $TurnOff), ($RGroup + $Channel4 + $TurnOff), ($RGroup + $Channel5 + $TurnOff));
    }

    foreach ($rfCodes as $rfCode) {
    shell_exec($rfPath . $rfCode);
    sleep(1);
    }

  70. Hi Tim, Thanks for all your work on this.
    I’ve read a number of articles that have quite a detailed output using RFSniffer which includes Protocol, Decimal, Binary and Pulse Length but I only get a single 6 or 7 decimal code. Is the extra detail a feature of the Arduino sniffer or can I change something to get more from my Raspberry Pi?
    Thanks, Don

  71. Thanks for this great reference.

    I already had my outlets working before finding your page (just using a pulse length someone else mentioned as working), however its my understanding you were able to make the rfsniffer actually detect the pulse length? Are you able to tell how to do this, or post the cpp file so it can be compared to the original, or that a personal secret?

    I read through all the comments, and also poked around your git hub page, but couldn’t seem to find any way to determine what code changes to make to enable this extra functionality on my own.

      1. Excellent!

        With your help, I added that line of code, and was able to find out that my pulse length is actually 186. Previously I had it set to 195, and it did work alright, but would sometimes take multiple attempts to trigger an outlet. Now after changing it to 186, it is working rock solid and has not missed a beat.

        Thanks again. This was a huge help. I’m going to check out some of your other projects.

  72. Hi Tim,

    I might be missing one key concept.

    I understand why we’d need the 433 Transmitter, which comes as a package with a corresponding receiver. However, is the receiver merely an extra component we do not actually use in this project?

    It is my understanding that you are ultimately using the Etekcity outlets as the receivers, correct? Thus, the RFSniffer steps are actually detecting those Etekcity outlets?

    Thanks!
    Pete

    1. Yes the sniffer/receiver is only used to capture your code and pulse. Once you them you shouldn’t need the receiver unless you get new outlets

    2. You really only need to receiver if you plan to sniff out the codes your remote is currently using. If you dont care to use the same code as your remote, you can use any codes posted and program your outlets from your Pi.

  73. Rick:

    I an a novice at this and all I need is a wireless way to flip a switch on. I want to hook the transmitter to the break lights in a towed vehicle and have it turn on a LED in the towing vehicle when ever the towed vehicle’s breaks are engaged. i found these on Amazon: Wireless Transmitter and Receiver Link Kit Module 433Mhz for Arduino DIY. They should be the ones you are using. Will they work or is there a simpler way? Your help would be greatly appreciated.

    Bill

    1. Hey Bill,

      It will take a lot more than just the transmitter and receiver. How will you supply power to the trailer? You need a microcontroller to send the signal. In my post I’m using a raspberry pi.

      1. Thanks for your reply

        It’s not a trailer.. The towed vehicle a jeep so there is 12V. When the break pedal in the jeep is pushed by the “break buddy” then 12V would go to the break lights and transmitter. The receiver is also in a vehicle with 12V. What I need the receiver to do is turn on an LED.

        If not the transmitter and receiver mentioned i your posts is there another simple set of components that will work or would be better.

        Thanks
        Bill

  74. Tim:

    What I need is a simple transmitter receiver setup. the transmitter would be in the in the jeep I am towing, There is power in the vehicle being towed. The receiver would be in the truck which is towing the jeep. When the transmitter gets a 12V signal it needs to cause the receiver in the truck to close a circuit ( turn on a LED ). Any ideas?

    Thanks
    Bill

    1. Hi Bill,

      You can probably hack a wireless backup camera transmitter. Just search “wireless backup camera” in amazon and you’ll find one that costs $10.24. You’d have to put some diodes and capacitors along with the led to detect the video signal on the receiver side.

  75. Hi Tim,

    When installing Apache and PHP, should we also proceed with the installation setup associated with “WordPress”?

    Thanks!

  76. Hi Tim,

    Do you know how many sets of Transmitter codes are used by the Etekcity Remote AC Socket product ?

    i.e. – in a typical store (if these were sold in a store) – let’s say there are 50 packs of such 5 Socket + 2 TX packages – there would be 100 such Transmitters, how many set of codes would exist inside these 100 Transmitters ?

    Do you think they would reuse these codes a lot among the 100 TX ? Since the RX would learn the TX code anyway.

    This is out of the curiosity if neighboring houses may have same codes jammed.

    Thanks

    1. Not sure how many channel groups ETEKCITY created, but the logic allows for 1024 different groups each containing channels 1 – 5. Just from my own research, it looks like 5 of the 10 bits used to make up the group identifier may be control bits. That would cut down the groups significantly to only 32. But 32 is still a pretty large number when you consider the thru-wall range of the remotes.

      If you want to be certain that your codes aren’t used by anyone else, make up your own group code that changes at least one of those control bits (1/5/6/7/9 while counting from the left).

  77. Hi Tim,

    I read from other buyer’s review of this remote AC Outlet Switch on Amazon – they dis-assembled it and shows a HS/PT2260 TX IC – which is a simple Encoder IC.

    So is this the Remote Transmitter that you have ? So the learning function resides in the intelligence of the AC Outlet Switch – right ?

    Regards

  78. Hi Tim,

    Follow up questions again.

    Being from the EE background – I am approaching this subject starting from the TX IC PT2260 data sheet – which mentioned it would Transmit 12 codes (8 address + 4 Data or 10 +2) + 1 sync bit.

    How does these bits corresponding to your RFSnif and CodeSend codes. (e.g. : I noticed somewhere you mentioned 6 digit codes for ON/OFF etc) – also how would these below correspond to the PT2260 transmitted codes ? (I think these are in decimal)

    $light1 = [349491, 349500];
    $light2 = [349635, 349644];
    $light3 = [349955, 349964];
    $light4 = [351491, 351500];
    $light5 = [357635, 357644];

    Sorry if these may be basic questions.

    Regards

    1. They are indeed sending 25 bits of data at a time. Perhaps by “codes” they mean 10 2bit address pairs + 2 2bit data pairs (plus 1 single sync bit)? That would make the most sense.

      The top 10 bits (or 5 2bit pairs) make up the group header, and the next 10 bits (5 2bit pairs) make up the channel. Together, those 10 pairs correspond to an exact address for each outlet. The last 4 bits (2 2bit data pairs) make up the on/off command. They all end with a 0 sync bit to total 25bits.

      The sniffed codes leave out the last sync bit. CodeSend adds that back in later. Here is your Channel1-ON command: (I added the hyphens only to visualize the different parts)
      349491 => 10101 – 0101010011 – 0011

      The group code 010101 will get padded with leading 0’s when sent, and a sync bit will be added to the end. Here is the full data that will be sent:
      0000010101 – 0101010011 – 0011 – 0

      The numbers are only shown in decimal to make it easier for the user.

    1. Integrating with HomeBridge is relatively easy with the work Tim has already done. You can create a small Node.js RPC server on the Pi that takes http requests and executes the codesend command based on the params received. Then using the homebridge-http plugin you can have HomeBridge talk to that RPC server to turn on and off the lights. I wrote about that very thing in this article. https://medium.com/@arvinsingla/apple-homekit-hacking-3d2902e7a1df

      I set up a repo here with a version of the Node.js server here: https://github.com/arvinsingla/rfswitcher

  79. Hey Tim,
    I love the tutorial! But, when I send the code, which is an eight or nine digit code, the receiver detects the pulse as 411 most of the time, when I set it to 407. Any ideas why it isn’t sending the right pulse?

  80. Hi Brad / Tim,

    Follow up your reply on 17th Nov – we’ve get the set of Remote and AC Outlet switches in and are playing with it.

    On this set of remote and Outlet switches – they all have a label of “1162” attached to them – I believe they correspond to the address of this set, which is determined by the jumper wires on the PCB – that in term determine the first 5 2 bit pairs

    Do you know how this 1162 translated into the address setting of the PT2260 IC pins ? (If they have a correlation)

    I think these address pins can either be set to “Floating” or “Zero” only (Not “One”) – so the first 5 2 bit pairs would either be “00” or “01”, but not “11”

    Is this correct ?

    Thanks.

      1. Tim,

        It is find and looking for an answer from someone else.

        By the way if I have 2 sets of these 2 Remote + 5 Switches – say one of the sets is “1162” (Set A) and the other set with another labelled code (Set B)

        Can set B be programmed to learn and respond to set A (1162)’s remote controller ?

        Thanks.

        1. Sorry I haven’t yet responded to your previous post. Haven’t had a chance to dig up my captures to look over.

          To answer this question though, yes they can. Each outlet can learn and retain 3 different channel codes. If a 4th is learned, the oldest is lost.

    1. The address correlation is what I’ve been hunting for some time. I’m uncertain if there is one. I’ve seen multiple “codes” have the same address. They did have the same last digit, if that makes any difference.

  81. Hi Tim,

    Thanks for the tutorial. Just looking for a bit of help as it feels like i’m very close to getting it working but for some reason the sockets are not turning on/ off.

    I’ve got the transmitter and receiver setup, I’ve detected the codes from my remote using RFSniffer as well as the pulse length. I recompiled codesend with the correct pulse length. When I run RFSniffer at the same time as sending the code out using codesend, I can see it is received just the the same as if I had pressed the remote, with the same code and pulse length, however the sockets never turn on or off 🙁

    I have an antenna soldered to the chip, but even with the socket literally a few inches from the transmitter it still doesn’t work anyway? Very frustrating!

    Any ideas?

    Thanks

      1. I don’t think they are the exact same chips, I bought similar ones off Amazon.co.uk though and they certainly look identical.

        The outlets are definitely different, just random ones I found on sale in a shop in the UK. But they are 433mhz and I was able to sniff the remote codes using the receiver and that’s what I’m trying to send out. The codes I am sending/have detected are seven digits and the pulse time looks to be 721.

        As I say, the odd thing is that RFSniffer detects the transmitted codes so you’d think that would mean the chips themselves are OK? But I’m out of ideas as to what else it could be, I assumed it was the aerial on the transmitter but I’ve now soldered that in and still the same.

  82. I got a single one of the outlets, without the remote because I figured I’d be using it with the pi anyway, however this is my first experience with these units. Can I somehow send a signal from the pi (433 Mhz transmitter) and teach the outlet that’s it’s signal, or do I need to get a remote and first learn the signals that way?

    1. If the outlets have a learn button, you do not need a remote. You can use any proper code with codesend and “learn” it.

  83. Tim,
    I havd the whole thing working, with RfSniffer. Got all the codes I needed. I had to change my micro sd card with the one with a bigger space. Thats when things stopped working. I can still use code send to switch ON/OFF the switch but cannot see the code any more.
    When I do the following
    sudo /var/www/rfoutlet/RFSniffer I dont see any code when I use the remote to swtich ON/OFF.

    I did the following steps on my new SD Card.
    1. git clone git://git.drogon.net/wiringPi
    cd wiringPi
    ./build
    2. Run: git clone https://github.com/timleland/rfoutlet.git /var/www/rfoutlet

    And nothing comes up, any suggestions.

    Thank you
    SN

    1. Sounds like it could be a number of different issues. Did you reinstall everything properly? Did you make sure that the gpio pins are connected the same way? Try the old sd card and see if it still works.

      1. Tim,
        I did tried pretty much everything
        1. Checked the gpio pins (they were the same)
        2. Tried the old sd card (did NOT work)

        What worked earlier, didn’t seem to work anymore. My old sim card also had could not get the codes.

        Could the receiver have gone bad?
        I am able to send commands to turn on/off the switches. But I cannot read any new codes.

        Thanks

  84. I had to tinker with this a bit. The default setup and code is a nice starting point to figure out what is going on, though. My issue was that the pulse was not consistent from the remote. It would range between 184 and 189. Sending only one signal would not work consistently. So I modified codesend.cpp and put a a loop to cover the most common pulse values with a call to send after each. After I compiled and moved it to the correct directory, it seems to be working well. I also changed the request method in the PHP file to $_GET for easier testing.

  85. I’ve run into one problem with this setup. I’ve managed to use the RFSniffer to get the codes from my remote, but they are only 5-digits (65556 for off and 65557 for on, on channel 1) with pulse 330. I’m able to use this code if I use codesend in the terminal, but it’s not working via the toggle.php even though I’ve changed the codes to match my codes. Any suggestions?

    1. Might be that I figured out the problem. I’m using Rasbian Jessie and the toggle.php line $rfPath = ‘/var/www/rfoutlet/codesend ‘ . $rfCode should be like this $rfPath = ‘/var/www/html/rfoutlet/codesend ‘ . $rfCode
      because of the changed directory in Jessie.

  86. Hi Tim,

    Really great article, I’ve just started getting into using the raspberry pi, and was planning for this to be my first project. The one thing I’m unsure about is the outlets, unfortunately since I’m from the UK it’s quite hard to find Etekcity branded outlets, though I did manage to find these on eBay

    http://www.ebay.co.uk/itm/Remote-Control-Sockets-Wireless-Switch-Mains-UK-Plug-Programable-3-Pack-1-Remote-/351609277422?hash=item51dd8bcbee:g:73EAAOSwwE5WXQMn

    It does say the frequency is 433 and they look very similar so hopefully there isn’t any issues, I’m planning on testing this out shortly, so I will let you know how it goes.

    Sam

    1. Hi Sam,

      I am also interested to know whether this would be because where I am located – we use same UK (13A) AC wall sockets – the best thing you can help check is to open up the remote controller and check the Remote transmitter encoder IC – whether it is the same as the US counterpart.

          1. Yes they are, press the button on socket for 5 seconds to reset, then press remote on button for 2 seconds and it is reprogrammed. They come with full instructions for resetting and programming.

      1. Hi Keith or others,

        Do you find these similar (Programmable) remote AC wall socket with EU (and/or Australia) plug type – selling on Amazon / E-Bay ?

        Thanks.

  87. Hey, great article! I’ve gotten it mostly working. I’ve recorded the codes and I’ve verified the transmitter works by running codesend directly with the codes.

    The problem I’m having is with the web page. I installed Apache (on a fresh Rasbian install) but the document root appears to be in /var/www/html/ instead of just /var/www/. I tried moving the rfoutlet folder to the document root. It loaded but the buttons did nothing.

    Any thoughts?

    1. Hmm, I edited /etc/apache2/sites-enabled/000-default.conf and changed the document root back to /var/www/ but it didn’t make a difference, the buttons still didn’t work.

        1. I also took another commenter’s advice (since I’m also running Rasbian Jessie) and modified the $rfPath variable in toggle.php to /var/www/html/rfoutlet/codesend but no luck.

          1. When trying to turn them on/off from the web page, what response are you getting back from the pi? If you are using chrome, you can open developer tools and see the response.

        2. Replying here since I can’t reply to your latest comment.

          I’d checked the console in Chrome but didn’t see anything, but I just tried it in Safari and I’m seeing the following error when I press the buttons:

          [Error] Failed to load resource: the server responded with a status of 412 (Precondition Failed) (toggle.php, line 0)

          1. Yep, codesend runs fine without sudo when I run it directly in the terminal.

            And looks like my previous comment got mangled by some formatting, the URL I was using was http://192.168.0.100/rfoutlet (where that’s the IP of my pi, obviously).

        3. Figured it out. I must have somehow disabled PHP in the apache configuration because after some more testing I figured out that apache wasn’t serving up *any* PHP files.

          Thanks for taking the time to reply, and again for putting all this together!

  88. Can’t seem to get past running RFSniffer. Just sits there and is blank. Can’t figure out what the issue is, I tested the GPIO pins with LEDs and they seem to work properly (turning on and off the LEDs) so I know the pi and the wiringPi library work but can’t get the receiver/transmitter to work. Any thoughts / debugging tips? Thanks!

      1. Is there anything I can do to check they’re working? What are diagnostic steps I can go through? Is there another program I can run to see if your code isn’t playing nice or something? I’m at a loss for what to do :/

          1. I mean it wouldn’t run if something was spelled wrong no? Like i would get a normal terminal error.

  89. Hi Tim,
    I love this project! I am new to programming and to Raspberry projects, but I am having fun with this! I have managed to get all the way to just past step 7, but when I try to log on to the web using this url: http://192.168.0.105/rfoutlet , I get “Not Found” “the requested URL /rfoutlet/ was not found on this server” . I play with this late at night, so fatigue could play a part. Here is my toggle php file:
    true, ‘rfpath’ => $rfpath]);
    ?>

    I can get it to work on the command line and without Sudo, so I think I am on the right track. Any suggestions?

    Thanks,
    Dann

          1. I think you may just be visiting the wrong url path. What is the full directory location of the rf project folder?

  90. I did a clean install and I am having an issue when trying to compile, and then the moving and replacing of the file:
    pi@ZiggyPi:~ $ sudo make codesend
    make: *** No rule to make target ‘codesend’. Stop.
    pi@ZiggyPi:~ $ mv -f codesend /var/www/rfoutlet/
    mv: cannot stat ‘codesend’: No such file or directory

      1. Yeah, I have the codes and they work from the command line. I still just can’t get it to work with the web. That’s why I did the clean install and set up because my original directions were outdated and never mentioned Compiling and Moving and overiding the old codesend.

          1. Ok since you’re on Jessie you should have an html folder. I think you need to move your rfoutlet folder into the html directory. So your path should be /var/www/html/rfoutlet

          2. Eureka! We’ve got it! Your latest updates worked for me. I was having trouble moving the file, so I did another clean install and started over. The key factor was to add the “html” in all lines that that had “/var/www/rfoutlet” in them. Simply changing them all to “/var/www/html/rfoutlet” did the trick! Well, actually I got the page error on my first try. But then I remembered that due to the fresh install, my IP may have changed, and it did. I put in the correct IP and Voila, Good to go!
            Thanks for being a great teacher. What’s Next? Ha Ha.

    1. IT WORKS NOW!!!!!!!!
      I originally had the sniffer hooked up to GPIO 21 as suggested and nothing worked…. I moved it to pin 27 and it picked up the ppulses! Thank you so uch for the tutorial.

      Sorry to make the post count longer maybe it will help someone with a V2-B.
      (and to think that I get paid to trouble shoot… I posted a message

      BTW my button#2 seems to be 1332675 and 184. I cant wait to make a slick web interface!

  91. Came here from the Amazon page, really appreciate you putting up a link and offering this plethora of information. Can’t wait to get started with these. Cheers!

  92. Thanks again for the ideas!
    I’m making this work on my garage door (since im down to 1 opener with an old battery…) using a wired relay and python, but using your php, html, and java scripts because im really lazy, and not very smart. If anyone wants some ideas here is how I did it. (its messy and “quick and dirty”)

    I commented out the line with “shell_Exec” and added: “exec(‘/usr/bin/python3.4 /var/www/html/garageDoor/led.py’);” underneath. had to set 4755 for python3.4 and “my” script.

    To make it look better i block commented out the 4-5 div tags in the index.html and also removed the “OFF” div and renamed “on” to “toggle door” or something, and used inline css to change colors. Now I just have to get my tasker app to run this when my phone connects to Bluetooth.

    —python—script—
    #Remember that 25 is physically 22!
    import RPi.GPIO as GPIO
    import time
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(25,GPIO.OUT)
    #print “LED on”
    GPIO.output(25,GPIO.HIGH)
    time.sleep(1)
    #print “LED off”
    GPIO.output(25,GPIO.LOW)

  93. Tim, once again I can’t thank you enough!
    Now I’m using tasker on android to send a custom post request methods to the pi like: Postdata=outletID&outletStatus=on

    So when I plug my phone in to charge various lights turn off. and when its unplugged in the morning my lights turn on in sequence. Maybe ill add my coffee pot to this as well 😛

  94. Hello Tim,

    This was a very helpful guide, thank you for taking the time to put it together! I am having an issue and I’m trying to determine if I ruined my receiver. I have everything wired correctly, I checked about 100 times, but when I run ./RFSniffer there’s nothing returned when I push the buttons on my remote.

    I added an else statement to the FRSniffer.cpp file after “if (mySwitch.available())” to see if it’s not being initialized and it’s not. Essentially it’s not being created by the constructor or something. Do you think this is due to bad hardware or something else I have done with my system?

    Thanks for any tips you might have!

    1. Glad you’re enjoying the guide! Are you using the same outlets and receivers I use in this guide? Are you positive you have everything wired correctly?

      1. I am using the same outlets and receivers as the guide. The wiring appears to be correct, but I ordered another set of receiver and transmitters which will be here tomorrow to see if I did mess them up. I could try the other remote too, I only tried the one but it was turning an outlet on and off which is what I expected.

        I’ll keep at it and post an update when I figure it out. I went as far as a different bread board and wires. This will just make success even sweeter when I get it to work!

        1. I had the same issue at first, and read up on GPIO pinouts. There are so many variations…

          Here Mr. Grodon uses his own pinout scheme for wiring-pi. So “Pin 0” in wiring-pi world would physically be “pin 11” (on a B+ model). And that would also be labeled as “gpio 17”. That threw me for a loop when I first bought it! And some python scripts use BCM. Its alphabet soup 🙂

          Chart: https://projects.drogon.net/raspberry-pi/wiringpi/pins/

          Once you get it working; check out autovoice plugin, and you can integrate it into google now voice commands to toggle stuff. I got my house rigged with voice commands now 🙂 I ran out of wireless dongles and just bought some relays and ran some wire.

  95. Trying to access this from my Galaxy IOS phone remotely. I installed TightVNC on my Raspberry Pi 2, and androidVNC on my phone. It works if I am on the same network, but if I get off the network It does not connect. Any Suggestions?

    1. Just running VPN software isn’t going to create an external network.
      You need to configure your router to pass requests to the Pi. If you have no other web based server (including allowing external connections to setup in your router), then you can forward all port 80 traffic to your Pi. I would use a non-standard port externally to route to port 80 internally so others can so easily get in.

      I’d suggest finding a free DNS service like http://www.noip.com/free

      Most routers support this or other similar services to automatically update the IP when your ISP gives you a new one.

  96. Next question is for the addition of more outlets. I have 13 different codes, so I can control that many outlets. Modifying both the index.html and toggle.php only gave me a couple smaller boxes that did nothing. here is what I added:
    Test Aux

    On

    Off

    All Sockets

    On

    Off

    1. Not sure why it did not post my edits correctly. I basically copied the lines from the number five outlet and changed the numbers sequentially. I did the same for line six to the final numbers.

        1. That’s pretty much what I did, but when I go to my browser, it is non functional.
          Is there a way to post a pic? I am sure I am just missing an edit somewhere.
          Thanks,
          Dann

          1. I did add the codes in toggle.php, and Yes, I think I did it right. Here is an example of my edit for the Data outlet ID: Lines copied: “data-outletId=”5″ data-outletStatus=”on” class=”btn btn-default toggleOutlet”>On
            data-outletId=”5″ data-outletStatus=”off” class=”btn btn-default toggleOutlet”>Off”
            I left out the start and finish code hopping it would post. I changed the 5’s to 6’s and in the final lines I changed the 8’s to 7’s. if that makes any sense.

          2. I get no errors, just odd squares and the last on / off are not aligned. Just sent you a message.

          3. Yea looks like you are missing the class names on the buttons. They need the classes “btn btn-default toggleOutlet”

          4. Well that took care of it! When I copied the the lines in the terminal, I did not realize that it cut out the “btn btn-default toggleOutlet” line.
            I now have 10 “On / Off Buttons all with individual codes and Button #11 turns all On or Off! Now all I need is a 110v Deadbolt solenoid and I can incorporate door locks! Thanks again Tim! Your awesome!

            Dann

  97. I have been using your rfoutlets codesend and RFSniffer on the rpi model b+ with Volumio 1.55
    has worked like dream for the last year
    Have now upgraded to rpi 2 model b v1.1
    Volumio works. RFSnifferworks
    codesend does not have a led across data
    the led flickers for about 30 seconds hould only be 10 cycles
    the card works ok on the older model have updated upgraded wiringpi etc
    please help

      1. the pin numbers are correct can turn on off with gpio command
        looked at the output with analyser. a series of 1ms pulses going up to 10ms over 10 second period
        maybe a timer or interupt not set

        put the card into the last model pi all works

        1. It wil work if installed on a raspian image
          When i install it on Volumio 1.5. or idaudio image
          and plug card in model b it Works
          When i plug it into the new Model 2 V1.1
          RFSniffer works and gives out the correct readings
          codesend 123456. displays correctly
          but the output pin 0 flickers for about 10 seconds
          if i change it to another port it does the same thing
          Put the card in the older model all is good

      2. The pins are correct still not working if by changing pin number
        rfsniffer works
        i posted some other posts instead of replying never used a forum before only looked

        works if i install it on a raspian image but not on volumio or iqaudio
        but ok on the older model pi

  98. Morning, The manual code sendworks, but the website does not. Is there a debug mode/log I can look at that will tell me a button has been pushed and what the output of the button is?

    1. You can open dev tools in your browser and see if there was an error. Also did you verify that you can call codesend with sudo?

      1. It works without sudo. Just as the pi user. I looked in Chrome developer tools, but didn’t see any errors.

        1. Hi Lee, not sure if you are having the same issue as me, but my problem was that I only installed apache in step 4 and forgot php, once I installed that the buttons worked via the web-page.

          1. Hi Adam, I did miss that step initially, but I did go back and install it. Still nothing happens. Is there a config that tells Apache to recheck for php?

          2. >”Hi Adam, I did miss that step initially, but I did go back and install it. Still nothing happens. Is there a config that tells Apache to recheck for php?”

            No, once I install php from step four it works… are you sure you updated toggle.php properly with the same information that works manually when you run codesend? That’s the only other thing I can think of right now that would cause it not to work :/

  99. No, once I install php from step four it works… are you sure you updated toggle.php properly with the same information that works manually when you run codesend? That’s the only other thing I can think of right now that would cause it not to work :/

  100. Glad I found this. It works awesomely. I’m using this for a school project and I’ve made some changes to how the web button works. Instead of 2 buttons for each outlet, I have one that toggles. Still buggy, but I’m not done with my project. Keep up the good work!

    1. Thanks that’s great. The trouble with toggle is you don’t get feedback that the outlet is on/off so it may get out of sync. Were you able to solve this?

      1. That’s true! I just found out about this! I checked if the function in the script is after sending the code after the alert, but it somehow misses it. Here is the code I have so far.

        https://jsfiddle.net/kwfatda5/1/

        It was so hard to understand what I was doing. Javascript lies too much!

  101. Do you ever have reliability issues with the outlets?
    meaning ON command was sent, but the outlet/socket did not turn ON and vice versa for OFF?

    I had an audio amplifier connected to one of them. whenever the outlet is ON and the amplifier is ON, the outlet has trouble receiving commands. the outlet behaves much better then the amplifer is OFF.

      1. how do you deal with it then?

        i mean.. when your cron is supposed to turn off the power and it doesn’t actually turn off..
        that severely affects confidence in the automation

        i’m coming from the point of view where 1 failure in 10,000 is ok, but my rate seems to be like 1 in 10

        my 433mhz unit has a transformerless power supply (1 failure in 10)
        i have another 315mhz unit with a switched PS which has never failed (assumed to be 1 failure in 10,000)

        do you know which PS yours uses?
        do you think the PS is the cause and will you attempt to “fix” this?

        thank you

  102. Tim,
    When I tried to open web interface for rfoutlet, it says page not found. I did check my rpi ip by ifconfig function and the Apache web page opened successfully, but when I added /rfoutlet/ to the link, it did not find the web page. Any suggestions?

  103. Do you know of any problem with repeatedly sending either the “on” or “off” signal to these outlets?

    I’m setting it up, with the help of a water detector to turn on (and off) a wetvac when I get water in my basement. I’m thinking I’ll just set up a cron job that polls the moisture sensor once every 5 minutes, if there’s no moisture it sends the “off” code (regardless of if the unit was on or not previously) and if it senses moisture it sends the “on” code (regardless of if it was already on from the last poll)

      1. You will burn them out if you continuously switch them ON/OFF, but if the device is OFF and you send an OFF (or ON and you send an ON), it will have zero effect on the outlets. They are always “listening” to everything on the same frequency, but only react when it’s time to flip the switch.

        1. You set up a variable or a status file which records the last value sent. If no change don’t send the command, if it is different, send the command.

          1. You’re better off just sending the commands in case they weren’t actually received the last time.

  104. Hello i see your web from a coment on amazon! and wonder if you think in a way to make these outlet run on 220 v since only 110 versions are available and i live on Uruguay!!! I have one similar and could see that the supply is a capacitive one.

  105. Anyone have any idea how I could go about figuring out the distance between a device that is accessing the ip of the raspberry pi so that I cpuld have lights turn on based on my location?

    1. This would be possible if you made your own native app and used geo fences. You could also turn the lights on when your phone connects to your wireless router.

  106. I followed your instructions and got this to work maybe a year ago, and I’ve been very happy with it. Another question, is there a url that could be entered into a browser address bar that would turn these lights on and off? I’m trying to figure out how to use an IoT way of turning these on and off, and the easiest I can think of is to use IFTTT to go to a “website” to turn on or off these lights.

    Thanks!

    1. I have not used iftt with the lights but it would definitely be possible. Most likely you would need the pi to ping for an incoming email or api since the pi is behind a firewall. Anyone else set this up?

  107. After sniffing the codes and pulse length, it takes anywhere from 10-15 “codesends” to actually switch the outlet, using -l and the correct pulse length. Any idea why it takes so many attempts?

      1. It’s 6 inches away, no antenna. I tried another pi and another transmitter, same outcome.

        Maybe I have too much interference at my work bench, I’ll try moving the setup elsewhere.

        1. That could be it. You should try attach a small wire to the antenna hole in the transmitter. I used a single wire from a cat 5 cable and it greatly improved the range

  108. Thanks for this tutorial!
    Everything went smoothly for me except when I went to run RFSniffer in step 6. Nothing was printed to the terminal. I even tried holding my remote less than an inch away from the receiver, in case it was a reception issue, but no luck. I also tried it with 2 different receivers, in case on was faulty, and neither worked. Do you have any tips for troubleshooting this? This is my first Raspberry Pi project, so any help is appreciated.

      1. Is there anything that needs to be done to the code? I’m running RFSniffer and nothing comes up when I’m pressing the buttons on the remote.

        Could it be a faulty 315mhz receiver?

          1. Okay, I ordered a new 315mhz receiver/transmitter for my pi and I can receive and transmit the codes just fine. The thing is, my outlets aren’t switching on or off.

            I do want to note that the remote that came with the outlets only respond to button touches if I hold it more than half a second. Could that be a problem? How would I be able simulate a longer button press with the script?

          2. It’s possible the remote just takes a second to send the single. Have you tried to capture the signal from the remote?

          3. By capture the signal from the remote, you mean Step 6 in your guide? If so, yes. I have already captured each button and pulse. The pi receiver even picks up the proper codes and pulse when sending via the codesend command or the rfoutlet toggle switch webpage.

            Any other suggestions? I don’t think it is an antenna issue. I have soldered the proper length of cat5 wire to the transmitter. The wireless outlet is also within inches of the transmitter and it still isn’t responding.

          4. Okay, I think I’m getting somewhere. I hooked the the receiver to an arduino uno. Using the serial monitor and my physical remote prints:

            Received 11384 / 24bit Protocol: 1

            Sending the same code via the pi/transmitter the serial monitor prints:

            Received 11384 / 15bit Protocol: 2

            So now my question is – Is it possible to modify the protocol from 1 to 2 on a raspberry pi ? 24 bit to 15 bit?

        1. Oops. I got it backwards.

          I meant to say, would it be possible to change the protocol from 2 to 1? 15 bit to 24bit?

          1. Hi,

            I think I am on the same boat and you and Adam.

            Looking into Tim’s code, I have a feeling this
            mySwitch.send(code, 24);
            codesend.cpp line 78, may alter something, considering the send method under RCSwitch and passes the code and the int 24 to method dec2binWzerofill. where the int (24) is the bitLength variable and this method converts code to binary with bitLength.

          2. Hi RY,

            Not sure if you got anywhere on this, I modified Tim’s source code to allow for Protocol, bit Length, and even a repeater (which is actually built in to RCSwitch)

            However, it seems even mimicking the signal RFSniffer was getting from the remote exactly (I’ve also modified the display code to print out the Protocol, Bit Length, and Delay in RFSniffer), the outlet still wouldn’t respond.

            Just wondering if you or anyone else figured this out, considering I have several sets of these and would prefer to use them as oppose to replacing them the 433 Mhz one….

  109. Hello all

    I was able to all the steps above perfectly and it all worked except the last step where I open webpage and click on buttons.

    I ran the command with code from command line, and it works fine but it doesnt work in the UI. I double checked the codes in toggle page and it all looks good. Not sure why its not working in UI.

    Any suggestions will be of great help.

    Thanks
    San

    1. If you’re using google chrome, open dev tools and see if you are getting any errors in the network tab. Also make sure you change permission of codesend program so sudo isn’t required.

      1. I am using Raspberry Pi’s default browser and I have ran the below commands, still no luck.

        sudo chown root.root /var/www/rfoutlet/codesend
        sudo chmod 4755 /var/www/rfoutlet/codesend

  110. When I hit the buttons, I see no errors either.. so weird.
    ——————
    General
    Request URL:http://192.168.1.110/rfoutlet/toggle.php
    Request Method:POST
    Status Code:200 OK
    Remote Address:192.168.1.110:80

    Response Headers
    Accept-Ranges:bytes
    Connection:Keep-Alive
    Content-Length:1859
    Date:Wed, 08 Jun 2016 04:28:10 GMT
    ETag:”743-534bb223f25e1″
    Keep-Alive:timeout=5, max=86
    Last-Modified:Wed, 08 Jun 2016 02:33:41 GMT
    Server:Apache/2.4.10 (Raspbian)

    Request Headers
    Accept:*/*
    Accept-Encoding:gzip, deflate
    Accept-Language:en-US,en;q=0.8
    Connection:keep-alive
    Content-Length:27
    Content-Type:application/x-www-form-urlencoded; charset=UTF-8
    Host:192.168.1.110
    Origin:http://192.168.1.110
    Referer:http://192.168.1.110/rfoutlet/
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
    X-Requested-With:XMLHttpRequest

    Form Data
    outletId:2
    outletStatus:off

      1. Yes yes. I verified and just to make sure ran this again. Still no luck.
        sudo chown root.root /var/www/rfoutlet/codesend
        sudo chmod 4755 /var/www/rfoutlet/codesend

        It is weird, when I looked at network log, I see it is passing
        outletId:2
        outletStatus:off

        1. Hmm sounds like your issue in the toggle.php file. Can you double check the variables are set correctly in toggle.php?

          1. Thank you guys for extended support. But I am not sure what is happening here.

            I checked toggle.php and code are fine. I tested by taking those codes and ran it manually by calling ./codesend with code and it worked .

            Also, I checked the path for codesend in toggle.php file and its specified as “./codesend” which seems to be right as those 2 files are in same directory.

            I went a step ahead and created 2 simple shell scripts, one to turn on and other to turn off and ran those scripts and it worked.

            SO I took those scripts and included in index page to see if it works, but even that didnt work.

            At this point, I think the issue is with codesend not able to execute from webpage. But I saw the permissions and seems to be correct.
            see permissions below.
            -rwsr-xr-x 1 root root 4096 Jun 7 18:55 codesend

            please advice.

          2. Have you altered the security of your web server, maybe preventing root from having any permissions. Good security practice is usually to remove root permissions from /var/www and only allowing www-data permissions. If this is the case codesend will not work.

  111. Hi Tim,
    The raspberry pi kit which you have mentioned above is not THAAAAt expensive but why is that particular version of raspberry pi you have suggested? Can I buy a cheaper version? Super excited to start the project…

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

    Greg

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

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

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

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

  116. 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. The webpage should be posting to toggle.php which should be the same directory that codesend binary is in. Verify that you ran step 7 from the post and that you change your path to /var/www/html/rfoutlet/codesend.

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

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

    Thanks

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

        1. Thanks glad you’ve enjoyed it! Are you asking if I’ve been able to automate the learn function from the raspberry pi? If so I have not.

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

  120. 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:
    https://goo.gl/photos/FATcHW4ERkUeZcNc9

    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)

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

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

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

    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.

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

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

    export WIRINGPI_GPIOMEM=1

    this solves the following error message

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

  126. 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
    <?php
    $output = shell_exec('/var/www/rfoutlet/codesend xxxx');
    echo "$output”;
    ?>
    I assume this happens because of permission issue.
    Can you please advise me?

  127. 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 :
    <?php
    $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

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

  129. 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… 🙂

  130. 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();
    }

    }

    }
    }

    1. Why not pass your args in instead of hard-coding the outlet and command? Then you can reuse the app for all your outlets.

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

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

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

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

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

      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.

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

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

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

      1. Hi Tim,
        Kind of a noob question. I found a 433.95 Mhz remote outlet. Will I be able to use it here?
        Thanks in advance.

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

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

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

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

      Thanks

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

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

  145. Hi Tim.

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

    Thanks.

    Esteban

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

        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!

  147. 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:
    sleep(0.1)
    now = datetime.datetime.now()
    Now = now.hour * 60 + now.minute
    timewindow1_ok = (19*60+00) <= Now < (20*60+15)

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

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

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

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

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

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

    Chris

      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.

        Cheers,

        Chris

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

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

    1. Thanks! I haven’t come across a 220v outlet. You may have to build something custom. Let me know if you find a solution.

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

  154. 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 “http://192.168.1.79/rfoutlet/” 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?

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

        https://pastebin.com/raw/Hgx12KVL
        https://pastebin.com/raw/eMYjrdeW

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

    Richard

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

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

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

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

    Ari

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

    Thanks!

          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:
            pi@raspberrypi:~ $ ./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:
            pi@raspberrypi:/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?

            Thanks!

          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!

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

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

  164. have been using rfoutlet for the last 3 years
    about to update to rpi3 B+ in the next few months
    any issues yet

  165. Hi Tim,
    I got this all set-up and working… once! Now I bought another set of Etekcity plugs and I cannot get the RFSniffer to run…??? I am no expert when it comes to Raspian, so I have no idea why the script isn’t running. I get no errors in the terminal window (when I type the command withOUT typos anyway!) It just returns the “blinking cursor” and nothing happens when I press the buttons on the remote. Any ideas?

    1. Never mind… got it! Guess I wasn’t close enough. I don’t recall the 1st time having to be with INCHES, but it worked when I got close. LOVE the utility of “talking” to my lamps. : )

  166. Thanks for your info!! I was trying for weeks to work with my 433 mhz outlets and my banana pi. With the files your posted here i can turn all of then on and off perfectly. Now I want to use the script with some application or Telegram bot to do all more easy.

  167. Hi

    I`m trying to send this binary code with ./codesend 110001000110011000010010 -p 2 but i think is too long , do you know if codesend from rfsniffer is able to send this type of codes ?

    Thank you!

  168. Hi Tim,

    What I try to run, RFSniffer (step # 6), it just sits there…..nothing……I looked at the code via nano and it appears as jibberish, nonsense……any ideas?

    This is my release:

    PRETTY_NAME=”Raspbian GNU/Linux 8 (jessie)”
    NAME=”Raspbian GNU/Linux”
    VERSION_ID=”8″
    VERSION=”8 (jessie)”

    Tku,

    Charlie T.

        1. Tim,

          I got it working….was a bad VCC wire to transmitter…..Now I can turn light on and off with Codesend, but the php server part is not working…..when I type in my Pi ip address (http://10.0.0.225/rfoutlet/), a server error message appears.

          Any additional suggestions?

          1. Tim,

            For some reason, I had to move all files to a new directory, /var/www/html/rfoutlet (as suggested above). Now I see the on/buttons on my browser, but there is no action when pressing them (however, codesend still works from command line). Getting there inch, by inch…yes, I re-did step 7.

            Any additional suggestions?

            Tku,

            Charlie T.

            This is how the files appear:

            pi@Spare_Pi:/var/www/html/rfoutlet $ ls -l
            total 92

            -rwxr-xr-x 1 root root 18832 Oct 14 09:34 codesend
            -rw-r–r– 1 root root 3833 Oct 14 09:58 index.html
            -rwxr-xr-x 1 root root 18832 Oct 14 09:35 README.md
            -rwxr-xr-x 1 root root 18832 Oct 14 09:36 RFSInffer
            -rwxr-xr-x 1 root root 18832 Oct 14 09:36 RFSource
            -rw-r–r– 1 root root 398 Oct 14 10:17 script.js
            -rwxrwxrwx 1 root root 1845 Oct 14 10:09 toggle.php

          2. Maybe you have problems with the permission to launch the codensend using the PHP code or you have to put it in the correct location

          3. Tim,

            I simply cannot get the buttons to function…… there are no browser Dev error messages, and I changed all permissions (below), and my code background is very limited. If you have any additional suggestions, great, if not, Thank You for all your support.

            pi@Spare_Pi:/var/www/html/rfoutlet $ ls -l
            total 92
            -rwxrwxrwx 1 root root 18832 Oct 14 09:34 codesend
            -rwxrwxrwx 1 root root 3833 Oct 14 09:58 index.html
            -rwxr-xr-x 1 root root 18832 Oct 14 09:35 README.md
            -rwxr-xr-x 1 root root 18832 Oct 14 09:36 RFSInffer
            -rwxr-xr-x 1 root root 18832 Oct 14 09:36 RFSource
            -rwxrwxrwx 1 root root 398 Oct 14 10:17 script.js
            -rwxrwxrwx 1 root root 1846 Oct 15 15:04 toggle.php

          4. Have a look to my codesend permission:
            drwxr-xr-x 4 root root 4096 Jun 26 21:43 .
            drwxr-xr-x 5 www-data www-data 4096 Jun 26 21:43 ..
            -rwsr-xr-x 1 root root 18832 Jun 26 21:45 codesend
            -rw-r–r– 1 root root 8196 Jun 26 21:43 .DS_Store
            drwxr-xr-x 8 root root 4096 Jun 26 21:43 .git
            -rw-r–r– 1 root root 3833 Jun 26 21:45 index.html
            -rw-r–r– 1 root root 943 Jun 26 21:45 README.md
            -rwxr-xr-x 1 root root 18144 Jun 26 21:45 RFSniffer
            drwxr-xr-x 2 root root 4096 Jun 26 21:43 RFSource
            -rw-r–r– 1 root root 397 Jun 26 21:45 script.js
            -rw-r–r– 1 root root 1855 Jun 26 23:29 toggle.php

  169. Hi Tim!

    Not sure where I am going wrong. I am getting this error:

    pi@raspberrypi:/var/www/html $ ./codesend 4282115 -l 177 -p 0
    -bash: ./codesend: No such file or directory

    Also, there is no website when I run url/rfoutlet. I am pretty sure I have followed all of the steps correctly to this point. Help, please! 🙂

    1. I think you maybe in the wrong directory. Try changing directories to the rfoutlet folder in /var/www/html/rfoutlet. Let me know if that helps.

  170. Hi,

    Is it possible to equip the outlets with a power meter? So that each outlet would log: time–>kWh.

    Thanks for any advice.
    Jiri

      1. Hi Tim

        I’m using one set of outlets with 4 digits code with success. I’ve bought another set lately. These have 7 digits code starting with 2, like 2820913.
        The issue is when trying to send the code the RFSniffer reads different code. totaly different. And I can’t control them. It is only when it starts with 2. When I change the first digit to 1 instead of two, RFSniffer reads the same code as sent. But this code does not execute the command.
        How can I fix this?

          1. Tim

            They are different for sure. They do not have the dip switches to change the code for example.
            I think the issue is on code lenght. Or maybe there is some kind of code lenght limit in the script? only this lenght code does not get back to reader the same as sent.
            7 digit code is decimal. Can You help me and show some other option to send the code?
            I will send You the exact pairs of sent code and readed one.

          2. Hi Tim

            my mistake. The code Has 8 digits
            when I read the code from remote controller I get
            20982814
            but when I send this code, the sniffer reads
            4206598
            and does not turn the outlet ofcourse.
            and if You change 2 at start (10982814) it will be sent OK. So Im wondering if the lenght of code is the key to solve this.

  171. Tim! You are a saint! Thank you for this excellent tutorial! I was able to get this to work on my pi 4b running octoprint which controls my 3d printer. Fun little project! Now I am trying to get this to work alongside pihole, homebridge, and the printer server.

      1. It did! A quick question! Do I need to install apache to run codesend? I am trying to get this to work on a pi running pihole (uses Lighttpd) I am able to receive codes with rf sniffer. However, when I type the\ codesend command with the rf code code and the correct pulse it says the command has been sent but I am not getting a response form the lights. Curious because I was having issues getting both apache and pi hole to run simultaneously, and I will be using homebridge to toggle the outlets so I do not need a web UI for the toggle.

        1. Hey Bill. No Apache is not required unless you want to serve a webpage to access it from a website. If you are calling codesend directly you shouldn’t need Apache.

  172. I was getting an error message:
    /var/www/html/rfoutlet $ ./codesend
    -bash: codesend: command not found

    I sent days trying to figure it out on a new build.
    Turns out this binary and alot of the make and build commands will not work on 64bit OS
    I reinstalled a 32bit version and it work. For what it worth I was using dietpi 64 bit and it works on dietpi 32bit.

    Thank for the great work on this.

Leave a Reply

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