# Importing Tasmota Sensor data to Influxdb

**URL:** <https://community.influxdata.com/t/importing-tasmota-sensor-data-to-influxdb/30866>\
**Category:** Telegraf\
**Tags:** mqtt, json\
**Created:** [July 25, 2023, 9:20am UTC](https://community.influxdata.com/t/importing-tasmota-sensor-data-to-influxdb/30866 "2023-07-25T09:20:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom-E](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tom-E](https://community.influxdata.com/u/Tom-E)\
**Post date:** [July 25, 2023, 9:20am UTC](https://community.influxdata.com/t/importing-tasmota-sensor-data-to-influxdb/30866/1 "2023-07-25T09:20:45Z")

</div>

Hi, I’m running an ESP32 with tasmota to bridge BLE based measurements to an MQTT broker.

The MQTT message format is like

```auto
{"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:

```auto
[[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"

```

---

<div class="post-metadata">

**Author:** ![jpowers](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jpowers/32/8569_2.png) [@jpowers](https://community.influxdata.com/u/jpowers)\
**Post date:** [July 25, 2023, 1:10pm UTC](https://community.influxdata.com/t/importing-tasmota-sensor-data-to-influxdb/30866/2 "2023-07-25T13:10:07Z")

</div>

Maybe @srebhan has a better idea, but i would use the xpath parser for something like this:

```auto
[[inputs.file]]
  files = ["data"]
  data_format = "xpath_json"
  xpath_native_types = true

  [[inputs.file.xpath]]
    metric_selection = "child::*"
    field_selection = "*"

```

produces:

```auto
file Temperature=19.6,mac="c47c8d60ebed",Fertility=90,Illuminance=1220,Moisture=15,RSSI=-82 1690290527000000000
file Fertility=98,Illuminance=851,Moisture=18,RSSI=-86,Temperature=18,mac="c47c8d6204f8" 1690290527000000000

```

You can continue to refine this
