InfluxDB 2.X is an open-source application that creates time-series databases named “buckets”. We want InfluxDB to act as a data source to Grafana, an analytics and interactive visualization application that creates charts and graphs of the data received. Node-Red is used to feed the “buckets”. As part of the IoT Automation Project, we will make use of Grafana to display visually appealing charts and graphs on Home Assistant.
Device/Sensors information → MQTT → MQTT broker → Home Assistant → Node-Red → InfluxDB → Grafana

InfluxDB creates time-series databases, meaning that the data collected from Node-Red are plotted on time. In other words, every point of data received are attached with a timestamp. As time moves forward, InfluxDB will continuously receive data from Node-Red, and Grafana’s graphs will be dynamically modified/created. Other database management software, such as SQLite, do not create time-series databases, which is unsuitable for our needs.
Grafana and InfluxDB were set up as docker containers in a docker compose file inside Portainer.


Some notes, embedded is disabled for Grafana by default, so we have to enable it to include it in Home Assistant. In addition, we have to give permission for Gradana to read and write for graphs. To do this, we assign Grafana user 1000, which is the same as thor.
Node-Red is a flow-based tool commonly used in IoT for setting up automations and connecting devices together. It is used here to relay information from our sensors to buckets inside InfluxDB. From there, this data can be used by Grafana for dashboarding. For our first example, we wanted to send the temperature from our lab temperature sensor to an InfluxDB bucket. We began by using the following three nodes: inject, current state and InfluxDB out.

The inject node triggers the rest of the flow. It defaults to only triggering when clicked, but since we want new data at regular time intervals, we set it to repeat every 30 minutes.
To configure the current state node, we entered the entity ID of the sensor that we want. We changed the variable output to global so that it can be accessed by other flows. At first, we selected the output to be entity, but after some debugging, we changed it to entity state and it functioned as intended. Looking back, we could have kept it, since it displays much more information than just the entity state, but it would have complicated our code.
The last node to configure is the InfluxDB out, which stores the data in an InfluxDB bucket. To set it up, we created a server in which we entered the IP address of InfluxDB followed by its access token. We then filled in the information as follows:

When we ran this node, the data was not being transmitted to our InfluxDB bucket.
After researching, we found that it was because InfluxDB accepts data in the following format: