Get started with Home Assistant, InfluxDB and Grafana.

Laying the Foundation

Create several directories to persist configurations, logs & data

You’ll most likely use different directory names – keep in mind that you have to update the docker-compose.yaml too

/share/Container/home-assistant Home Assistant configuration /share/Container/influxdb InfluxDB Data & Config /share/Container/grafana/log Grafana Logs /share/Container/grafana/data Grafana Data

Basic configuration

InfluxDB Generate the default config for InfluxDB docker run --rm influxdb:1.2-alpine influxd config > influxdb.conf Now move the influxdb.conf to your config directory (in my case /share/Container/influxdb) Home Assistant If no configuration is found, Home Assistant will create a basic configuration itself after the container has started.

Orchestrate

Copy and paste the following content into a docker-compose.yaml file

docker-compose.yaml version: '2.1' services: hass: image: homeassistant/home-assistant:0.40 restart: always depends_on: - influxdb - grafana links: - influxdb ports: - "8123:8123" volumes: - /share/Container/home-assistant:/config:rw - /etc/localtime:/etc/localtime:ro influxdb: image: influxdb:1.2-alpine restart: always volumes: - /share/Container/influxdb:/var/lib/influxdb - /share/Container/influxdb/influxdb.conf:/etc/influxdb/influxdb.conf:ro - /etc/localtime:/etc/localtime:ro ports: - "8086:8086" environment: INFLUXDB_GRAPHITE_ENABLED: 'true' INFLUXDB_REPORTING_DISABLED: 'true' grafana: image: grafana/grafana:4.1.2 restart: always depends_on: - influxdb links: - influxdb volumes: - /share/Container/grafana/log:/var/log/grafana - /share/Container/grafana/data:/var/lib/grafana - /etc/localtime:/etc/localtime:ro ports: - "3000:3000" environment: # the login for the web-interface on port 3000 will be admin/secret GF_SECURITY_ADMIN_PASSWORD: 'secret' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 version : '2.1' services : hass : image : homeassistant/home-assistant :0.40 restart : always depends_on : - influxdb - grafana links : - influxdb ports : - "8123:8123" volumes : - /share/Container/ home-assistant :/config :rw - /etc/ localtime :/etc/localtime :ro influxdb : image : influxdb :1.2-alpine restart : always volumes : - /share/Container/ influxdb :/var/lib/influxdb - /share/Container/influxdb/influxdb . conf :/etc/influxdb/influxdb.conf :ro - /etc/ localtime :/etc/localtime :ro ports : - "8086:8086" environment : INFLUXDB_GRAPHITE_ENABLED : 'true' INFLUXDB_REPORTING_DISABLED : 'true' grafana : image : grafana/grafana :4.1.2 restart : always depends_on : - influxdb links : - influxdb volumes : - /share/Container/grafana/ log :/var/log/grafana - /share/Container/grafana/ data :/var/lib/grafana - /etc/ localtime :/etc/localtime :ro ports : - "3000:3000" environment : # the login for the web-interface on port 3000 will be admin/secret GF_SECURITY_ADMIN_PASSWORD : 'secret'

Execute docker-compose up in the same directory where you put your docker-compose.yaml. Docker will now download the needed images, create a network and the containers. On startup, Home Assistant will create some initial configuration files. This is necessary for the next step so be patient 🙂 Also, please don’t kill the process! Just let the terminal open and use another window for the next steps.

Configure Home Assistant for InfluxDB

Now we have to make sure that HA is sending the data to our Database.

First you have to update home assistants configuration.yaml. Add the following code

influxdb: host: influxdb database: home_assistant tags: source: hass 1 2 3 4 5 influxdb : host : influxdb database : home_assistant tags : source : hass

You can find a more complete list of available parameters in the Home Assistant InfluxDB documentation.

For the next steps i’ll refer to dockerhost which translates to the ip/hostname of your docker server. If it’s your local machine you can use “localhost”

Now create the InfluxDB Database for Home Assistant:

curl -i -XPOST http://dockerhost:8086/query --data-urlencode "q=CREATE DATABASE home_assistant"

Time to restart home assistant: Point your browser to http://dockerhost:8123/config

You should see the configuration interface of HA. Scroll down until you see the card “Server Management“. Click on “RESTART” and wait 15-20 seconds until the server has restarted.

Configure Grafana

Login to grafana by opening http://DOCKERHOST:3000 in your browser. Username is admin, password secret.

First step is to configure a datasource. Give it a Name, check Default and set InfluxDB as Type. As Url use http://influxdb:8086. Set home_assistant as Database. Leave the rest as it is and click Save & Test. You should then see a success message.

Add a dashboard and a graph

Add a new Dashboard. Then drag and drop a graph to the empty space.

Now you have to configure the graph. Click on the header Panel Title and then on Edit.



In the new panel under the graph you see several tabs. Click on General and edit the Title for the graph from Panel Title to Sun elevation. Now click on the Metrics tab to configure the data source.

A click on the entry with the blue A on the left opens the configuration for the first time series of the graph.

In the expanded view, click the plus (+) sign next to the blue WHERE. In the drop down select entity_id. Now click the new field select tag value and select sun.

On the left side of WHERE click on select measurement and select sun.sun.

Next to the blue SELECT field you see field(value). Click directly on value, not on field, and select elevation.

Last step is the GROUP BY statement. You see a fill(null) field, click on null and select none.

Congratulations 😎 – you should see the beginning of an elevation graph. You’ll most likely not have enough data for a 6 hour graph if you’re using a fresh install. Click on Last 6 hours in the top right corner of your browser tab and select Last 5 minutes.