I know there are already a few tutorials on setting up InfluxDB and Grafana with Home Assistant, but they did not meet my requirements. Specifically, I did not want to use third-party images, which may not be maintained, and not use panel iframes to display the plots. Moreover, many of the tutorials still show the InfluxDB admin GUI, which is no longer available. So, here’s my version of how to get everything set up with the official images.
Run the following command to start the InfluxDB container (change /volume1/docker/influxdb/ to the desired path):
Add InfluxDB to Home Assistant and restart Home Assistant. I am using the default settings, but feel free to change them. I am adding only two entities to start off.
Now that Home Assistant is communicating with InfluxDB (check for errors, if any, in Home Assistant logs), we can configure Grafana. Navigate to http://IP_ADDRESS:3000 and you should see the Grafana login screen. Login with root:root.
If you have not made any mistakes, you should see Data source is working when you click Add.
Now you are ready to add your dashboard and create your first chart. Since there are several tutorials on the web for the same, I am not going to discuss adding charts in Grafana here.
After you have created your charts, we now want to include them in Home Assistant. You can use Panel iframes as discussed here. Alternately ( and this is the method that I prefer), we can export the plots as PNG images and use the local_file camera component to display them inside Home Assistant. Thanks @fgabriel for the inspiration.
You can follow the tutorial here to obtain the API key and the URLs for our plots. Basically, obtain the API key from the Grafana dashboard
Obtain the Direct link rendered image URL for the plots that you want to be included by selecting the graph in a dashboard and clicking on Share.
Once you have the API key and the URL, you can add the following command_line sensor (thanks @skalavala for the tip) to periodically download the PNG image from Grafana and save it under /home/homeassistant/.homeassistant/downloads/temperature.png. You can change the URL and its parameters to configure the plot. For example, you can use from=now-30d&to=now to obtain the plot for the last 30 days.
You can check the version of your InfluxDB container by running docker exec -it influxdb influx.
For Grafana, you can navigate to any page go to any page that is not a dashboard (Data Sources page for example) and look at the footer:
or you can use grafana-cli -v after entering the Grafana container using docker exec -it grafana /bin/bash.
To update images, a) stop the respective Docker containers using docker stop grafana or docker stop influxdb; b) pull the latest image using docker pull grafana/grafana or docker pull influxdb; and c) restart Docker containers.
You can use the same graphana-cli to install plugins. For example, to install Pie Chart plugin, just run the required command grafana-cli plugins install grafana-piechart-panel in the Grafana container and restart the container.
@amelchio just pointed out that we can also use generic camera component that does not require API keys. Just create a user in Grafana with viewer rights and add the following with the Direct link rendered image URL from step 11 above.
I had the same requirements (and the same observation about outdated tutorials on the web) a while back when I set up InfluxDB and Grafana. As it was my first real encounter with Docker, it took some trial and error to get it right. On top of that, I used docker-compose to put it all together.
As I’m not good at putting together guides/tutorials like this one, I’ll just share my docker-compose.yml file for anyone who might be interested:
It is my own preference to use network_mode: host rather than specifying ports in a domestic setup.
My host volume folders are relative to where my docker-compose.yml file is located.
Included is a 3rd container (Speedtest) which can obviously be left out if so desired. I use it instead of the Speedtest component within Home Assistant to avoid flooding my Raspberry Pi 3’s ethernet connection every time the test would run.
You’re welcome, and same here. Plus it’s an easy way for me to keep track of how I put together my containers. The alternative would be to paste the commands I used in a notepad or something, which seems cumbersome to me.