Mqtt data to influxdb with telegraf

Sorry for not understanding the config fil. And the help files. But I need som more help to understand how to setup telegraf to get the rigth data from the MQTT server and push it to influxDB2

I think I have made a good setup for sending the values to the broker.

/Adress/RomName/Device/{Device info}

/Glommensgate1/stue/RT_TV/{“Device”:“B5 Stue ved dor”,“T_PV”:“20.39”,“T_SP”:“20.5”}
/Glommensgate1/stue/RT_Ovn/{“Device”:“B7 Stue ved kjokken”,“T_PV”:“0.0”,“T_SP”:“20.5”}
/Glommensgate1/stue/RT_Tak/{“Device”:“Stue Smoke 1”,“T_PV”:“21.9”,“T_SP”:“20.5”}

I tride to use
data_format = “influx”
The I get these errors.
2021-03-14T23:48:11Z E! [inputs.mqtt_consumer] Error in plugin: metric parse error: expected field at 1:19: “{“Device”:“B5 Stue ved dor”,“T_PV”:“20.39”,“T_SP”:“20.5”}”

Then I tride with
data_format = “json”
#json_name_key = “Device”
#json_name_key = “stue”

But I don’t understand how to use the key names

Can somebody give me an example with thise to values

/Glommensgate1/stue/RT_TV/{“Device”:“B5 Stue ved dor”,“T_PV”:“20.38”,“T_SP”:“20.5”}

/Glommensgate1/gang/RT_gulv/{“Device”:"",“T_PV”:“22.4”,“T_SP”:“22.5”}

My telegraf.conf file:
[agent]
interval = “10s”
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = “0s”
every 10-15s
flush_jitter = “0s”
precision = “”
debug = true
quiet = false
logfile = “”
hostname = “”
omit_hostname = false
[[outputs.influxdb_v2]]
token = “$INFLUX_TOKEN”
organization = “stormautomasjon”
bucket = “mqtt”
[[inputs.mqtt_consumer]]
servers = [“tcp://localhost:1883”]
topics = [
“Glommensgate1/stue/#”,
“Glommensgate1/bad/#”,
]
topic_tag = “topic”
username = “"
password = "
*”
… # data_format = “influx”
#data_format = “json”
#data_format = “value”
#data_type = “float”

#json_name_key = “Device”
#json_name_key = “stue”

I have played around with my MQTT broker and your data and have a Telegraf configuration for you that works and could serve as a starting point for you:

[[inputs.mqtt_consumer]]
  servers = ["tcp://mqtt.flespi.io:1883"]
  topics = [
    "Glommensgate1/stue/#",
    "Glommensgate1/bad/#",
  ]
  username = "mytoken"
  password = "*"
  client_id = "Telegraf"
  data_format = "json"
  tag_keys = ["Device"]
  json_string_fields = ["T_PV", "T_SP"]
  name_override = "mqtt"

# Convert string values to another metric value type float
[[processors.converter]]
  [processors.converter.fields]
    float = ["T_PV", "T_SP"]

[[outputs.file]]  # only for debugging
  files = ["mqtt.out"]
  influx_sort_fields = true

[[outputs.influxdb_v2]]
  urls = "removed"
  token = "removed"
  organization = "removed"
  bucket = "removed"

What I noticed with your json data is that:

  1. you have a lot of Device keys with empty strings, I would avoid that.
  2. the floats are all packed as strings, I would change that, then you don’t need the processors plugin anymore.

Thank you. I think I understand a bit more. I will try to change the string to float on the values. And give more device names.

Thank you

If sombody else wounders.
To make the value float I took away the " " from the values.

So now it’s like thise

{“Device”:“CO2 Walter romtemp”,“T_PV”:22.04,“T_SP”:21.5}