Importing multiple Tasmota Sensors per device data to Influxdbv1

Hello,

i’m using actual tasmota device with 3 sensors + mqtt → mosquitto mqtt server → telegraf + influxdbv1
Everything if working great except the one host who has 3 sensors of same type (DS18B20) and only the last one (id 000006C03A66) is written to influxdb. Here are my configs:

tasmota output:

22:03:27.223 MQT: tele/tasmota_5E2BC2/SENSOR = {"Time":"2024-03-20T22:03:27","DS18B20-1":{"Id":"000005DFDF04","Temperature":21.3},"DS18B20-2":{"Id":"000006473CA6","Temperature":43.6},"DS18B20-3":{"Id":"000006C03A66","Temperature":44.3},"TempUnit":"C"}

mqtt server:
/etc/mosquitto/mosquitto.conf

allow_anonymous true
listener 1883 0.0.0.0
log_type error
log_type warning
log_type notice
log_type information

telegraf:

[[inputs.mqtt_consumer]]
    servers = ["tcp://192.168.20.14:1883"]
    topics = [
        "cmnd/#",
        "tele/#",
    ]
    qos = 0
  data_format = "xpath_json"
  xpath_native_types = true

  [[inputs.mqtt_consumer.xpath]]
    metric_name = "'logging_data'"
    metric_selection = "child::*"
        #    field_selection = "*"
        #https://community.influxdata.com/t/reading-all-the-fields-from-xpath-in-one-go-without-defining-each-field/24195/4
        field_selection = "descendant::*[not(*)]"

Only the last of the three sensors how up in influx. What can i do to get the data of all three sensors ?

Thanks and best regards
Marcel

What is most likely happening is you need to set something as a tag to differentiate between the three sensors. Otherwise, if the timestamps and tags are the same then only the last metric will get written.

Hello jpowers,

thanks for your answer. Unfortunately this seems all i can configure at the client:

You set tags in your telegraf config. You can either update your xpath config or use a converter processor to change the id to a tag.

Tanks for the answer. Do you have a example xpath config ? I am new to the whole mqtt/telegraf stuff. (Before this i used espurna which had direct influxdb client, but with tasmota it seems i have to go mqtt)

What did you try?

[[inputs.file]]
  files = ["test.json"]
  data_format = "xpath_json"
  xpath_native_types = true
  [[inputs.file.xpath]]
    metric_name = "'logging_data'"
    metric_selection = "child::*"
    field_selection = "Temperature"
  [inputs.file.xpath.tags]
      id   = "Id"

get me:

logging_data,id=000005DFDF04 Temperature=21.3 1711034442000000000
logging_data,id=000006473CA6 Temperature=43.6 1711034442000000000
logging_data,id=000006C03A66 Temperature=44.3 1711034442000000000

Not sure exactly what you are after, but that would move the id from a field to a tag.

Hello,

when i add this modification, telegraf won’t start:

Mar 21 19:31:27 ctinfluxdb telegraf[3270]: 2024-03-21T19:31:27Z E! error loading config file /etc/telegraf/telegraf.conf: plugin inputs.file: line 11209: configuration specified the fields ["xpath"], but they were not used. This is either a typo or this config option does not exist in this version.
Mar 21 19:31:27 ctinfluxdb systemd[1]: telegraf.service: Main process exited, code=exited, status=1/FAILURE
Mar 21 19:31:27 ctinfluxdb systemd[1]: telegraf.service: Failed with result 'exit-code'.
Mar 21 19:31:27 ctinfluxdb systemd[1]: Failed to start Telegraf.

I thing its because i’m using the section [[inputs.mqtt_consumer]] and not [[inputs.file]] like you stated ?

Correct, you’ll need to update those headers.

I was unclear or maybe i misunderstand you: when i write your suggestion in the [[inputs.mqtt_consumer]] section, telegraf wont restart.

Do you mean i need an additional [[inputs.file]] section ?

this is what my full telegraf.conf looks like now (and works like i want, except the missing two sensors):

[global_tags]
[agent]
        interval = "10s"
        round_interval = true
        metric_batch_size = 1000
        metric_buffer_limit = 10000
        collection_jitter = "0s"
        flush_interval = "10s"
        flush_jitter = "0s"
        precision = "0s"
        hostname = ""
        omit_hostname = false
[[outputs.influxdb]]
        urls = ["http://127.0.0.1:8086"]
        database = "telegraf"
        username = "sensor"
        password = "******"
[[inputs.mqtt_consumer]]
        servers = ["tcp://192.168.20.14:1883"]
        topics = [
                "cmnd/#",
                "tele/#",
        ]
        qos = 0
        data_format = "xpath_json"
        xpath_native_types = true
[[inputs.mqtt_consumer.xpath]]
        metric_name = "'logging_data'"
        metric_selection = "child::*"
        field_selection = "*"
        data_format = "value"
        data_type = "string"

Or maybe there is another, better way to do it ? I just want to get every mqtt message to influxdbv1.

no, I don’t have a full mqtt setup like you do. I was using your input using the file input, so my parser has to reference the file plugin.

Your current config still does not set any tags! You MUST set a tag to differentiate between the various sensors. Otherwise the last metric wins.