MQTT data to Grafana

I’ve got a RPi running Home Assistant and have an MQTT broker add-on installed so I can use the data being published by the Cerbo GX for home automation/information. This works great!

I thought to try out Grafana to get fancier graphs and dashboards and noticed that I would need more plugins to read the MQTT data. My assumptions so far:

  1. I need telegraf to read the MQTT data (I’ve installed the plugin on HA)
  2. To store it in a influxDB (Also installed now)
  3. I can use Grafana (also installed in HA) to read the data from
    influxdb and make the graphs I need.

First of all, is this correct? Or is there a way to read the MQTT data directly from Grafana?

Although I’ve got telegraf/influxdb and Grafana installed on HA as add-ons, I’m not knowledgeable enough to figure how to get telegraf to read MQTT and publish it to Influxdb.

Can anyone give some useful pointers? Or correct me where my thinking goes wrong?

I’d like to keep all things running on 1 Rpi preferably through Home Assistant without modding my Cerbo GX.

I am using this configuration for Telegraf to read from my central MQTT broker, which is bridged to the FlashMQ in VenusOS: Pump MQTT data from a Victron Energy Cerbo GX with Telegraf into InfluxDB v2 · GitHub
Tried to maintain data layout as it is generated by GitHub - victronenergy/venus-grafana: Default Grafana dashboards, for docker solution and Venus OS Large .

Thanks, I’ll look into these!

Can such a Telegraf configuration work with the latest 3.73 FW? It seems latest FW requires the built-in MQTT broker in Cerbo to activate the keep-alive mechanism. However, I don’t know how to do this in Telegraf. :smiling_face_with_tear:

Currently I can get MQTT topics only in some random periods (something like 20-60-600mins), which is quite unusable. I want to store the metrics in InfluxDB2 every 60 seconds.

The keepalive mechanism is of VenusOS is described here: GitHub - victronenergy/dbus-flashmq: Plugin for FlashMQ that interfaces between DBUS and MQTT. · GitHub
It would be possible to use the inputs.exec plugin to create some message periodically. This can then be written to the keepalive MQTT topic of VenusOS.
I do this with Node-RED currently, but moving this to Telegraf could reduce the overall number of nodes in my Node-RED.

Can Node-RED in Cerbo write metrics directly into InfluxDB2? That would be a good alternative. Could you show me an example or provide a guide on how to do it? I’m quite new to Node-RED, but I have programming skills.

Node-RED can do that, but I wouldn’t do that with Node-RED. You need a very high amount of nodes to get data from MQTT to InfluxDB. And if you just start, you should use InfluxDB 3, not 2 anymore.

And what’s the reason? Is it high CPU usage, does it take too long, or is it just too much work? I’ve been using InfluxDB2 for quite some time now…

For me that would be way too much work. Btw here is my Telegraf configuration for pumping everything from MQTT to InfluxDB 2. I still need to migrate to InfluxDB 3, too.

Well, I noticed this config earlier, but I’m curious to know what firmware you’re currently using on the Cerbo. In this config, I don’t see how you’re handling the keep-alive mechanism, and besides, the topic in the latest FW version 3.73 isn’t “venus/N/+/#,” but just “N/+/#.”

As said, my keepalive is done with Node-RED. And the additional `venus/` in the topics is due to a broker to broker connection from my central MQTT broker to the FlashMQ in VenusOS, which reduces the load on the VenusOS device.

Okay, now it’s clear, and my telegraph is receiving the metrics regularly. The documentation does describe “keep-alive mechanism” but I didn’t understand from whose perspective this is meant—whether it tied to a specific client or it is shared across the server.

It all makes sense now. I mentioned “random periods” here, but after some observation, I realised that Telegraf only received topics when another MQTT client was subscribed and published keep-alive requests. Keep-alive requests are NOT tied to a specific MQTT session or client. The other client could even be a web browser that has opened the dashboard in the VRM portal (even in a remote network). As long as one of these clients periodically publishes keep-alive requests, Telegraf can receive topics. However, when another client disconnects, the 60-second timer in Cerbo is activated, and after this time, publishing of MQTT topics stops.

Therefore, some client must periodically publish a keep-alive request (in less than 60 seconds). Sending some kind of PINGREQ does not affect whether or not the Cerbo keeps publishing. I also experimented with MQTT Explorer and Mosquitto; these two are capable of publishing keep-alive requests, but this must be done periodically and manually. VRM is a special case because it does this automatically and periodically on behalf of the user.

The conclusion for other dummies like me is that, since Telegraf’s inputs.mqtt_consumer is subscriber-only, it is not capable of publishing a keep-alive request. However, you can use any other publisher to do this periodically and then Telegraf will act as a black passenger :slight_smile:

The easiest way is to use Node-RED to do this.

Note: MQTT topic is case sensitive. Must begin with uppercase ‘R’.