MQTT Consumer Topic Parsing with Value data format?

I have a set of MQTT topics as follows:


The data from these topics are all floats. They’re not contained within a JSON container, they’re just raw in the topic. The topics are updated at varying rates.

I have an MQTT consumer input connected to the broker with access to these topics.

  servers = ["tcp://"]
  topics = [

  qos = 1
  persistent_session = true
  client_id = "telegraf"
  username = "USERNAME"
  password = "PASSWORD"
  data_format = "value"
  data_type = "float"

	topic = "powermonitor/+/sensor/+/state"
	measurement = "measurement/_/_/_/_"
	tags = "_/serial/_/_/_"
	fields = "_/_/_/field/_"
     field = "string"

I’m struggling to work out what I’m doing wrong, as despite fiddling around with all manner of different parameters, Telegraf doesn’t appear to pick up on any of the messages to the topics.

I’m sure I’ve missed something and it’ll be an easy fix, but I’m aiming for metrics as follows:

powermonitor,serial=SERIALID power=390.0 1657282270000000000
powermonitor,serial=SERIALID current=2.0 1657282270000000000
powermonitor,serial=SERIALID frequency=49.9 1657282270000000000
powermonitor,serial=SERIALID power_factor=0.8 1657282270000000000
powermonitor,serial=SERIALID voltage=233.3 1657282270000000000

I’ve been testing with an file output to stdout, and this MQTT_Consumer appears to do nothing at all. " are shown to load in the Telegraf logs, but only the other one produces metrics.

@Jay_Clifford if you (or anyone else) has any ideas it’d be greatly appreciated!


PS, the data format is loosely based on the format from ESPHome, for if anyone is searching this in the future.

Slight update, I have the inputs detected. I have no idea what I did, but some of my fiddling worked. I removed the topic_parsing type being string because that caused errors. I think the topic selector was probably the issue, and the code in the original post works okay if all of the data types being used in the outputs are the same as the output is expecting (in my case an integer was expected where a float was sent, so that needed fixing).

My line protocol was then:

powermonitor,field=current,serial=SERIALID value=0.43 1666654823065465354
powermonitor,field=power,serial=SERIALID value=101.82 1666654823087467357
powermonitor,field=voltage,serial=SERIALID value=243.5 1666654832726737206
powermonitor,field=frequency,serial=SERIALID value=49.9 1666654832726870623

Which was functional if a little messy.

Then used the pivot processor to pivot it into the format described in the original post.

  tag_key = "field"
  value_key = "value"

Glad to hear you figured it out!

Could you maybe post the entire solution? I also try to figure out the parsing, but the documentation is minimal!
Would really appreciate it!

The entire solution is exactly as I posted in the initial post, minus the final 2 lines. There were no changes or additions besides this. I ended up copy and pasting the formatted version from this post back into the Telegraf file, and I guess removing my previous attempts/comments and starting fresh fixed it.

You’re right the documentation is minimal, but there is enough there to work with. I think I just screwed up by editing in nano/vi rather than in a proper editor that could spot my syntax issues.

I’d suggest making a new topic with more detail about exactly what you’re aiming to do if you’re still having issues!