# Reading Tasmota Mqtt Content

**URL:** <https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671>\
**Category:** Telegraf\
**Tags:** mqtt, json\
**Created:** [June 22, 2024, 10:05am UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671 "2024-06-22T10:05:48Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paddy65305](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/paddy65305/32/15815_2.png) [@Paddy65305](https://community.influxdata.com/u/Paddy65305)\
**Post date:** [June 22, 2024, 10:05am UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/1 "2024-06-22T10:05:48Z")

</div>

I have a ESP32 with Tasmota how is put to the digital electricity meter to get the information.  
this send to Topics:  
one on Tasmota/STATUS10 every 15min:  
{“StatusSNS”:{“Time”:“2024-06-22T10:00:01”,“MT175”:{“E\_in”:12642.6,“P”:2256.00,“L1”:263.00,“L2”:6.00,“L3”:1988.00,“Server\_ID”:“0649534b010e1f5f9b3b”}}}

and one on Tasmota/SENSOR with the current change Values. This seams to be the content of StatusSNS  
{“Time”:“2024-06-22T10:00:01”,“MT175”:{“E\_in”:12642.6,“P”:2256.00,“L1”:263.00,“L2”:6.00,“L3”:1988.00,“Server\_ID”:“0649534b010e1f5f9b3b”}}  
But then only one of the Fields in MT175.\* is sendet.  
I try to get a messerument with all of this five Fields put all version I try didn  
t work.

I have try a data\_format=“xpath\_json” version but there I get no values, and with to lines above I get the Error: configuration specified the fields [“timestamp\_path”], but they were not used. This is either a typo…

data\_format = “json\_v2”  
[[inputs.mqtt\_consumer.json\_v2]]  
[[inputs.mqtt\_consumer.json\_v2.object]]  
path = “StatusSNS”  
timestamp\_path = “Time”  
timestamp\_format = “2006-01-02T15:04:05”  
[[inputs.mqtt\_consumer.json\_v2.object.field]] # fields by key and type  
P = “number(MT175.P)”  
L1 = “number(MT175.L1)”  
L2 = “number(MT175.L2)”  
L3 = “number(MT175.L3)”  
E\_in = “number(MT175.E\_in)”

---

<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:** [June 25, 2024, 2:42pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/2 "2024-06-25T14:42:33Z")

</div>

Hi,

You have a couple of issues:

> Error: configuration specified the fields [“timestamp\_path”],

This is because the timestamp path config option for a json\_v2 object is called `timestamp_key`

> [[inputs.mqtt\_consumer.json\_v2.object.field]]

You have two options here either:

> [[inputs.file.json\_v2.object.field]]  
> [inputs.file.json\_v2.object.fields]

Both options have different settings. The fields, note plural and a list, is a list of key values, while the field, singular, is something that can be specified multiple times and specify multiple paths, keys, etc.

---

<div class="post-metadata">

**Author:** ![Paddy65305](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/paddy65305/32/15815_2.png) [@Paddy65305](https://community.influxdata.com/u/Paddy65305)\
**Post date:** [June 26, 2024, 2:20pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/3 "2024-06-26T14:20:37Z")

</div>

As I plan to use DeepSleep there is only Tasmota/SENSOR…

So what is the easiest way to get the information from the SENSOR-Topic:

:{“Time”:“2024-06-22T10:00:01”,“MT175”:{“E\_in”:12642.6,“P”:2256.00,“L1”:263.00,“L2”:6.00,“L3”:1988.00,“Server\_ID”:“0649534b010e1f5f9b3b”}}

but can also be only one Information like:  
{“Time”:“2024-06-22T10:00:01”,“MT175”:{“L2”:6.00}}

But I want for sure collect all information. (or them with all information)

---

<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:** [June 26, 2024, 2:55pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/4 "2024-06-26T14:55:48Z")

</div>

I would use `xpath_json`:

```toml
data_format = "xpath_json"
xpath_native_types = true

[[inputs.mqtt_consumer.xpath]]
  metric_name = "'metric'"
  field_selection = "/MT175/descendant::*"
  timestamp = "/Time"
  timestamp_format = "2006-01-02T15:04:05"

```

Which would take this JSON:

```json
{
    "Time": "2024-06-22T10:00:01",
    "MT175": {
      "E_in": 12642.6,
      "P": 2256,
      "L1": 263,
      "L2": 6,
      "L3": 1988,
      "Server_ID": "0649534b010e1f5f9b3b"
    }
}

```

and produce:

```s
metric E_in=12642.6,L1=263,L2=6,L3=1988,P=2256,Server_ID="0649534b010e1f5f9b3b" 1719050401000000000

```

or with this JSON:

```json
{
    "Time": "2024-06-22T10:00:01",
    "MT175": {
      "L2": 6
    }
}

```

produce:

```s
metric L2=6 1719050401000000000

```

I’ll add there are two things you might need to think about as well:

1. Do you want the server id to be a tag?
2. The timestamps are the same in these examples. In this case, the 2nd L2 value would win. In this case they are the same so it wouldn’t matter, but if they were different just be aware that when metrics are named the same, have the same timestamp and don’t have any tags, then the last value wins.

---

<div class="post-metadata">

**Author:** ![Paddy65305](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/paddy65305/32/15815_2.png) [@Paddy65305](https://community.influxdata.com/u/Paddy65305)\
**Post date:** [June 26, 2024, 3:12pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/5 "2024-06-26T15:12:15Z")

</div>

1. the serverID is not needed, I have only one digital electricity meter and it want be change (and if it change it will only replace so for the timeline it is’nt important.
2. there will be multiple publishing in the same second from tasmota. so if only one L1,L2,L3,P is save its okay, but one should be inserted.

is there a possible that there is no Tag set with “Tasmota/SENSOR”. I added befor via API and scripting and there is also no Tag, that make later in Grafana Problems.

---

<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:** [June 26, 2024, 3:18pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/6 "2024-06-26T15:18:20Z")

</div>

> [@Paddy65305](#):
>
> is there a possible that there is no Tag set with “Tasmota/SENSOR”

Are you trying to add a tag to the resulting metric like:

```s
metric,source=Tasmota/SENSOR L2=6 1719050401000000000

```

If that is the case you can add to the end of your mqtt\_consumer config:

```auto
[inputs.mqtt_consumer.tags]
  source = "Tasmota/SENSOR"

```

Or remove a tag?

---

<div class="post-metadata">

**Author:** ![Paddy65305](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/paddy65305/32/15815_2.png) [@Paddy65305](https://community.influxdata.com/u/Paddy65305)\
**Post date:** [June 26, 2024, 3:37pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/7 "2024-06-26T15:37:05Z")

</div>

no removing the tag.

seams that the xpath didn’t match…  
I change to //MT175 but the time didn’t work. It week every 10minutes (bad Idea to test with deepsleep 10min)

the time was at min 50 and the influx was 51min

---

<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:** [June 26, 2024, 3:54pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/8 "2024-06-26T15:54:18Z")

</div>

> [@Paddy65305](#):
>
> no removing the tag.

What is setting this tag? Can you show me an example metric?

---

<div class="post-metadata">

**Author:** ![Paddy65305](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/paddy65305/32/15815_2.png) [@Paddy65305](https://community.influxdata.com/u/Paddy65305)\
**Post date:** [June 26, 2024, 4:14pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/9 "2024-06-26T16:14:34Z")

</div>

perhaps its easer if I show you an query:

```auto
from(bucket: "myBucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "energy")
  |> filter(fn: (r) => r["_field"] == "P")
  |> filter(fn: (r) => r["topic"] != "")
  |> last()

```

I don’t want the topic now I have one REsult with topic Tasmota/SENSOR and one TASMOTA/STATUS10  
and as I Inserted before there is no topic needed, was is what I want

---

<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:** [June 26, 2024, 4:25pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/10 "2024-06-26T16:25:42Z")

</div>

> [@Paddy65305](#):
>
> perhaps its easer if I show you an query:

Dropping data in influxdb depends on whatever version and release of influxdb you are using. I’m not a huge influxdb expert, but if you let me know what version you are using I might be able to guide you there.

---

<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:** [June 26, 2024, 4:27pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/11 "2024-06-26T16:27:23Z")

</div>

> [@jpowers](#):
>
> `mqtt_consumer`

If you want to just drop the `topic` tag from your metrics you can use the `tagexclude` modifiers see: [telegraf/docs/CONFIGURATION.md at master · influxdata/telegraf · GitHub](https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#modifiers)

```toml
tagexclude = ["topic"]

```

---

<div class="post-metadata">

**Author:** ![Paddy65305](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/paddy65305/32/15815_2.png) [@Paddy65305](https://community.influxdata.com/u/Paddy65305)\
**Post date:** [June 26, 2024, 4:30pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/12 "2024-06-26T16:30:10Z")

</div>

the newest influx I think: InfluxDB v2.7.6

---

<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:** [June 26, 2024, 4:40pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/13 "2024-06-26T16:40:44Z")

</div>

If you only have a few records it might be easier to export, edit them, delete the database, and push them back.

This shows how to do larger deletes where you will delete rows with specific tag values:

> **[Delete data | InfluxDB OSS v2 Documentation](https://docs.influxdata.com/influxdb/v2/write-data/delete-data/)**
>
> Use the influx CLI or the InfluxDB API /api/v2/delete endpoint to delete data from an InfluxDB bucket.

Make sure you have a backup!

---

<div class="post-metadata">

**Author:** ![Paddy65305](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/paddy65305/32/15815_2.png) [@Paddy65305](https://community.influxdata.com/u/Paddy65305)\
**Post date:** [June 26, 2024, 5:55pm UTC](https://community.influxdata.com/t/reading-tasmota-mqtt-content/34671/14 "2024-06-26T17:55:24Z")

</div>

it was nearly one day, every 10minutes so I think API would be easier. I will read the docu and look.  
But I have now the fields with telegraf in. 😃  
thanks
