Mqtt parsing help

Dear community,
novice here. I’m struggling with something that looked easy at first glance…

I’ve a MQTT device that sends this json payload, under /tele/floor1/SENSOR

{Time":"2024-01-03T15:17:18",
"devType":"EBC",
"EBC":{"Temperature":19,"Humidity":50},
"PressureUnit":"hPa","TempUnit":"C"}

I can correctly parse this using this configuration


  data_format = "json_v2"
  [[inputs.mqtt_consumer.topic_parsing]]
    topic = "tele/+/SENSOR"
    tags = "_/device/_"
  [[inputs.mqtt_consumer.json_v2]]
    timestamp_path = "Time"
    timestamp_format = "2006-01-02T15:04:05"
    timestamp_timezone = "CET"
    measurement_name = "data_from_device"

    [[inputs.mqtt_consumer.json_v2.object]]
      path = "EBC"
      [[inputs.mqtt_consumer.json_v2.field]]
        path = "EBC.Temperature"
        type = "float"
      [[inputs.mqtt_consumer.json_v2.field]]
        path = "EBC.Humidity"
        type = "float"

Now… sometimes the device may have an additional sensor so the payload becomes this

{"Time":"2024-01-03T15:17:18",
"devType":"EBC2",
"BMP280":{"Temperature":20.4,"Pressure":1006.0},
"EBC":{"Temperature":20,"Humidity":60},
"PressureUnit":"hPa","TempUnit":"C"}

To handle the new values i’ve created one more config file which looks similar to the other

    [[inputs.mqtt_consumer.json_v2.object]]
      path = "BME280"
      [[inputs.mqtt_consumer.json_v2.field]]
        path = "BME280.Temperature"
        type = "float"
      [[inputs.mqtt_consumer.json_v2.field]]
        path = "BME280.Pressure"
        type = "float"

No luck. Data get all merged down and I only see one value for temperature humidity or pressure, meaning that I can’t distinguish the different sensors.
I think I should use tags but I dont know how.
Thanks in advance!

Yep! you need to add a tag to differentiate between the two sensors or rename each metric.

I’m not great with gjson, but what you need to do is set the tag for each metric to be the object key (e.g. device=“BMP280” and device=“EBC2”)