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):
docker run -d \ --name="influxdb" \ --restart always \ -p 8086:8086 \ -p 8083:8083 \ -v /volume1/docker/influxdb/:/var/lib/influxdb \ influxdb
Now that the InfluxDB web UI is deprecated, run the Influx client using:
docker exec -it influxdb influx
Create a new database for Home Assistant and exit the Influx client:
CREATE DATABASE home_assistant exit
Start Grafana container (change
/volume1/docker/grafanato the desired path):
docker run -d -p 3000:3000 \ --name="grafana" \ -v /volume1/docker/grafana:/var/lib/grafana \ grafana/grafana
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.
influxdb: host: 192.168.2.113 include: entities: - sensor.temperature_158d0001ab3b2b - sensor.humidity_158d0001ab3b2b
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
Next, configure InfluxDB as the data source in Grafana. If you have followed along, here’s how it should look like (assuming no password)
If you have not made any mistakes, you should see
Data source is workingwhen 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_filecamera 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
Direct link rendered imageURL for the plots that you want to be included by selecting the graph in a dashboard and clicking on
Next, get the the
Direct link rendered imageURL
Once you have the API key and the URL, you can add the following
command_linesensor (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=nowto obtain the plot for the last 30 days.
sensor: - platform: command_line name: "Download Grafana" command: curl -s -H "Authorization: Bearer API_KEY" "http://192.168.2.113:3000/render/dashboard-solo/db/home-assistant?orgId=1&panelId=1&width=1000&height=500&tz=UTC-05%3A00" > /home/homeassistant/.homeassistant/downloads/temperature.png
Next, you can add a
local_filecamera to Home Assistant to display the images.
camera: - platform: local_file name: Grafana_temperature file_path: /home/homeassistant/.homeassistant/downloads/temperature.png
It should now appear as a camera in HA.
- 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 -vafter entering the Grafana container using
docker exec -it grafana /bin/bash.
- To update images, a) stop the respective Docker containers using
docker stop grafanaor
docker stop influxdb; b) pull the latest image using
docker pull grafana/grafanaor
docker pull influxdb; and c) restart Docker containers.
- You can use the same
graphana-clito install plugins. For example, to install Pie Chart plugin, just run the required command
grafana-cli plugins install grafana-piechart-panelin the Grafana container and restart the container.
@amelchio just pointed out that we can also use
genericcamera 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 URLfrom step 11 above.
camera: - platform: generic name: Grafana_2 still_image_url: 'http://192.168.2.113:3000/render/dashboard-solo/db/home-assistant?orgId=1&panelId=1&width=1000&height=500&tz=UTC-05%3A00' username: !secret grafana_user password: !secret grafana_pass
Let me know if something is missing or not clear and I will be sure to modify the instructions.