Yes, you’ve read the title right. You can get four WiFi outlets that can be controlled in various ways, including the Google Assistant, IFTTT and Tasker – each unit for under $6. And you don’t have to solder.
(prices converted from EUR to USD)
When buying your RF outlets, make sure that they are controlled via the 433 MHz frequency. Also, keep in mind that some outlets don’t work with this method. Usually, cheap units are perfect for this, as they tend to have only one unencrypted RF code. If you are not sure which one to buy, check out this list of outlets that are known to be working. Mine are from Silvercrest, sold by LIDL.
With the exception of the outlets, I got everything else for cheap from Aliexpress. Yet I still don’t know why they have “express” in their name… By the way, I got my Google Home Mini for just 16€ (~$19) – Black Friday rocks.
All of this added is about $22, so about $6 per outlet. This is a lot cheaper than the smart WiFi outlets you can buy from brands like TP Link, where each unit retails for about $30 (and some of them even need hubs which are sold seperately). So I think this is a very nice deal.
The ESP8266 is basically an Arduino with built-in WiFi. In conjunction with the RF receiver and transmitter, it can record the code the remote sends to the outlets. With that code captured, it can power on or off the outlet without you pressing a button on the remote. And since it has WiFi, we can couple those things together, basically creating a bridge between the two protocols. Now that we control it via the HTTP-protocol, it is essentially “smart” and we can (with some hacking) control it with a lot of different things, like with the Google Assistant or through an web app running on your PC or phone. In the end, we have an API that works like this:
Using RF outlets has many advantages. You don’t have to deal with main’s voltage (which you never should if you don’t know what you’re doing), you can use them for something else in the future and you get a remote in the box with it.
First and foremost, setup your RF outlets with the included remote so that you can actually use them. Then, we need to build the actual thing together. But don’t worry – it’s rather easy. You just have to connect some wires together and that’s it.
Check what kind of development board you actually have. It’s usually labeled on the back or given on the seller’s site. Head over to Google and search for your model + pinout. You should find something like this. Look out for the pins GPIO0, 3.3V and GND. Usually, there are multiple 3.3V and Ground pins, you can choose one of your favor. Connect the RF receiver (usually the bigger one of the two RF chips) to the ESP8266 by connecting GND to GND, 3.3V to VCC and GPIO0 to a data pin of the RF receiver. If you didn’t get it right the first time, don’t worry. There shouldn’t be any permanent damage done to it.
Now with everything connected, we can plug it into the computer.
To get everything up and running, you firstly need to install the Arduino IDE, which you can get from the Microsoft Store or the Arduino website. Once installed, we can open it up to gather all our required dependencies. Let’s begin with the board manager. For that, select File > Preferences and paste in
http://arduino.esp8266.com/stable/package_esp8266com_index.json under “Additional Boot Manager URLs”. Click “OK” to go back. Next, click Tools > Board > Boards Manager, search for ESP8266 and install the ESP8266 boot manager by the ESP community. Restart the Arduino IDE to apply all changes.
To select the proper board, choose Tools > Board and select your board. The name of which is usually written on the back or given on the retailer’s site. I’m using a NodeMCU v3. Now, let’s install the libraries. Go to Sketch > Include Library > Manage Libraries… and search for rc-switch by sui77. Repeat this for the TaskScheduler library by Anatoli Arkhipenko.
We can move on to the interesting part! To capture the codes, plug your ESP8266 into your computer. Click on File > Examples > rc-switch > ReceiveDemo_Advanced and then on the little arrow in the top bar to upload the code. Now move over to the magnifying glass icon in the right top corner to open the serial monitor. Make sure the baud rate is set to 9600. Press a button on your remote and you should see a code showing up. Save the decimal code, the protocol and the pulselength somewhere, we will need it later. Repeat this for every on and off button of your remote, and don’t forget to write down which code corresponds to which button.
Getting closer! But before we can send codes with our ESP8266, we need to swap the RF receiver with the transmitter. Connect the transmitter in the same way as the receiver was, so GND to GND, 3.3V to VCC and DATA to GPIO0.
Now, we need to upload the script that enables the ESP8266 to act like a WiFi to RF bridge. For that, I created a thing called Outlet8266. Get it from Github and open it. Set your WiFi SSID and password and a password for the Outlet8266 API in the code – leave the
duckdns variables empty for now. Then, upload it to your chip like you did with the last sketch. Once completed, open up the serial monitor again and you will be prompted with the IP address of your ESP8266 – from now on called Outlet8266, just sounds cooler.
To see if it actually works, head over to the Outlet8266 web app. Enter the local IP address of your Outlet8266 as well as your set password. When you are successfully connected, you can add your first outlet. Give it a name (like “TV” or “Bed Lights”) and enter the required codes for the on and off buttons. Done! Give it a test and it should work!
Using it just with the web app is kind of boring. Lets bring up the Google Assistant! There are two possible options there. The first one uses IFTTT, but requires to open ports on your router so that the Outlet8266 is accessible from the internet. Or, you could keep your Outlet8266 in the local network by using AutoVoice with Tasker. Each method has some benefits and drawbacks, so choose what’s best for your setup. Of course, if you want to go super baller mode, you could also build your own bot with Dialogflow (previously known as API.ai), but that would probably be too much for this post.
To use IFTTT, you need to bring your Outlet8266 to the rest of the world and out of your local network. That’s done using a Dynamic DNS service and opening a port on your router. Start by going to duckdns.org and create a new account. Continue to register a new subdomain like “awesomeoutlet.duckdns.org”. In the top info bar, you should see your token; copy it. Go back to our Arduino script, but now enter the token and the domain. Then, reupload the script.
After that, you need to change some stuff in your router settings. Open your web browser and navigate to your router’s configuration site, usually 192.168.0.1 or 192.168.1.1. Search for something called Port Forwarding. Set the public and destination port (or port range) to both 80, the local IP address to the one your serial monitor showed you and the protocol to TCP/UDP. There are plenty of tutorials out there on how to do this, and probably also one for your model if you can’t get it working.
Now, let’s connect it finally to the Google Assistant! Open up IFTTT and sign up with your Google account. Go to My Applets > New Applet > +this > Google Assistant > Say a simple phrase and enter your desired phrases (like “Turn on night lights”). Click Create trigger > +that > Webhooks > Make a web request and enter:
To finish it, click on “Create action”. And that’s it! Unfortunately, IFTTT is not that great when it comes to repetitive things, so you have to create a new applet for every outlet, and for on and off. Not the most efficient solution, but it shouldn’t take more than five minutes or so.
Firstly, download Tasker and AutoVoice from the Google Play Store. If you’ve never used Tasker before, I’d recommend to watch a short tutorial, as it’s not as easy at the beginning as IFTTT. But trust me – Tasker is a brilliant app and allows to automate your whole phone and beyond.
Create a new profile by tapping the plus button. A popup will open. Select Event > Plugin > AutoVoice > Recognized. A little window will open. As your commands, set all the things you want to say seperated with a comma, like
lights on,lights off,tv on,tv off. It’s important that these have the same name as the outlets you configured in the Outlet8266 web app. You can get creative with your responses and let it say whatever you want, again, comma-seperated. Now go back. It will prompt you to create a new task. Name it something you like.
http://<your-outlet8266-ip>/api/decimal?pass=<your-outlet8266-password>&code=%code. Optionally, you can also define the protocol and pulselength, which is required for some outlets by adding
&protocol=<protocol>&pulselength=<pulselength> to the end.
With that done, you can now say
ask Autovoice "lighs on". Firstly, that’s not natural at all and secondly you can only type it to the Assistant since the quotation marks are required. To fix that, open the Assistant settings to create shortcut commands. There, you can define what you want so say (like “turn on the lights”) and what it should actually do, which you want to set to something like
ask Autovoice "lighs on" – again, the quotation marks are necessary. And now – finally! – you should be able to say “Hey Google, turn the lights on”.
Now the big advantage over IFTTT is that you can do many things at the same time. That means that “turn on the computer” can not only turn on the outlet, but could also wake up the computer via Wake On LAN.
Of course, you don’t want to have this mess laying around on your desk. So get your project box, make a small hole in it using a hand drill so you can feed through your micro-USB cable. The only thing left to do is to stuff it all in and to close it up.
Also, if you want to boost your signal range, you could solder a 17cm long wire to the antenna pin of your RF transmitter.
As this system is using an open and easy to use API, you can integrate it creatively and without too much hassle in your workflow. For example, I used Tasker to create many shortcuts on my phone to turn on or off outlets, like in my quick tile settings and on my lockscreen. You could even automate it completely and for example turn on lights when the sun goes down – super cool. But of course you can also customize it on the hardware side. Here you could add maybe buttons to the case to control the outlets, or motion detection to turn on things when you enter the room.
However, one of the coolest things you could do is to automate completely other devices! Since the Outlet8266 is basically just an RF transmitter that sends every code you want it to, you could easily create an applet that opens your garage door. As you can see, there is a lot of space for your own creativity – and if you’ve created something awesome, don’t forget it to @krmax44 me.
If you want to push your home automation steps to the next level, I would recommend to check out Home Assistant. It runs on a Raspberry Pi and can control much more than just RF things. In fact, to this point in time it has more than 900 components you can control, like Google Cast, Kodi and a lot of other smart home devices. Definitely take a look at it, it is mind-blowingly amazing. Also, the Google Assistant integration is much better with Home Assistant than it is with either IFTTT or AutoVoice. Speaking of recommendations, I’d strongly recommend to subscribe to BRUH Automation. He creates super cool videos about all things related to home automation. His video about Raspberry Pi controlled outlets was actually a big inspiration for this project.
But if you are less into home automation and more into DIY and tech, check out Great Scott. He creates very interesting videos related to this kind of tech which also helped me a lot with this project.
Thanks for reading up to this point. I hope you learned some things and found it interesting!