Setting Up the Raspberry Pi 3 for Home Assistant
With the recent news that Nest’s Revolv was going to shut down its services, I was happy to have chosen open-source for my home automation stack. I’ve been seeing posts crop up on Twitter and Reddit about wanting an “offline” solution (one that works even without the Internet, but still functions within a LAN), and decided to share my experiences with setting up a brand new Raspberry Pi 3 with the open-source Home Assistant platform. As a warning, I must say that I AM still new to this, so I apologize in advance for any errors, but I figured I would share my information as it may help a few people who run across the same issues I had. Hopefully this information doesn’t become too outdated too soon.
An open-source home automation platform ensures that your data is safe, secure, and always available when you need it. You control the system, so you are not reliant on any third-party for services or data (which also means you have no one to blame but yourself if something goes wrong!). I picked Home Assistant partially to start learning more Python (I’m mostly a JVM guy), but I’ve heard great things about other frameworks such as OpenHAB. I chose the Pi 3 for its enhanced processor and built-in Wifi/Bluetooth capability. If you prefer slightly less manual configuration (especially for something like Z-Wave), then you may want to check out the Docker image for Home Assistant as well.
Before starting setup, there are a few things you may need:
– A Raspberry Pi 3 running Raspbian Jessie. The Raspberry Pi site has a great installation guide.
– A micro SD card for the Pi.
– A power charger/adapter for the Pi (I used an old cell phone charger).
– Basic knowledge of Linux Bash commands.
– Basic knowledge of YAML.
– A mouse, keyboard, and HDMI display + cable (temporarily)
– (Optional) Knowledge of Python if you plan on adding features. Also useful for debugging.
If you don’t have all of these, I’d recommend spending the ~$50 to purchase the materials, and a few weekends to brush up on the above.
Configuring the Pi
To start off, I’m going to assume that you can boot into your Raspberry Pi and you have Raspbian Jessie running (Home Assistant recommends this version as it has Python 3.4 already installed). You should hopefully have a mouse, keyboard, and display to interface with it. The very first thing you’ll want to do is configure it for your locale and timezone. Next you
can should change your password. Finally, we’ll connect to Wifi (if you’re not wired) and update the OS from the terminal. After all of these you may need to restart. Here is a cheatsheet:
Installing TightVNC for remote access
Ideally we would like to control the Pi from our main machine(s), rather than having to log into every time. If you don’t mind a dedicated “command station” for the Pi, then you can skip this part. First we’ll install the TightVNC server:
To set up a password and make sure it works, you can run:
Next up, we’ll set it up to run automatically on boot (otherwise we have to manually login to the Pi after each reboot):
I’ve left a few lines in there that are commented out that seemed to cause issues (or were unnecessary) for me, but seemed like it may help in some configurations. As a note, you will probably want to configure the line that starts with “ExecStart” to match the geometry (resolution), depth (color depth), etc. that you may need. My main machine is 1920×1080, so I opted for a slightly smaller display for the VNC client. The “%i” parameter in this case is equal to the “:1” (the display option) that we will pass to the service. So our next steps are to allow that file to be executed on start:
If you want to have a shared clipboard (so you can cut/copy/paste between your host machine and your Pi), then you need to install “autocutsel”:
Then add this line to your “.vnc/xstartup”:
The last step is to download the TightVNC client on your main machine, enter the IP and password, and connect! If you still have any issues, the Raspberry Pi site has a decent resource (although I could not seem to get their autostart instructions working on my Pi). Make sure to uncheck “Disable clipboard transfer” on your VNC client’s configuration to enable clipboard sharing.
Installing Samba for remote file sharing
One thing we’ll be doing a lot with Home Assistant (at least initially), is editing the configuration file. Even with TightVNC, sometimes it’s easier to open up the files on your local machine. As a result, we will set up file sharing for the Pi so other machines on the network can edit the files.
First we will want to install Samba:
Then we’ll need to configure it by uncommenting/adding a couple of lines for Windows support, adding a block of text of our own, and adding a couple lines if we need symlink support:
Symlink support is useful if you plan on having a single “Share” or “Public” folder, and linking (“ln -s src dest”) folders that you want to share into it.
Lastly we will set a password:
Then you can install/configure a client to access the files. If you have a Windows machine and configured the share for it, then your Pi’s files should show up under the “Network” setting.
Now we can change the Pi’s files whenever we want!
Installing Home Assistant
Ok, hopefully the previous steps weren’t (too) bad, and we’re now ready to dive into the fun stuff… installing our home automation framework!
As usual, our first step is to install and run Home Assistant:
Running the “hass –open-ui” command will generate a lot of files that will be useful (and also display an intro message), so be sure to do that even if you plan on automatically starting Home Assistant on boot. At this point, feel free to open up your hass page (on port 8123 of your Pi’s IP) and play around with it.
Next we’ll set it to boot on start very similarly to how we did for TightVNC:
Note that you may need to change the “ExecStart” to point at your hass install. Mine was in a different location than what Home Assistant had listed on their site. Finally, if you changed your username, then be sure that is what follows the “@” in the file name.
And again we will need to configure it to autostart:
You can call “sudo systemctl stop email@example.com” to stop the service, or with “start” to boot it up again. “restart” is useful if you made changes and need to restart the server. Finally, you can run “sudo journalctl -f -u home-assistant@pi” to view a log of your Home Assistant service. I like to keep this in its own terminal for easy debugging through the VNC.
If you have any issues, the Home Assistant site actually has some very good instructions for general setup and autostarting.
At this point, you should have everything you need running! No devices/sensors are yet configured, but you can look over the “Components” page on Home Assistant to see what suits your needs. I’m personally a fan of Z-Wave as it does not require any third-party services.
I’m excited about home automation and willing to share what knowledge I have. I am including part of a copy of my configuration (working as of Home Assistant 0.17.2). The only notable feature thus far is that I have it configured to send me a text when the washer/dryer is done, thanks to Google Voice, a Gen5 Z-Wave Z-Stick, and a couple of Z-Wave Energy Switches. It may not be perfect (and I should probably move it into a couple of scripts), but again, I’m eager to share and contribute to the open-source home automation community.
One thought on “Setting Up the Raspberry Pi 3 for Home Assistant”
I am having a problem with running : sudo pip3 install homeassistant
Traceback (most recent call last):
File “/usr/bin/pip3”, line 9, in
load_entry_point(‘pip==1.5.6’, ‘console_scripts’, ‘pip3’)()
File “/usr/lib/python3/dist-packages/pkg_resources.py”, line 356, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File “/usr/lib/python3/dist-packages/pkg_resources.py”, line 2476, in load_entry_point
File “/usr/lib/python3/dist-packages/pkg_resources.py”, line 2190, in load
File “/usr/lib/python3/dist-packages/pip/__init__.py”, line 74, in
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File “/usr/lib/python3/dist-packages/pip/vcs/mercurial.py”, line 9, in
from pip.download import path_to_url
File “/usr/lib/python3/dist-packages/pip/download.py”, line 25, in
from requests.compat import IncompleteRead
ImportError: cannot import name ‘IncompleteRead’
Any help appreciated.
Looks like it may be an issue with your pip version. Maybe try: `sudo easy_install –upgrade pip` and then re-run the install command?
I hadn’t thought about notifications for the dryer/washer, thanks!
great work, thank you very much