Reading Tasmota Mqtt Content

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:

and one on Tasmota/SENSOR with the current change Values. This seams to be the content of StatusSNS
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”
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)”


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


You have two options here either:


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.

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:


but can also be only one Information like:

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

I would use xpath_json:

data_format = "xpath_json"
xpath_native_types = true

  metric_name = "'metric'"
  field_selection = "/MT175/descendant::*"
  timestamp = "/Time"
  timestamp_format = "2006-01-02T15:04:05"

Which would take this 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:

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

or with this JSON:

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


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.
  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.

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

metric,source=Tasmota/SENSOR L2=6 1719050401000000000

If that is the case you can add to the end of your mqtt_consumer config:

  source = "Tasmota/SENSOR"

Or remove a tag?

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

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

perhaps its easer if I show you an query:

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

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.

If you want to just drop the topic tag from your metrics you can use the tagexclude modifiers see: telegraf/docs/ at master · influxdata/telegraf · GitHub

tagexclude = ["topic"]

the newest influx I think: InfluxDB v2.7.6

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:

Make sure you have a backup!

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. :smiley:

1 Like