How to set up your Raspberry Pi as a home automation server
Now that you have agreed with my previous article, you have selected Home Assistant as your home automation hub! Congratulations!
A key idea you have to understand is that you will be running your hub software on a server. Don’t let the name scare you, it is just a computer that will be running all the time. It has to be running all the time to ensure it can communicate with your smart home devices and can run your home automations.
You now have to make a major choice. Do you want to run Home Assistant as a Docker container inside a specially created environment (Hass.io) or on a traditional Linux installation (Hassbian)? This is the crucial choice because the versions of Home Assistant installed in Hass.IO & Hassbian are different.
Even though there are instructions to do so, you do not want to try to run Home Assistant on Windows. There will be too many incompatibilities and the vast majority of the documentation will assume you are running in a Linux environment. Even if you are not very familiar with Linux, the basic commands are relatively simple to understand. In addition, if you are running Home Assistant as Hass.io (which you should be), you will not be on the Linux command line very often anyway.
I made the mistake when I first began with Home Assistant to run the Hassbian option. This is because I was under the mistaken assumption that I wanted to manage the underlying Linux infrastructure myself (I had already set up Pi-hole and I didn’t understand that I could run it as a plugin in Hass.io).
However, it became clear after a few weeks of running Home Assistant under Hassbian that it was sub-optimal. I had to manually update Home Assistant on the Linux command line. I had to enable the virtual environment to configure it. I could not take advantage of the many excellent plugins that have been developed for Hass.io that make configuration much easier.
Therefore, I only recommend you go the Hass.io route.
Hass.io is the preferred and easiest way to install and run Home Assistant. This takes advantage of Docker to run both Home Assitant and all the additional plugins you will want to run to have the most functional & flexible environment possible.
Docker is a technology called “containerization”. As the name implies, a Docker container contains all of the code & dependencies that a piece of software needs to run. The big advantage of Docker over just installing software on your computer is the “dependencies” part. In the past, ensuring you had the right versions of either .so files or .dll files was terrible (DLL Hell). Docker ensures that all of the code you need is available and isolated from all other processes running on your computer. This ensures reliable installation, updates & running of your application.
Hass.io has been specially designed to run Home Assistant and many plugins using Docker.
Hardware & Software needed to set up your Raspberry Pi
As I suspect many of you do, I run Windows 10 on my primary computer at home. Naturally, this is because it has the best games! However, my primary PC is not used to host my Home Assistant software. It is also not turned on except when I am playing a game, writing blog posts or my wife is using it edit maternity & newborn photos.
Therefore, you will need some crucial hardware & software to bridge the gap between your Windows PC & your Linux machine. Obviously, you may not need all the hardware or software I needed; mix & match as needed (affiliate links below).
- Raspberry Pi – Hosts your Home Assistant installation. I recommend you buy the latest model with the most CPU you can get. Home Assistant is a Python based system and needs plenty of CPU power to run the interpreter. The best version you can buy as of the time of this writing is the Raspberry Pi 3 Model B+. This technically has more feature than you need (built-in Bluetooth, HDMI port, camera port, 40-pin GPIO headers, etc). These features, while very cool and useful for other projects, will not help you with this home automation setup since you will be running the Raspberry Pi as a server and remoting into it from your PC.
- Samsung Evo Plus 32GB MicroSD card – Stores the OS and configuration files for your Raspberry Pi. Your Raspberry Pi package is very likely to contain a MicroSD card already (so you can easily get started). However, I recommend you buy a higher-quality SD card. Flash memory is “volatile”, no pun intended, and these cards are being written to constantly. Eventually, I will migrate to a different storage medium, but for now, a better MicroSD card will do.
- MicroSD card reader – Copies the Hass.io image from your Windows PC (where you will download it to initially) to your MicroSD card. Note that the reader I have linked to is a USB 3 model. This makes it more futureproof, but it will require more hardware to work on most Windows PCs.
- USB Type C female to USB 3 male adapter – Converts from USB 3 on the MicroSD card reader to my traditional Windows PC with its USB Type C ports. This would not be needed if you select a MicroSD card reader that can already be plugged into your computer (either because you have a USB 3 port or because you pick a different reader). It was needed in my case (and surprisingly hard to Google for).
- Short Ethernet patch cable – Connects your Raspberry Pi to your home network. I recommend you plug it in directly to the router instead of taking advantage of the WiFi network. This will make your network connection to the Raspberry Pi faster and more reliable (in addition, if you are running Pi-hole, you want a fast network connection to the DNS server running on the Raspberry Pi).
- balenaEtcher – Will “flash” the image of Hass.io you will copy down from the Internet from your Windows PC to your MicroSD card.
- VNC Viewer – Log into the Raspberry Pi’s GUI from your Windows PC.
- Putty – Log into the Raspberry Pi in a “headless” (no GUI mode). This is much faster than using the Raspberry Pi’s GUI, but you may be more comfortable using the Terminal window on the Raspberry Pi.
Flashing & plugging in your Raspberry Pi
Now that you have purchased the hardware & downloaded all of the needed software, you can get started.
- Remove your Raspberry Pi from the box. If you purchased the Canakit version, it will also come with a great case to protect the delicate electrical components.
- Remove the MicroSD card (or open the new MicroSD card you bought) and plug it into the MicroSD card reader that is plugged into your Windows PC. If prompted, select Open Files for what to do with media like this.
- Download the Hass.io image from the Home Assistant website. Make sure you select the version for the version of Raspberry Pi you purchased (most likely, Raspberry Pi 3 Model B and B+ 32bit).
- Open balenaEtcher to flash the MicroSD card with the image you have downloaded from the Hass.io website.
- Click on “Select image” and navigate to where you downloaded the Hass.io image (most likely, the C:\Users\<your ID>\Downloads directory) and select the image (most likely, hassos_rpi3-2.10.img.gz). Click Open.
- Most likely, Etcher will automatically figure out that it should select your USB 3.0 device to write to. If not, select “Change” and select your MicroSD writer.
- Click “Flash!” to copy the image from your Windows PC to the MicroSD card. Note that this will overwrite anything already on the MicroSD card. If you recycled an existing MicroSD card you already had, you will lose anything that was on it. The image you downloaded is a complete OS and filesystem.
- On the Windows taskbar, on the right-hand side of the screen, click on the Up arrow on the System Tray (where the clock is). You want to left-click on the USB device and select “Safely remove hardware and eject media” to ensure Windows finishes writing anything to the memory and cleanly removes it. Click “Eject”. I have had a few memory cards fail over the years due to Windows not being done with them before I yanked the card out, so I always eject.
- Carefully install the MicroSD card back into your Raspberry Pi. You do not have to push hard to do this.
- Install the Raspberry Pi carefully in its case. You must be careful with the exposed MicroSD to not damage it (slip the MicroSD card into the slot provided in the case. Now you can install the rest of the case.
- Finally, plug your Raspberry Pi into power and your router via the Ethernet patch cable.
The next post will explain how to connect & configure Hass.io on your Raspberry Pi.