Hi, I’m running an ESP32 with tasmota to bridge BLE based measurements to an MQTT broker.
The MQTT message format is like
{"Time":"2023-07-25T10:08:37",
"Flora6204f8":{"mac":"c47c8d6204f8","Temperature":18.0,"Illuminance":851,"Moisture":18,"Fertility":98,"RSSI":-86},
"Flora60ebed":{"mac":"c47c8d60ebed","Temperature":19.6,"Illuminance":1220,"Moisture":15,"Fertility":90,"RSSI":-82},"TempUnit":"C"}
Basically I’d like to have two measurement series in Influxdb, one for Flora6204f8, one for Flora60ebed.
How can I use the JSON key as measurement name? I try to extract the key in the the JSON_V2 parser with ‘@this’ but I can’t get it to work. Here is the template so far:
[[inputs.mqtt_consumer]]
servers = ["tcp://mosquitto:1883"]
topics = [
"tele/+/SENSOR",
]
data_format = "json_v2"
[[inputs.mqtt_consumer.json_v2]]
# measurement_name_path="@this"
[[inputs.mqtt_consumer.json_v2.object]]
optional=true
path = "Flora*"
disable_prepend_keys = true
included_keys = ["Temperature","Illuminance","Moisture","Fertility","RSSI"]
[[inputs.mqtt_consumer.json_v2.object.field]]
# Causes error loading config file /etc/telegraf/telegraf.conf: plugin inputs.mqtt_consumer: line 153: configuration specified the fields ["name"], but they weren't used
path="@this"
name="sensor"
[inputs.mqtt_consumer.json_v2.object.fields]
Temperature = "float"
Illuminance = "float"
Moisture = "float"
Fertility="int"
RSSI="int"
[[inputs.mqtt_consumer.json_v2.object]]
optional=true
path = "LYWSD03*"
disable_prepend_keys = true
included_keys = ["Temperature","Humidity","DewPoint","Battery","RSSI"]
[inputs.mqtt_consumer.json_v2.object.fields]
Temperature = "float"
Humidity = "float"
DewPoint = "float"
Battery="int"
RSSI="int"