This is how you automate everything at home

Do you want to automate everything in and around the house, but you don't know where to start? With software such as Domoticz, OpenHAB and Home Assistant you can start small and you are not immediately tied to a certain system. Home Assistant in particular is a jack of all trades and is rapidly growing in popularity. There is a good chance that you will immediately find some useful applications for it. We'll show you how to use it with some fun usage examples!

The world of Home Automation has countless standards that are often difficult to combine. You are most flexible with software such as Domoticz, OpenHAB and Home Assistant. Domoticz is suitable for beginners but does not look very modern. OpenHAB and Home Assistant rely more on scripts. With OpenHAB, this mainly feels like a handicap for beginners, while with Home Assistant you quickly see the advantages of this. It is also actively developed and has a larger user base. High time to get acquainted!

In this masterclass we will install it on a Raspberry Pi 3 model B, but an Intel nuc, small Linux server or a nas is also a good option. On many of these systems, including a Synology NAS (see box), you can conveniently use Docker for so-called container virtualization. On the Raspberry Pi you will usually choose the Hass.io environment. It also relies heavily on Docker in the background, but also offers many extras, such as simplified installation of updates and extensions. Incidentally, Hass.io is also available for some other systems, including Ordroid C2 and Intel-nuc. Keep in mind that you can't do much else with the system besides running Home Assistant.

Installation on the NAS with Docker

On various systems, including the more extensive NAS of Synology, you can conveniently use Docker for the installation of Home Assistant. Make sure you have Docker installed and open the application. Go to Register, search by keyword homeassistant and choose homeassistant/home-assistant from the list (usually the first one) followed by To download. Choose the latest version. Then go to Image and when the download is finished press Start. Now a wizard for the configuration of the container opens. Click on it Advanced settings. Put a check in Enable automatic restart. Then go to Volume / Add Folder and mount the docker/HomeAssistant folder to /config. This basically ensures that the folder with the configuration files on your nas - so outside the container - is saved so that you can access it. Tick ​​the tab Network the option Use the same network as Docker Host at. On the right tab Environment add the variable with the plus sign TZ increase with the value Europe/Amsterdam. Finally choose To apply, Next one and then in the overview screen again To apply so that the container is executed. You can then start Home Assistant at the address of the nas and port 8123 in the form //ipaddress:8123.

01 Installation on Pi

For the installation on our Raspberry Pi 3 model B we choose the ready-made image with Hass.io. The basis is formed by the operating system HassOS and a Docker environment. Within that Docker environment, the container for Home Assistant is automatically started, which you can also easily update via the web interface. That web interface also includes some other extras, such as a backup (snapshot) tool. In addition, you can quickly add various extensions, such as the Configurator with which you can easily adjust configuration files via the browser. Get the image file for Hass.io. We selected the 32bit image for the Raspberry Pi 3 model B and B+. Use balenaEtcher to flash the image file to a microSD memory card (preferably at least 32 GB).

02 Memory card preparation

Once you're done flashing the memory card, you're basically ready to boot the Pi with it. Optionally, you can make sure that settings for WiFi are correct and/or a fixed IP address is assigned by writing a configuration file. In this masterclass, however, we choose to simply connect the Pi with a network cable. That is immediately more stable than WiFi, where the IP address is assigned via DHCP. Note that after starting your Pi, there are some installation tasks that will run, which can take up to twenty minutes. Optionally, you can monitor that process by connecting a monitor. When it's done, you can access the web interface using a browser on your network at //hassio.local:8123. Here you will be asked to create an account, which you then log in with. Hassio.local not working? Then use the IP address of your Raspberry Pi, which you can look up with tools such as Advanced IP Scanner.

03 Add Configurator

We install Configurator to easily adjust the configuration, one of the extras of Hass.io. To do this, go to Hass.io in the menu. Click below Add-on Store on this official add-on and choose install. Enter in the configuration script under the heading Config enter a password after password and add allowed_networks the IP range of your network. Then click Save followed by Start. Then follow the link to Open Web UI to open the Configurator. Via the folder icon you can open the desired configuration file, for example configuration.yaml in which we make most changes to this masterclass. You can also easily add a new configuration file with the desired name. Do you want to include the Configurator in the Home Assistant menu? Then add the lines below (for example at the bottom) to that file.

panel_iframe:

configurator:

title: Configurator

icon: mdi:wrench

url: //10.0.0.70:3218

Make sure behind url the correct link is. click on Save to save the changes. Now in Home Assistant go to Settings / General and click below Server management on Restarting. You should now be able to open the Configurator directly via the menu.

04 Setup configuration files

Take a good look at the structure of the configuration files beforehand. The main configuration can be found in configuration.yaml. By default, the configuration is divided to keep the overview. You can see that from a line like automation: !include automations.yaml. That is a reference to the separate script with automation rules. You can also do this yourself for, for example, all sensors with sensor: !include sensor.yaml. There is even an option to automatically insert entire folders. All of this is especially useful when you're a bit further along and your scripts are getting longer and longer.

05 First adjustments

Fill in configuration.yaml for the component home assistant: behind latitude: and longitude: Enter your home location. You can easily find the values ​​at www.gps-coordinates.org. They are used, among other things, to determine sunrise and sunset. Make sure to time_zone: The correct time zone is displayed, such as Europe/Amsterdam. Don't forget to save your changes via Save. After adjustments, it is wise to validate the configuration via Settings / General. Especially with spaces you can go wrong. In that menu you can also reload the configuration or – if that is not sufficient – ​​restart the server. This is very important for the changes you make in the configuration files to take effect!

06 Automatically added

Thanks to the Discovery component, devices such as Chromecast, Apple TV, Kodi, Sonos and your television may have already been found automatically. You will see the automatically found devices under Settings / Integrations along with many manual integrations. We'll be using this to add Philips Hue bulbs shortly. Then, before we really start to 'automate', we will also add some other devices. Good to know is that Home Assistant supports a lot of hardware and software (see box 'Works with ... almost everything'). There is therefore a good chance that you already have a lot of devices at home that connect to it.

Works with… almost anything!

Home Assistant supports an enormous amount of hardware and software or – in short – components. For a complete overview, visit www.home-assistant.io/components. A detailed description is included for each component. That might be a bit too short for beginners, but if you're a little further along, it's almost always enough. Otherwise, there are countless auxiliaries and resources available on the Internet. Also keep an eye on the Home Assistant blog because interesting components are added regularly!

07 Philips Hue Bulbs

We start by integrating Philips Hue lamps that work via the ZigBee protocol. The Hue Bridge ensures that you can also control the lamps from your network, with the Hue app or of course Home Assistant. It can talk directly to the so-called api in the Hue Bridge. We use the older Hue Bridge 1.0, which is perfectly adequate. In Home Assistant, go to Settings / Integrations and click behind Philips Hue on Configure. When prompted, press the round button on the bridge and then press Submit. Each Hue lamp is then automatically added to Home Assistant as a so-called entity and you can operate it. A changed status is updated within seconds, for example if you switch on or off a lamp outside the Home Assistant.

08 Cheap Yeelight

Yeelight lamps work via WiFi and are an affordable alternative to Philips Hue. You can add them to Home Assistant quickly and easily. Let's take the Yeelight YLDP02YL (about 18 euros) as an example, which can display colors and has a good light output with 600 lumens. Before you can add the lamp in Home Assistant, make sure it works in the usual way via the Yeelight app and has the latest firmware. Also put the option LAN Management in the app to allow access with other applications such as Home Assistant. Find out the IP address via the same Yeelight app or the network overview of your router. In our example, that's 10.0.0.185. Then open configuration.yaml and add the lines below. If you have multiple lamps, add them each with its own IP address and descriptive name (without spaces) under devices.

light:

- platform: yeelight

device:

10.0.0.185:

name: Atmosphere lamp

Don't forget to make the changes active (below Settings / General). After this, the lamp will be available in Home Assistant under the chosen name. Also try one of the many effects such as Disco or Police.

09 Add 433MHz products

To work with products in the 433MHz band, such as KlikAanKlikUit (see box 'KaKu in Home Assistant'), we connect the Rfxcom RFXtrx433E to one of the USB ports of the Pi. This is a popular 433MHz transmitter/receiver that can handle numerous products and protocols. Think of switches, weather stations, doorbells, automatic curtains and garage doors. You will also find a wide range in Chinese webshops. To add this transmitter/receiver as a component to Home Assistant, you only need to add the following lines to the configuration.yaml script. With the device at /dev/ttyUSB0 it looks like this:

rfxtrx:

device: /dev/ttyUSB0

After this we still have to add the desired sensors and the like. We will do that in the next step. Connecting a transmitter/receiver for Z-wave, a solid alternative, is done in a similar way, but with the following rules:

sulfur:

usb_path: /dev/ttyUSB0

KaKu in Home Assistant

KlikAanKlikUit (KaKu) has many products for the smart home. Some work around 868 MHz or with Zigbee, but the best known is the switchgear at 433 MHz. With this you can switch sockets and sockets remotely. You will find such sets in every hardware store and electronics store. They use a simple protocol that is very similar to the ancient X10 protocol. There are also disadvantages. For example, communication is only possible in one direction. So you can send a signal to switch on a lamp, for example, but there is no confirmation that this has actually happened. In addition, the communication is not encrypted, so there is a chance that neighbors inadvertently switch devices on and off. If you connect a transmitter/receiver that knows the protocols, you can get started in Home Assistant with KlikAanKlikUit products, but also countless other (cheap) sets that use the 433MHz frequency range, such as window, door and temperature sensors.

10 Making sensors available

To start with, we want to add some temperature sensors that operate at 433MHz. Sensors are used very widely within Home Assistant and not only for the actual measurement of the temperature. For example, you can add weather forecasts (including Buienradar and OpenWeatherMap) as a sensor, but also the level of your printer cartridges (via SNMP or cups), meter readings from your smart meter, the current trading value for bitcoin, the current travel time from A to B according to Google Maps or the speed of your internet connection. Therefore you can choose to put these details in a separate configuration file (for example sensors.yaml) as described in step 4. By default, the weather forecasts from the Norwegian Yr.no are added as a sensor. To make the temperature sensors of the rfxtrx component available we add a few lines so that it looks like this:

sensor:

- platform: yr

- platform: rfxtrx

automatic_add: True

11 Add sensor

As soon as a temperature sensor gives a signal, usually once a minute, thanks to the option automatic_add added directly. You can see the value in the web interface in the section Overview. Make sure your configuration is active and refresh your browser screen (F5) if necessary. Write down the temperature sensor identification code, which will look like 0a52070e380e00365346369. Add the desired sensors in your configuration file under the heading devices with a recognizable name. For a sensor that measures temperature and humidity, this comes down to the following, for example:

- platform: rfxtrx

automatic_add: True

device:

0a52070e380e00365346369:

name: Outside

data_type:

- Humidity

- Temperature

12 Add Switches

Adding switches is basically the same, but now you use the component switch:. To do this, add the following lines to the configuration.

switch:

platform: rfxtrx

automatic_add: True

If you press the on button on the remote control, you will see the code immediately appear on the overview page and you can add it. This is done in the same way as with the temperature sensors under a cup devices:.

switch:

platform: rfxtrx

automatic_add: True

signal_repetitions: 2

device:

0b11000f012ef9ba01010f50:

name: Christmas lights

If we assume that the remote control is also simply linked to the smart plug in question, you can now also operate the connected device via Home Assistant. With the value at signal_rehearsals (optionally) make sure that the signal is sent multiple times, so that you have more certainty that it arrives. If you don't have a remote control, you can also manually generate a code with Home Assistant and connect it to the smart plug via the learning mode. This learning mode is usually active for a short time when you plug the smart plug into the socket.

13 Present via router

Whether someone is at home can play an important role in your automation rules. There are several options for such information. You can tackle it thoroughly with Bluetooth or GPS. But there is also a simple option: ping the IP address of your smartphone or tablet. An alternative, as described below, is to read the connection list of the router to see if your smartphone is registered. To do this, we first turn on the so-called Device Tracker for a Fritz!Box in configuration.yaml. Compiles and periodically updates the connection list. In this example, the router has the IP address 10.0.0.1 but that may differ in your situation.

device_tracker:

- platform: fritz

host: 10.0.0.1

track_new_devices: yes

interval_seconds: 10

consider_home: 180

The value at consider_home, in this example 180 for three minutes, is the extra time Home Assistant takes before it actually puts someone on leave.

14 Device Presence

After the previous adjustment, a script known_devices.yaml will automatically appear in your configuration folder. That is a list of all devices found on the network. New devices are added to this automatically. Change the script so that there track: no is next to devices you don't want to track. For devices that you do want to track, such as your smartphone, choose as below track: yes with back name a friendly name.

device name:

hide_if_away: false

icon:

mac: 20:39:56:7B:4A:93

name: gertjan

picture:

track: yes

The accuracy of this tracking method is not optimal. For example, a smartphone in sleep mode will occasionally disconnect the Wi-Fi connection, making it seem as if that person is absent. However, that is taken care of. The Fritz!Box only removes devices from the connection list if they have not been seen for ten minutes. You can also experiment with the value for consider_home. The 'coming home' of a smartphone is immediately noticed.

15 Automate with Home Assistant!

We have now added the necessary devices that can be controlled and managed from Home Assistant or with an app, but that doesn't make the house smart! For that we are going to add automation rules in automations.yaml.

A rule contains up to three parts: a trigger, any conditions and the desired action(s). With a trigger you set when the rule should be evaluated, for example after a certain time, when a button is pressed or as soon as someone comes home.You can use conditions to set restrictions, so that, for example, a lamp is only switched on when someone is at home and when it is dark. Finally, you define the action to be performed, for example turning on the lamp. A good help is the part Developer Tools / States. There you will see the known entities with their status and attributes. For example, an entity is a lamp with status on or off and attribute if brightness (for a dim lamp). An entity can also be the sun with status above_horizon and attributes like next_rising and next_setting. You can explore the actions via Developer Tools / Services. For example, for a switch this is switch.turn_off and for a lamp light.turn_off.

16 Switching with time

We enter with a simple time-controlled trigger that alternately turns a lamp on and off every second. below alias we give a short descriptive name. Of /1 you indicate that it repeats every second. You add the rules to automations.yaml.

- alias: 'Toggle lamp'

trigger:

platform: time_pattern

seconds: '/1'

action:

service: light.toggle

entity_id: light.atmosphere lamp

17 Switching with sunset

Below you see an example where the lamp is turned on one and a half hours before sunset and is turned off again at 23:00.

- alias: 'Lamp on before sunset'

trigger:

platform: sun

event: sunset

offset: '+01:30:00'

action:

service: light.turn_on

entity_id: light.atmosphere lamp

- alias: 'Lamp off at 23:00'

trigger:

platform: time

at: '23:00:00'

action:

service: light.turn_off

entity_id: light.atmosphere lamp

18 Switching with Presence Information

To make the above even more advanced, you could, for example, choose to turn off all lights when everyone has left home.

- alias: 'Everyone gone – lights out'

trigger:

platform: state

entity_id: group.all_devices

to: 'not_home'

action:

service: light.turn_off

entity_id: group.all_lights

You can build on this endlessly. Think of adding conditions so that lights only turn on when someone is home. Or the receipt of a notification for status changes. The iOS app is useful for that. With Android you can use Pushbullet. Also nice to discover are the many extras for Home Assistant. It's easy for Hass.io to do that. A good example is Node Red, which makes it easier to program actions via a web interface.

Recent Posts

$config[zx-auto] not found$config[zx-overlay] not found