In this article I wrote that this substituted a Python script with additional processing tasks. One of the tasks was the transmission of the data into MQTT to provide other systems with this kind of information (it was a small e-paper display used as a remote display in my home, I have now solved this differently).
However it’s quite easy to enable Telegraf to distribute the data via MQTT. You have to put the following statements in a file (for example mqtt_output.conf) in /etc/telegraf/telegraf.d:
[[outputs.mqtt]]
servers = ["localhost:1883"]
topic_prefix = "telegraf/cmi"
batch = true
data_format = "json"
[outputs.mqtt.tagpass]
sourcedevice = ["cmi"]
It’s an additional output like the InfluxDB output I’m using to store the data. However in this case it’s limited to measurements with the tag sourcedevice equal to cmi. As you may remember, I configured the input from the CMI in a way that sets sourcedevice=cmi and so I’m using this tag now to limit the MQTT transmission to CMI data only.
Let’s check this on the MQTT server.
$ mosquitto_sub -v -t telegraf/#
telegraf/cmi/server/http {"metrics":[{"fields":{"Heizkreispumpe":1,"Heizungsaussentemperatur":33.6,"Kesselanforderung":1,"Vorlauftemperatur":54.7,"Warmwasserladepumpe":0,"Warmwasserspeicher":53,"pufferspeicheroben":75.9,"pufferspeicherunten":75.9},"name":"http","tags":{"cminode":"node 31","host":"server","sourcedevice":"cmi","url":"http://<ip>/INCLUDE/api.cgi?jsonnode=31\u0026jsonparam=I,O,Na"},"timestamp":1613745181}]}
telegraf/cmi/server/http {"metrics":[{"fields":{"Heizkreispumpe":1,"Heizungsaussentemperatur":33.6,"Kesselanforderung":1,"Vorlauftemperatur":54.7,"Warmwasserladepumpe":0,"Warmwasserspeicher":53.1,"pufferspeicheroben":75.9,"pufferspeicherunten":75.9},"name":"http","tags":{"cminode":"node 31","host":"server","sourcedevice":"cmi","url":"http://<ip>/INCLUDE/api.cgi?jsonnode=31\u0026jsonparam=I,O,Na"},"timestamp":1613745241}]}