Local MQTT into InfluxDB v2.6
in Local MQTT
Hi, I recently recieved a glow smart meter. I have it set up and feeding into Home Assistant successfully via a local MQTT broker.
However, I'd like to take the MQTT feed directly into InfluxDB via Telegraf. I know I can feed it from HA into InfluxDB but I'd like to cut out HA from the loop if possible.
I can subscribe to the feed from the CLI but I can't make sense of how to parse the feed in Telegraf for input to Influxdb.
Has anyone done this and able to help?
Comments
You just need to put an MQTT input plugin configuration section into your telegraf.conf file - see https://www.influxdata.com/integration/mqtt-telegraf-consumer/ . The topic will be the topic you are sending data to, and the data_format should be set to json. You dont need to do any extra parsing - the data gets loaded into influxdb with just this
Ahha, thanks @antxxxx. Trust me to over complicate things.
Just to clarify in my mind.
if I do something along the lines of....
[[inputs.mqtt_consumer]]
servers = [ "tcp://localhost:1883" ]
topics = [ "glow/XXXXXXX/SENSOR/#" ]
data_format = "json"
data_type = "?????"
to pick up all the sensor data for /electricitymeter and /gasmeter. Will I need to define the data_type (which I think are all float)?
You dont even need the data_type. This is all I have in my config and it works great
[[inputs.mqtt_consumer]]
servers = [ "tcp://localhost:1883" ]
topics = [ "glow/#" ]
topic_tag = "glow"
data_format = "json"
Brilliant, thanks for that I'll try it when I get in.
Worked a treat. Took me a while to figure how to feed it into a different bucket but once I figured that it works perfectly. Thanks @antxxxx.