Tag: raspberry pi

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

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

Hardware

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

Software

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

Deciding on a home automation system

The first step to building your own home automation system is deciding what the major components will be. There are so many choices and so many different vendors that it can be overwhelming to decide what to do first.

I believe the right philosophy is to standardize of a few key technologies and build out using those. I have included affiliate links to the various pieces of hardware I have purchased and am using in my own home.

Some of the major technologies you need to decide on are:

  • What hardware will I use?
  • What hub will I use to control “all the things”?
  • What wireless communication protocol will I use?

Summary (i.e. get this)

Hub

The most important decision is what hub you will use to control your home automation. This is the most important decision because it will drive every other decision. You will have to decide what your goals are, how flexible the hub software is, how many integrations the hub has with 3rd party components and what kind of support you expect from the vendor.

Some of the major hubs are:

There are some additional hubs out there, but a key issue with them is the lack of integrations or lack of long term sustainability. A key place this could bite you is if the vendor decides to shut down support for their hub. This will kill future integrations and may completely shut down your home automation (if the hub depends on services the vendor must provide, like a cloud-based server). An example of this is the Lowe’s Iris system.

In my case, I wanted an open source system that was not dependent on any one vendor. This is mostly because I am software developer, so I have no fear of having to dig into the guts of the software and make tweaks (just ask my wife how many times I have had to dive into the PHP of her WordPress site to fix some odd bug!). The open source model helps ensure that the platform has long-term staying power because it is maintained by deeply interested people who work on it out of their free time. This also increases the likelihood of integrations working no matter what vendor is involved. Naturally, Amazon, Google & Apple don’t really want integrations between their various ecosystems because it is in their interest to keep you locked into their platform.

Therefore, for the ability to tinker with and see the source code, to increase the likelihood of long-term sustainability and have maximum integrations, I choose Home Assistant.

Hardware

You will have to decide what hardware you want to use to host your hub. In many cases, this will be decided for you (Alexa runs on an Alexa device like Echo). For Home Assistant, you will have to decide what hardware to run your hub on. The most common configuration is to run it on a Raspberry Pi. You can easily buy any number of Raspberry Pi kits, I choose a kit made by Canakit, which makes many different kits for different use cases. I ended up buying a kit on Amazon, since I already had a Prime membership

Wireless communication

Finally, you will have to decide what wireless communications protocol you will want to use for your home automation equipment. Unless you are doing new construction, running lots of wires throughout your walls is probably not in the cards. Therefore, you will need wireless communication.

Many of the smart home devices you can buy tout their WiFi capabilities. This is supposed to be seen as a feature. I see this as a bug. WiFi was not meant to be used to handle the dozens of wireless communications of simple home automation equipment. Most people’s home routers cannot handle more than a few dozen clients (Linksys actually sets this at 50). You typically don’t want that many clients anyway, not without more substantial wireless hardware (Ubiquiti is my preferred home networking system and I will write a later blog post explaining why and how I have their equipment set up in my house).

Obviously, the industry has been dealing with this for a lot longer than the recent Smart Home craze, so there are 2 primary wireless protocols that are used, Z-Wave and Zigbee. Both of these are low power, wireless protocols that can be used to control smart home devices. Many vendors, in fact, sell different versions of their products that support one or the other. In general, I don’t see a compelling reason to choose one over the other; you can decide which one you prefer based upon the devices you would like to control. Z-Wave, in my mind, has better industry support and standardization, so that is the protocol I chose for my smart home devices. This is not to say that I won’t ever use Zigbee. I may eventually come up with a compelling use case or device, but I haven’t had to yet.

Therefore, you must have an antenna connected to your hub that can send and receive your given protocol. Many of the commercial hubs have this antenna already built in. In my case, since I went with the open-source Home Assistant system, I had to buy a separate Z-Wave USB stick to plug into my Raspberry Pi. I choose the Aeotec Z-Wave Gen 5 USB stick.