Get started with Home Assistant, InfluxDB and Grafana.
Laying the Foundation
Create several directories to persist configurations, logs & data
|/share/Container/home-assistant||Home Assistant configuration|
|/share/Container/influxdb||InfluxDB Data & Config|
|InfluxDB||Generate the default config for InfluxDB
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.|
Copy and paste the following content into a docker-compose.yaml file
# the login for the web-interface on port 3000 will be admin/secret
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
You can find a more complete list of available parameters in the Home Assistant InfluxDB documentation.
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
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.
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.