Home Assistant, the One to Rule Them All. an Advanced Guide

by farmer1998h in Circuits > Remote Control

6694 Views, 18 Favorites, 0 Comments

Home Assistant, the One to Rule Them All. an Advanced Guide

hassio2.png
hassio.png

This instuctable was written as part of an assignment for the HAN University of Applied Sciences.

Nowadays more and more devices in our homes become smart. Lights, switches, vacuums, basically everything electric. Only alle these devices are either made by different companies, all using different apps and servers. Or the devices are too expensive for the average user, while they could be easily made by yourself.

If only we could combine all these devices from different manufacturers, and also add our own DIY devices… oh wait we can:

Introducing Home Assistant.

Home assistant is an open source, self-hosted software package that runs on many different platforms, giving you control over all supported smart home devices at one place, giving you the option to combine multiple different IOT devices, automate then, and also giving you a pretty interface where you can see and control it all.

Want to combine a Tuya power socket switch connected to a space heater with a Sonoff Zigbee temperature/humidity sensor for an easy room thermostat setup? Done.

Want to make sure the lights are on in the house when you get home (without also telling google/amazon)? Done.

Want a text to speech message at 1 pm telling you your favourite cactus needs more water? Done.

Combining your expensive security camera’s with a cheap wireless camera or a usb webcam into 1 interface. Done.

The options with home assistant are unlimited, and most products don’t even require any scary coding. They do however require some configuration.

Installing Home Assistant

Installing home assistant (Hassio) tends to change a bit through the years. This guide will therefore not explain the full process, it will only point you in the right directions.

Before going any further it’s wise to read through the official installation guide from Hassio so you can get a better idea of the possible platforms from which to choose:

https://www.home-assistant.io/installation/

Installing Hassio can be pretty simple, or pretty hard, depending on which platform you choose. For most people the choice lies between using either a raspberry pi (3b+ or 4) or an old laptop . There are also options to install Hassio on an capable nas or regular daily driver pc, but I won’t cover those there. Luckily the guys as Home Assistant got you covered and all information can be found on their respective installation pages.

Keep in mind that home assistant has an excellent backup and transfer system built in. This means that in case your chosen platform wasn’t as great as you thought, transferring it to another system only takes a few minutes, installation not considered.

Choice 1: Raspberry pi flavour (Beginners, non-Linux users)

For beginners and people not familiar with Linux the best way to start with Home assistant is going with a raspberry pi.

Requirements:

· Raspberry pi 3 or 4 (4 is better)

· Quality (!) SD card, 32Gb or more

· Good Power supply with a proper cable

· Ethernet cable (Wi-Fi is possible, but not discussed or advised)

· Installation tools (PC with SD card reader and some patience)

The folks at Hassio have already made an excellent guide, so explaining it here would be pointless. https://www.home-assistant.io/installation/raspbe...

Simply follow the instructions under “Install home assistant operating system” and you’re good to go.

Some things to keep in mind:

While the Pi is an excellent starting point, it isn’t exactly a solid solution for all users over a long time (2+ years). In my experience once your installation starts to grow as you add more and more devices and services, the pi simply can’t keep up anymore. Added to the fact that SD cards only have so many read/write cycles which can run out fast with a setup running 24/7, replacing the pi with a more robust solution is a must once you’ll get the hang of it.

For the users that only connected a few lights and sensors and aren’t planning on going large there is also the option to switch out the SD card for a USB hard drive or SSD as explained over at Tomshardware: https://www.tomshardware.com/how-to/boot-raspberr...

Choice 2: PC master race (advanced)

A better but more advanced solution is using an old desktop or laptop as your main system. It can also give a new purpose to your old PC collecting dust in the corner.

Installing Hassio on a PC however requires some skills and some knowledge of Linux and its terminal. While installing on windows or MacOS is also possible, it either uses an inefficient virtual machine running Linux, or the windows subsystem for Linux.

There are multiple ways to install Hassio on a PC, I however advise to use the supervised version. While the installation might be a bit harder, it makes usage later a lot easier as you don’t need to mess with linux settings or docker containers and get the same exact experience of a raspberry pi installation with the added benefit of more computing power and storage.

Requirements:

The requirements for this type of installation are a bit more vague, and also depend on the usage. I suggest a machine with at least:

· Dual-core CPU

· 4 Gb of DDR3 RAM

· 32Gb of HDD/SSD storage.

· Debian (preinstalled)

I myself use my old acer aspire 7560 laptop with an SSD. Using a laptop decreases the footprint and noise of the machine quite a lot. Keep in mind however that closing the lid of a laptop in most cases puts the system in sleep mode, so either disable it in the linux settings or keep it open.

An added benefit of installing on a PC is that changing the system is as easy as swapping the drive.

Once again the installation guide is provided by the Hassio crew at:

https://github.com/home-assistant/supervised-installer

Some things to keep in mind:

In my experience the supervised installation is all you’ll need for Hassio, without the hassle of using the linux system itself later on. It does however require some occasional maintenance and updating.

An added benefit of going the PC way it that you can use it for other things too. As the supervised installation uses docker at its base, you can also install other docker containers (as long as the system can keep up with the combined load). I myself have also installed a Plex server on the system for all my stored movies and series. And before you wonder, yes you can add plex too as a sensor in Hassio.

Setting Up the System

Afbeelding1.png

If the installation went successful you’ll now see a pretty interface at either homeassistant.local:8123 or http://(ip_address_of_device):8123. Follow the instructions on screen and create a login account, give your installation a name and select your location on the map. Skip adding devices for now, as we can do that later. If everything went well you’ll now see the main page.

Before going further, click on the user in the bottom left corner. This will bring you to the user settings. Here select your preferred light/dark mode and interface colours, and enable the advanced mode setting. Clicking on overview will bring you back to the main screen.

Installing a configuration editor

Sometimes to get stuff working in Home Assistant we need to edit the configuration.yaml file. This can be found somewhere on the server, but its easier to add a file editor straight to the dashboard.

Click on the configuration menu(gear icon). This will bring you to the menu. Select Add-ons, Backups & supervisor. Now click the bottom right “add-on store” button. This will give you a list of available add-ons. I definitely advise you to take a look at all the add-ons later on, as explaining them all here will take days.

To edit the configuration.yaml there are 2 choices of software, the more simple “file editor” addon and the “studio code server” addon. Both are perfectly capable of editing files, only the studio code server uses visual studio code as its base giving it a clearer interface, but comes at the cost of performance as its quite heavy to run (especially on the pi 4, and it not supported by the pi 3).

For now the file editor addon will do just fine, so install it by clicking on it and pressing install.

After installation make sure both start on boot and show in sidebar are turned on.

To edit the configuration.yaml simply press on the wrench addon on the left bar, click the map in the top left and select the configuration.yaml

Setting Up Your First Device

Afbeelding2.png
Afbeelding3.png
Afbeelding4.png
Afbeelding5.png

Most of the non-DIY devices you’ll add will be done through the integrations tab (found under configuration -> devices and services or {ip}:8123/config/integrations). Some devices might already been found by the system, others need to be added through the add integration button. Here you can find a list of devices that can be added out of the box through the interface. Simply click through the settings and you’re done.

All these devices or services are based on internet communication. However some devices are too simple for Wi-Fi, or don’t have the battery capacity to run Wi-Fi for months on end using only a little battery. For these devices we can use other protocols, which we'll discuss later.

Adding a Card

Screenshot_1.png
Screenshot_1.png
Screenshot_2.png

To make controlling your devices from the interface easy, you can add cards to your dashboard. This can be done by pressing the 3 dots on the top left of your main menu -> Edit Dashboard. Now Press the "Add card" button in the bottom left corner. This will present you with all different card options (Note: every card can only work with certain entities). for now select the "Entities" card. Under "Entities (Required)" you can select the desired entities. Press save after you're done! The card will automatically turn it into a switch or a state if needed

Zigbee

Afbeelding7.png
Afbeelding8.png
Screenshot_1.png
Screenshot_2.png
Afbeelding11.png

Nowadays more and more devices use the ZigBee protocol. It works somewhat like Wi-Fi, with multiple devices talking to a central receiver, only the devices can also relay each other’s signals. This means devices can be way out of reach of the main receiver, as long as there are devices in between.

Zigbee is also built around power efficiency, battery powered devices can run for months of a single battery, transmitting only when needed.

Setting up the network

To use ZigBee with your home assistant network, you’ll need a receiver. This can be either an USB-stick connected to your server, or a standalone device connected to Wi-Fi.

On https://www.home-assistant.io/integrations/zha/ you’ll find a list of supported devices for the ZigBee integration. Choosing the right receiver is a bit of a personal choice. The USB-sticks can be easily set up and require no modifications, but are expensive and their location is dependant on the Hassio servers location. The standalone devices often require more setting up (some need to be opened up and reflashed), but are cheaper and can be placed wherever there is power and wifi.

I myself chose to reflash a Sonoff ZigBee bridge with Tasmota according to this guide: https://www.digiblur.com/2020/07/how-to-use-sonof...

Sonoff ZigBee bridge: aliexpress.com/item/1005002390399376.html (€18,77)

As my home assistant server is in the very corner of my house. However, for most people I recommend simple using one of the USB-devices listed.

To install the Zigbee system simply select the ZigBee integration in the integration menu, and select the correct USB device from the drop down menu.

Adding a ZigBee device

If you decided to use zigbee in your home assistant setup I highly advise you to buy some ZigBee Sonoff motion and temperature/humidity sensors, as they can be very useful later in automation, and are very cheap and small.

SNZB-02 Temperature and Humidity sensor (€9,27)

SNZB-03 Motion sensor (€10,36)

aliexpress.com/item/1005002390399376.html

To add a new ZigBee device click the configuration button in the integration menu, then click ‘Add device’ in the bottom left.

Put the device you like to add in pairing mode (this depends on the manufacturer), For the Sonoff devices this can be done by removing the battery isolation strip, reinserting the battery, and holding the reset button for 5 seconds till a red led starts flashing. After a few seconds a new device should appear on screen and the devices is added to your system. In the popup you can also assign a room and change the name of the devices.

RFLink

Afbeelding12.jpg
Afbeelding13.png
Afbeelding14.png
Afbeelding15.png
Afbeelding16.png
Screenshot_4.png
Screenshot_5.png
Screenshot_1.png

Another way to control your smart home devices is by using RFLink. You already might know devices that use this communication protocol, mostly as 433/868MHz transmitters/receivers like KlikAanKlikUit or those generic remote controlled power sockets.

These too can be controlled by Home Assistant (with the right equipment), and you’ll probably already have some in your house right now. And its not only the sockets that can be used, the remote too can be connected to Home Assistant to be used for all kind of useful things.

Getting it running

To send and receive RFLink commands you’ll need a transmitter. This will be achieved by uploading some code to an Arduino Mega, with an appropriate transmitter/receiver shield.

WARNING: this part requires uploading code and soldering

To build the transmitter, you can either choose to buy a kit provided by the developers:

https://www.nodo-shop.nl/nl/rflink-/159-rflink-ard...

or make your own.

Receiver: aliexpress.com/item/4000065229076.html

Transmitter: aliexpress.com/item/4000018571977.html

Arduino mega: aliexpress.com/item/1005001621715914.html

The transmitter here also comes with a receiver module, but in my experience its completely unusable.

Now connect both modules according to the schematic above. More information can be found at https://www.rflink.nl/wires.php

You can simply connect some wires to the modules and the arduino, or use some protoboard and turn it into a shield like I did.

To upload the code to the arduino mega, simply download the latest version on https://www.rflink.nl/download.php. Unzip the file and launch the RFLinkLoader.exe, select the correct Serial Port for your device and press Upload. After the process is done you can disconnect the transmitter and connect it to your Home assistant server’s USB-port.

Now, open the configuration.yaml as discussed earlier and add the following:

rflink:
  port: **usb-port**
  wait_for_ack: false

Replace **usb-port**by the correct usb port for your RFLink. This can be found by going to Configuration->Add-ons, Backups & supervisor -> System (top), then press the 3 dots under the “Host section and click hardware. Your device will be found under ttyUSB.

To reload the configuration.yaml and enable RFLink simply restart the device (Configuration->settings->restart, or do it manually from the machine itself). After this any device that sends a signal and is supported by RFLink will appear (under a somewhat random name) in the device list. To save the device to your system, find the name of the signal (configuration -> Devices & Services -> Entities(top)) and add it to your configuration.yaml like in the image.

Automating Your Home

Afbeelding19.png
Afbeelding20.png
Afbeelding21.png
Afbeelding22.png
Afbeelding23.png

While it’s fun to have all your devices at one place, in the end you’re only moving the switch to turn it on. The real fun of Home Automation comes with, well… automating it.

Introducing automations

Home assistant has a lovely automation system built in. it can be found under the configuration settings -> Automations & scenes.

To begin your first automation, you can press the add automation button in the bottom right cornet of the automation menu, after which a popup will show asking you to either use a blueprint or start with an empty automation. Select the empty automation.

This will bring you to a new menu with 4 sections, named:

· New Automation;

· Triggers;

· Conditions;

· Actions.

Setting up an automation might look complicated, but once you’ll get the hang of it its quite easy.

New automation.

Here you can give your automation a name and a description. Be sure to give it a proper recognizable name, cause once you’ll get the hang of it the list of automations can get Quite big. Here you can also select a mode. The mode dictates what happens to the automation if it gets triggered again while it’s still running.

· Single Ignore new triggers while running:

· Restart Restart the automation if triggered while running:

· Queued Wait till finished and then run again:

· Parallel Run both old and new instance of automation.

Most cases require only the single mode, so leave it at that.

Triggers

Here you select the trigger what triggers the automation. This can be a sensor value, time, the sun and a number of other things.

Conditions

This is a condition that needs to be passed before the automation will run. For example, the automation can be a timeframe, or the state of another sensor.

Actions

This is what the automation will do if triggered and the conditions are passed. This can be turning on or off a device, change a colour of a lamp, wait some time and more.

An example

My bedroom has some quite hard to reach light switches, so I needed another solution. I combined a Sonoff motion sensor as seen earlier to a light I made. I only need the light to turn on in the dark, so I limited to night-time only. After a few minutes on the light slowly fades off.

Climate Automation

Screenshot_3.png
Screenshot_4.png
Screenshot_5.png
Screenshot_14.png

Another way to automate your home is to combine sensors into a climate system. For example to combine a temperature sensor and a wall power switch connected to a space heater into 1 thermostat.

This can be done by adding the following to your configuration.yaml (replace the ** with your sensors):

climate:
  - platform: generic_thermostat
    name: *name*
    target_sensor: sensor.*temperature_sensor*
    heater: switch.*electric_plug*<br>

Save the config and restart the server.

Now you can add the thermostat by adding a thermostat card to your dashboard and control the room temperature from there. This system will now act as a normal house thermostat, keeping a room at the set temperature.

Going Further With ESPHome

Afbeelding24.png
Screenshot_14.png
Screenshot_1.png
Screenshot_2.png
Screenshot_3.png
Screenshot_4.png
Screenshot_5.png
Screenshot_6.png
Screenshot_7.png
Screenshot_8.png
Screenshot_9.png
Screenshot_10.png
Screenshot_11.png
Screenshot_12.png
Screenshot_13.png

While home assistant supports a lot of devices, it still can’t overcome the main problem with smart home: the price. A simple 5 meter led strip for in your room can easily cost between 50 upwards to 220 euro (looking at you Philips). As a person that likes to cover every room in their pretty, purple light. This is simply too much. So we need a better solution, and what better solution is there than going DIY.

Introducing ESPHome

ESPHome is a tool built around the Espressif series of microcontrollers, the ESP8266 and the ESP32. Both are wifi capable microcontrollers, with the ESP32 also having Bluetooth and BLE capabilities. The possibilities with ESPHome are endless, so i cant explain them all here. Luckely ESPHome has a nice list of example projects for you to follow: https://esphome.io/guides/diy.html

Installing ESPHome

To install ESPHome you simply need go to the add-on menu (Configuration -> Add-ons, Backups & Supervisor), go to the add on store and find the ESPHome add-on. Click install, turn on "Start on boot" and "Show in sidebar" and make sure the add-on is started. From now on the ESPHome interface can be found on the sidebar.

Getting your first sensor set up can be a bit complex, so it might be useful to take a look at their examples on: https://esphome.io/guides/getting_started_hassio.h... This should easily get you going with ESPHome.

How to use ESPHome

Before you can start using ESPHome you'll need a ESP8266 or ESP32 enabled device. These can be standalone prototyping boards like the NodeMCU, or a premade ESP enabled device like a ESP Relay module or the various LilyGO TTGO boards.

Before starting you need to set up your Wi-Fi network. Do this by clicking the "Secrets" button in the top left. Here enter the following:

wifi_ssid: "YourWiFi"
wifi_password: "YourPassword"

To start using ESPHome simply connect your chosen ESP to your computer and start a new project by pressing the "New device" button in the bottom left. This gives you a popup where you can give the device a name. After this press Next, and then connect. ESPHome will then attempt to upload the basic code to the ESP. A popup will show up where you can select the com port for the ESP. If installation went well you should now be able to add the required code to make your sensors work. You can ofter easily find the code by simply googling the sensor + ESPHome.Once the code is added press install, then either "wirelessly" or "Plugged into this computer". A bunch of text should now appear on screen. Wait untill a green text, followed by a purple text shows up. Should any red errors appear, check if the code is correct, or the device connected to power and retry. After some time some blue debug information should appear with the sensor data as seen in the image. Check if these are within limits so see if your sensors are connected correctly.

You should now also see a new notification at the bell icon. Click it and select "Check it out". You should now see the newly discovered device on your system. Press configure, then submit. Select the room the device will be in (or skip it), and press finish. The device should now be done and the sensors should show up.


An example

I bought some Tuya enabled Wi-Fi plugs. Nowadays these come with other chips which makes then unusable in this case, but back then they used simple ESP8266 chips inside. To Get them off of the Tuya cloud and into my local system i reflashed the Chip inside with ESPHome. To get it working i used the following bits of code:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO5
      mode: INPUT_PULLUP
      inverted: True
    name: "plug_3_switch"
    internal: true
    on_press:
      - switch.toggle: relay<br>

This creates an binary sensor input on pin 5 of the ESP, which is connected to a button. The button pulls the pin to ground when pressed, so we invert it and make the default state positive with a pullup. The name set here is the name under which the button can be found in Home Assistant. Internal: true makes the button invisible, so the status can't be read by Home Assistant. Remove this line if you want to read out the button anyways. on_press makes it that the button executes a commend when triggered. In this case the button should trigger the relay. If desired you can remove these 2 lines together with the internal line and use the button as a regular switch sensor for Home Assistant.

switch:<br> - platform: gpio
   pin: 4
   name: "Plug_3"
   id: relay

This creates an output on pin 4, which is connected to the relay. Here the name is the external name you'll see in Home Assistant, and id the internal name used for the binary sensor.

status_led:<br>  pin:
    number: GPIO13
    inverted: yes

This attaches the status led of the device to pin 13. The status led gives information about the connection of the device.

Adding these 3 bits of code to the .yaml file for your device should turn it into a simple controllable wifi switch.

The Finishing Touches

Home Assistant has endless possibilities for home automation, and is in my opinion the best of its kind. It has lots of support and a large userbase, and is finding its way into more and more homes all over the world.

Unfortunately even this guide only scratches the surface of Home Assistant, so i definently recommend taking a look at their website https://www.home-assistant.io/

Below are some of the other things i definently recommend to take a look at, that i unfortunately couldn't discuss over here.

Accessing Home assistant beyond your home network:

https://www.home-assistant.io/integrations/duckdns...

Integrating Google Assistant / Alexa into Home Assistant:

https://www.home-assistant.io/integrations/google_...

https://www.home-assistant.io/integrations/alexa/