Home Assistant

Home Assistant is a solution/software that allows you to automate and coordinate your devices at home. It offers a variety of integrations that one to link different product/services together.

The main aim of this document is to provide a quick and easy setup on how to get up and running, and a reminder to myself to understand the reasoning about some of the setup choices I made.

There are 4 main ways to setup home assistant each with their own pros and cons. The documentation provides detailed explanations of each of the methods. There is also an excellent summary that discusses the pros and cons of each installation method.

I am going with the Docker Method as I had succesfully installed home assisation on a raspberrry pi using the OS method. While it worked find, I ended up destroying the SD card because my previous set up was using influxdb. The issue here is that this causes a lot of writes to the disk which can be excessive for an sd card.

Another reason for using docker/container method was that I was already quite familar with using docker, and I had an old linux laptop that was usually on most of the time. So it made sense to use this as my Home Assistant server.

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

docker-compose.yaml

This file defines the containers that I will be using.

From this SO question. We want to make sure that docker will run on startup. So if your “server”, laptop ever restarts home assistant will continue to run. This is done by the follwing command:

$ sudo systemctl enable docker

In your docker compaose file you can see that the key restart: always is defined. This is the line that ensure that particular container will always be restarted.

homeassistant container

This contains core homeassistant platform One thing of not is the line ~/projects/hassio:/config this loads my configurations files (explained later on) locally. Also network_mode:host is important to ensure that home assistant conatiner can discover other containers running.

homeassistant:
  container_name: home-assistant
  image: homeassistant/home-assistant:dev
  volumes:
    - ~/projects/hassio/:/config
    - /etc/localtime:/etc/localtime:ro
  environment:
    - TZ=Europe/Oslo
  restart: always
  network_mode: host

deconz

Deconz is a specific container used for the hardware that I am running currently running in my home. Essentially what I have is this USB stick that acts a zigbee protocol gatway. It allows the computer to interact zigbee devices. This acts a replacement for the ikea tadfri gateway and the xiaomi gateway. Using this allwos me to combine mulitiple devices from different companies using one gateway and avoid using any cloud services that may or may not send data to China …..

deconz:
  container_name: deconz
  image: marthoc/deconz
  volumes:
    - /etc/localtime:/etc/localtime:ro
    - ~/.local/share/dresden-elektronik/deCONZ:/root/.local/share/dresden-elektronik/deCONZ
  devices:
    - /dev/ttyACM0:/dev/ttyACM0
  environment:
    - TZ=Europe/Oslo
  restart: always
  network_mode: host

influxdb

This container creates a database that is made for time series data. Data that we will be collecting from all our IoT devices. While Home Assistant automatically stores this data in SQlite database by default after a certain amount of time this will be thrown away.

An excellent and more indepth article discussing the benefits of using influxdb can be found here: https://blog.wesselhissink.nl/homeautomation/long-term-home-assistant-data-history-with-influxdb/

influxdb:
  container_name: influxdb
  restart: always
  ports:
    - 8086:8086
  volumes:
    - influxdb_data:/var/lib/influxdb
  image: influxdb

chronograf

This sets up a nice GUI so that we can interact with the influx db. The first thing we need to use the tool for is actually create a database called homeassistant. One this is done we can use the tool for is to to see if our home assistant data is coming through and even plot some graphs.

chronograf:
  image: chronograf
  ports:
    - '127.0.0.1:8888:8888'
  restart: always
  volumes:
    - chronograf_data:/var/lib/chronograf
  depends_on:
    - influxdb

grafana

This is a graphing/dashboard tool. It has some powerful features, and allows for a lot customization. However while I have it in this setup, I haven’t had a really need for it as the default dashboarding/UI tool that comes with home assistant (Lovelace) has met my needs so far.

grafana:
  image: grafana/grafana:latest
  ports:
    - 3000:3000
  volumes:
    - grafana_data:/var/lib/grafana
    - ./grafana-provisioning/:/etc/grafana/provisioning
  restart: always
  depends_on:
    - influxdb

NOTE The above conatiner setup has not done any security admin/passwords. So be aware that anyone can probably access some of these containers if they have access to your wifi.

Getting it all up and runing

Once you are satisfied with how you have defined the containers you can run the follwing to get it all up and running.

docker-compose up -d

Updating

Update the containers that you are running the following can be done

docker-compose pull
docker-compose up -d --build homeassistant --build deconz ....

configuration.yaml

This is stored in the at the project root level and outlines the configuration of the tool.

tibber:
  access_token: !secret tibber_token


group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml



influxdb:


climate:
- platform: generic_thermostat
  name: Office Heater
  heater: switch.office
  target_sensor: sensor.office
  min_temp: 16.0
  max_temp: 25.0
  ac_mode: False
  target_temp: 20.0
  cold_tolerance: 0.0
  hot_tolerance: 0.0
  initial_hvac_mode: "off"
  away_temp: 16

One of the main components I wish to use is coordinate my temporation sensores sensor.office with my heater switches switch.office so that I can automate when they turn on. The above links the sensore and switch component to an entity of type generic_thermostat and named Office Heater. I define this for all the heaters in the house so we can easily manage them with a schedule define later on.

secrets.yaml

This is file where you would store secrete information and not commit/share. As seen above you can reference these values without exposing the underlying value.

Custom components

While home assistant provides a lot interesting integrations, there are lot other componensts that have been developed. Some of these components relate to the themes from of the lovelace ui and other other useful components.

In order be able to access these components, we need to the tool HACS. This can be installed by going into the homeassistant container by the follwing:

docker exec -it homeassistant bash

and then run the install script and exit

wget -q -O - https://hacs.xyz/install | bash -
exit

Schedule Component

One of the main things I wish to use HomeAssistant was to coordinate my tempreature sensors with my heaters to schedule the heaters to run when I define.

This has been discussed in the forums, and I have mainly followed what has been discussed in the thread.

In order to do this we need to install the schedule-component by following the instructions in the repository.

  1. Use HACS to find this component
  2. Restart Home Assistant
  3. Add the new integration into Home Assistant scheduler
  4. Add the schedule-card (desrcibed below)

Schedule Card

Now we have the schedule component installed we need to install the UI component so that we can create the schedule easily.

The schedule-card is the graphical UI component. To install this you need to go to the frontend sections of HACS and search for the add on. Refresh the browser and you should be able to add a new card in lovelace UI.