Introduction: DIY Smart Home (RF Outlets)

Picture of DIY Smart Home (RF Outlets)

I have spend hours and hours of video searching, googling, and website browsing to figure out how to make a DIY smart home as a beginner. I recently got into the Smart Home lifestyle yet I was tired of seeing all of the expensive plugs, switches, and accessories that cost way more than they were worth, just because it was an easy plug-and-play unit. After purchasing my Raspberry Pi 3, I was eager to get into the smart home market, yet didn't want to put a dent into my wallet. After over 80 hours of research and failed attempts, I finally gathered enough knowledge to successfully control any plug in device with the touch of a button or through my Amazon Echo Dot. If you are looking to create a cheap, easy, alternative to a voice or button controlled outlet in your home, you've come across the perfect instructable. In this guide, I will show you step by step on home to setup your raspberry pi, connect RF outlets to it, and create a completely automated beginner smart home system to get you up and running on your future projects. This project will only run you about $70-$120, but will allow you to control over 5 different devices, compared to the $150-$200 it would cost you to buy these products online/in store.

Step 1: Gathering Materials

You will need (to have already):

Computer

SD Card Reader

Wireless Router/Modem


You will need (to buy):

Raspberry Pi 3:

(Pi) https://goo.gl/74WJLQ ($35.70)

(Kit) https://goo.gl/mFPedU ($49.99)

Header Wires:

https://goo.gl/ZgZR1S ($6.99)

RF Receiver/Transmitter:

https://goo.gl/MVqaeA ($10.99)

RF Outlets (Comes with 5 Outlets):

https://goo.gl/qCu9Na ($25.48)

Ethernet Cord:

https://goo.gl/dPaHRJ ($4.43)

Micro SD Card (Class 10):

https://goo.gl/sRDCya ($8.99)

Optional:

Amazon Echo/Echo Dot:

Echo: https://goo.gl/eQvv12 ($179.99)

Echo Dot: https://goo.gl/6C7i4j ($49.99)

Step 2: Setting Up the Raspberry Pi 3 With Home Assistant

Picture of Setting Up the Raspberry Pi 3 With Home Assistant

In this guide I will be giving you a step by step guide with no assumptions or hidden steps. I assume you are brand new to everything here and I will be going over in detail everything from start to finish. Once you've done this once, this can be a 10 minute process that you can setup whenever/wherever you are. If you know how to do a step or already have a step completed, feel free to skip through them and follow along with the rest of this guide. Lets begin...

1. Login to your windows computer and open your internet browser. Download all of the following programs. All are virus free and safe, even though your virus protection software may say otherwise depending on your software.

Putty (click either 32 bit or 64 bit MSI installer link depending on your computer):

https://goo.gl/RDjiP8

Etcher:

https://etcher.io/

Hassbian:

https://goo.gl/1z7diw

Notepad ++:

https://goo.gl/brcZZN

2. Open your downloads and install each one. After all the installs, either pin them to your start menu for easy access or create a shortcut on your desktop.

3. After the installs, open up Etcher and click "Select Image". Select the Hassbian zip file. Next, insert your micro SD card into your computer either directly or via your SD card reader. After inserted, click "Select drive" and select your micro SD card or the SD card reader if you are using one. After selected, click "Flash!" and wait as the Hassbian image is flashed onto your micro SD card.

4. After the the image has flashed onto the micro SD card and you receive the pop up stating it was a success, remove the micro SD card from your computer/reader, and insert it into your Raspberry Pi. Proceed to connect your Raspberry Pi to your wireless router/modem via an ethernet cable. Next, plug your micro USB cable into your Raspberry Pi and the other end into the wall. After all this is done, wait 10-15 minutes for your Hassbian image to install and setup Home Assistant on your Raspberry Pi.

5. Once Hassbian has finished installing, go to your internet browser and type into the search bar "hassbian.local:8123". Press enter and you will be greeted with the Home Assistant web interface. If you do not see this interface, click here.

Step 3: Setting Up PuTTY

Picture of Setting Up PuTTY

1. Navigate to where you installed Putty and open up the program. You will be greeted with a multitude of boxes and buttons but we will be focusing on the "Host Name (or IP address". In the box below, type "hassbian.local" . Next under "Saved Sessions", in the box type a name for your session and then press save. After, click your saved session and click "open". A box will come up, just press yes and you will be greeted with a terminal interface. You will be prompted with "login as:" text, where you will enter the username "Pi" and the password "raspberry". After, press enter and you will be logged into your terminal interface that interacts with Home Assistant.

2. Type the following command:

sudo raspi-config

A new colorful window will pop up. Navigate this window using your arrow keys, but first press enter and follow the steps to change your user password. Next, using the arrow keys, move down to "Localization Options", then down to "Change Timezone" and navigate through the lists to change to your local timezone. Next scroll down to "Interfacing Options", then down to SSH, and enable SSH on your Raspberry Pi. Lastly navigate down to "FINISH!" and hit enter to exit.

3. Next we will be installing Samba - a program that allows us to view our Raspberry Pi via our file explorer and use the Raspberry Pi over SSH. To install Samba copy and paste the following code one line at a time making sure to hit enter each time.

sudo apt-get update
sudo apt-get upgrade
sudo hassbian-config install samba

4. Open up your file explorer and navigate to your "Network" tab on the left hand side. Right click in blank space and hit "Refresh". You should see after a couple of seconds, "HASSBIAN" or another name for your Raspberry Pi show up under the list of computers. If you do not your Raspberry Pi, click here.

Step 4: Wiring the RF Receiver/Transmitter to the Raspberry Pi

Picture of Wiring the RF Receiver/Transmitter to the Raspberry Pi

This is one of the easiest parts of the build and requires a tad bit of patience and good eyesight. Open your header wires and select 8 different colored female-to-female wires and separate them. Open up your RF Receiver/Transmitter modules and lay them out. Next, follow this schematic and this GPIO diagram to help guide you in connecting the transmitter and receiver to the Raspberry Pi.

NOTE: When using the pictures as a schematic, notice that the pins on the transmitter/receiver in the pictures may be in different places that on your actual transmitter/receiver pair. USE THE BOXES IN THE PICTURES AS A GUIDE IN WIRING YOUR TRANSMITTER/RECEIVER TO YOUR PI IF PURCHASED FROM THE LINK ABOVE!


Transmitter Module (SMALL ONE):

DA --> GPIO #17

VCC (Blank Space) --> +5VDC

G --> Ground

Receiver Module (LONG ONE):

Use left side of receiver

+5V --> +5VDC

DATA --> GPIO #21/27

GND --> Ground

Once wired, unbox your RF Outlets if you haven't already, and take out your first outlet. Put the included battery into the remote. Plug in the outlet to the wall and wait a few seconds. Proceed to hold the button located on the side of the outlet for 5 seconds or until the front red LED begins to blink. Once the LED is blinking, press the #1 ON/OFF buttons on your remote, this will link channel 1 to the outlet and have the outlet controlled via the remote.

Step 5: Linking RF Outlets With PuTTY

Picture of Linking RF Outlets With PuTTY

.In order to link your Raspberry Pi to the RF Outlets, we first must figure out the signal code that the receiver/transmitter must learn to intercept. To do this, we will install two programs onto the Raspberry Pi: WiringPi and RFSniffer.

1. Open Up PuTTY and login to your Raspberry Pi as we did before

2. First we will install WiringPi. Type or copy and paste the following commands line by line.

sudo git clone git://git.drogon.net/wiringPi 
cd wiringPi
./build

To confirm WiringPi has properly installed, issue the following command.

gpio -v

3. Next we will install RFSniffer. Type or copy and paste the following commands line by line.

sudo git clone git://github.com/timleland/rfoutlet.git /var/www/rfoutlet
sudo chown root.root /var/www/rfoutlet/codesend
sudo chmod 4755 /var/www/rfoutlet/codesend

After the program is installed, use the following command to launch the RFSniffer program.

sudo /var/www/rfoutlet/RFSniffer

4. A blank screen should occur near the bottom. At this point, use the included remote to find the code each button on the remote produces. We are only looking at the long 7 digit codes. Dont worry about the other numbers.

5. Open up Notepad ++ and open up a new file. Save this file as "RF Codes". Proceed to record each code from PuTTY into Notepad ++, starting off with all 5 ON buttons, then all 5 OFF buttons. Make sure each ON number is corresponding with the same number OFF button.


6. To test your codes and make sure everything is working properly, type in the following commands line by line.

sudo /var/www/rfoutlet/codesend #######

Replace the 7 # with your 7 digit ON/OFF codes.

Step 6: Linking RF Outlets With Home Assistant

Picture of Linking RF Outlets With Home Assistant

We will be using a home assitant addon called Raspberry Pi RF Switch which will allow us to use the codes recorded in the last step to link Home Assistant with our RF outlets

1. After all your codes have been recorded, go to your internet browser and go to this link https://goo.gl/xAV7Ai.

2. Open your file explorer and open up your HASSBIAN device in the "Network" tab. Click the "homeassistant" folder, then open up the "configuration" file.

NOTE: Be very careful when making changes to this file, any small spaces or extra letters can cause Home Assistant to crash or not work correctly so follow my directions very carefully and use the included pictures provided to make sure you are doing things correctly.

3. In the "configuration" file, scroll all the way down the the bottom and click at the end of the line of code that reads "automation: !include automations.yaml". Click enter twice and copy the following code from the link above or use the edited code below.

switch:
  - platform: rpi_rf
    gpio: 17
    switches:
      OUTLET NAME:
        protocol: 1
        pulselength: 180
        code_on: #######
        code_off: #######

4. READ CAREFULLY: The only things you will need to change on this code is the line that reads "Outlet Name", delete this and replace it with a custom name for your outlet. Make sure the beginning of the line stays lined up to where is is now, no not move it up or back. The last thing you must change is the "code_on" and "code_off" lines. Replace the 7 # with your 7 digit code for your first outlet. Make sure to put the ON code with the "code_on" line and OFF code with the "code_off" line.

5. Make sure you've typed everything correctly and compare with the image below to make sure everything looks the same with the exception of the Outlet Name and the ON/OFF codes. Once everything matches up, go up to the top and ht file, then save. Exit the "configuration" window.

6. Next we must restart Home Assistant to save our changes. Go to your internet browser and go to "hassbian.local:8123". Go down to the "Configuration" tab and once inside, click the "Configuration.yaml" button. Proceed to click the "CHECK CONFIG" button. This button will make sure your configuartion.yaml file is valid and has no errors. Once clicked, wait for the "Valid!" message. If you do not get this message, please first check your configuration.yaml file and make sure everything is where its suppose to be, with no extra spaces or characters, along with everything being lined up where it should be. If you still run into errors, click here. Login to PuTTY as we have done before and type the following command.

sudo reboot

7. Home Assistant should proceed to reboot. Wait around a minute and then go back to your internet browser and back to the "hassbian.local:8123" page. If you click the "States" tab, you should see your switch with the name you named your outlet.

8. Plug in a device (light, fan, charger ect.) to your RF outlet and go back to your computer. This is the final test...click your switch and watch your device turn on and off! If everything went as planned, you should have a fully working switch controlled via your computer.

Step 7: Linking Home Assistant With Your IOS Device

Picture of Linking Home Assistant With Your IOS Device

1. Unlock your phone and go to the App Store. In the search tab, search "Home Assistant". Download the home assistant app and wait for it to install.

2. Once installed, open the app and tap the gear icon in the bottom right corner. In the URL box, type in "hassbian.local:8123". If you setup a password for your Home Assistant, type that password into the "Password" box, if not, leave it blank. Hit save then hit done in the top right corner.

3. Wait for the app to reload and you should see your switch right in front of you. Test them out and make sure everything works.

NOTE: You may notice that you're switch may not have an animation, that is fine, just a bug in the app.

Step 8: Linking Outlets and Home Assistant With Amazon Echo/Dot

Picture of Linking Outlets and Home Assistant With Amazon Echo/Dot

This step was the hardest for me to figure out as there are little to no updated tutorials on this. As you will see, this is one of the easiest steps in this tutorial. Here we will link your Home Assistant server with Amazon Alexa to have full voice control of your switches and devices on your Home Assistant server.

1. Open your file explorer and open up your HASSBIAN device in the "Network" tab. Click the "homeassistant" folder, then open up the "configuration" file.
NOTE: Be very careful when making changes to this file, any small spaces or extra letters can cause Home Assistant to crash or not work correctly so follow my directions very carefully and use the included pictures provided to make sure you are doing things correctly.

2. Scroll down to where it says "logbook:" and click the end of that line. Press enter twice and copy and paste the following code into your file.

emulated_hue:
  type: alexa
  expose_by_default: true
  exposed_domains:
    - switch
    - light
    - group

3. Click file, then save. Make sure you've typed everything correctly and compare with the image below to make sure everything looks the same. Exit the "configuration" window.

6. Next we must restart Home Assistant to save our changes. Go to your internet browser and go to "hassbian.local:8123". Go down to the "Configuration" tab and once inside, click the "Configuration.yaml" button. Proceed to click the "CHECK CONFIG" button. This button will make sure your configuartion.yaml file is valid and has no errors. Once clicked, wait for the "Valid!" message. If you do not get this message, please first check your configuration.yaml file and make sure everything is where its suppose to be, with no extra spaces or characters, along with everything being lined up where it should be. If you still run into errors, click here. Login to PuTTY as we have done before and type the following command.

sudo reboot

4. Open up your Alexa app on your phone and swipe on the left side to open up the menu. Tap "Smart Home" and then tap "Devices". Click "DISCOVER" and wait 20 seconds for Alexa to discover your Home Assistant devices.

5. If everything was done correctly, you should see your outlet appear in your Alexa app. For the final test...try it out. Say the following command to your Echo/Dot.

"Alexa, turn on [your outlet name]."

"Alexa, turn off [your outlet name]."

You should see your device turn on and off by your voice. Anything you add to your Home Assistant should be available to your Echo, just make sure to run the "DISCOVER" function on the Alexa app each time you want to add a new device.

Step 9: Beginner Smart Home: Complete

Congrats! You are now on your way to building your first smart home/room. I hope this tutorial was easy and you had fun building this setup. If you have any comments or questions, please feel free to email me: benlongjohnp@gmail.com. If you had any trouble during the way, please check out this common issues page where I go over some common issues and problems I had while figuring this all out. I will also hope to answer general questions in the comment section below. Look out on my page int he future for a tutorial on how to make a very easy Android dashboard to control all home assistant devices.

Comments

keets (author)2017-09-10

Very interesting instructable.....BUT....

at step 2 point 1: log in at your windows computer.

There is more than only windows. There is mac. And if people work with Raspberry it's a shame that you forget instructions for Linux.

Raspberry+Linux= no need for Samba either.

BenL184 (author)keets2017-09-10

You are correct and I do have a mac. I just haven't looked into how to do this on a mac yet. That would require a lot of work I'm not trying to do right now. You can basically do all this on a mac though and just configure everything within the Pi using an external monitor.

DIY Hacks and How Tos (author)2017-09-09

Cool. I wish that I could get something like this set up at my house.

Try it out, it's so useful. I have it setup around my dorm and its extremely helpful. Also something cool to show off to guests.

About This Instructable

1,726views

63favorites

License:

More by BenL184:DIY Smart Home (RF Outlets)
Add instructable to: