Tasmota SPM JSON to MQTT_CONSUMER

Hi I’m getting this JSON from my tasmota SPM

15:15:47.864 MQT: sonoff/tele/ss-tal1-c1/SENSOR = {“Time”:“2024-04-30T15:15:47”,“SPM”:{“Energy”:[158.3,78.8,124.1,22.7,79.2,32.3,187.1,1.0],“Yesterday”:[12.7,6.4,8.8,5.5,6.5,1.6,16.4,0.1],“Today”:[1.6,0.8,1.1,0.7,0.8,0.7,1.8,0.1],“ActivePower”:[530.1,267.3,368.1,230.6,266.9,248.6,341.8,122.8],“ApparentPower”:[536.7,449.7,372.0,232.8,268.5,251.2,343.7,123.4],“ReactivePower”:[82.6,360.8,52.6,31.4,27.9,35.4,36.6,11.0],“Factor”:[0.99,0.59,0.99,0.99,0.99,0.99,0.99,1.00],“Voltage”:[221.1,223.0,221.1,221.3,222.7,220.9,221.2,222.9],“Current”:[2.43,2.02,1.69,1.05,1.20,1.13,1.55,0.55]}}

I want to save the data only of the SPM part, in my influxdb

[[inputs.mqtt_consumer]]
  client_id = "telegraf"
  username = "myuser"
  password = "mypass"
  data_format = "json_v2"
  servers = [ "tcp://vernemq.mqtt:1883" ]
  topics = [ "tele/+/+/+/SENSOR" ]

  [[inputs.mqtt_consumer.json_v2]]
    measurement_name = "spm_data"

    [[inputs.mqtt_consumer.topic_parsing]]
      topic = "tele/+/+/+/SENSOR"
      tags = "_/site/room/sensor/_"

    [[inputs.mqtt_consumer.json_v2.tag]]
    path = "Time"

    [[inputs.mqtt_consumer.json_v2.object]]
    path = "SPM"
    disable_prepend_keys = true

      [[inputs.mqtt_consumer.json_v2.field]]
      path = "Energy"
      type = "float"

      [[inputs.mqtt_consumer.json_v2.field]]
      path = "Yesterday"
      type = "float"

      [[inputs.mqtt_consumer.json_v2.field]]
      path = "Today"
      type = "float"

      [[inputs.mqtt_consumer.json_v2.field]]
      path = "ActivePower"
      type = "float"

      [[inputs.mqtt_consumer.json_v2.field]]
      path = "ApparentPower"
      type = "float"

      [[inputs.mqtt_consumer.json_v2.field]]
      path = "ReactivePower"
      type = "float"

      [[inputs.mqtt_consumer.json_v2.field]]
      path = "Factor"
      type = "float"

      [[inputs.mqtt_consumer.json_v2.field]]
      path = "Voltage"
      type = "float"

      [[inputs.mqtt_consumer.json_v2.field]]
      path = "Current"
      type = "float"

I used that and nothing is coming into my influxdb I dunno whats wrong or maybe there is another way

Hi,

What do you want your metric to look like? The values under SPM all appear to be arrays of data.

Are you looking for something like:

file ActivePower="[530.1 267.3 368.1 230.6 266.9 248.6 341.8 122.8]",ApparentPower="[536.7 449.7 372 232.8 268.5 251.2 343.7 123.4]",Current="[2.43 2.02 1.69 1.05 1.2 1.13 1.55 0.55]",Energy="[158.3 78.8 124.1 22.7 79.2 32.3 187.1 1]",ReactivePower="[82.6 360.8 52.6 31.4 27.9 35.4 36.6 11]",Today="[1.6 0.8 1.1 0.7 0.8 0.7 1.8 0.1]",Factor="[0.99 0.59 0.99 0.99 0.99 0.99 0.99 1]",Voltage="[221.1 223 221.1 221.3 222.7 220.9 221.2 222.9]",Yesterday="[12.7 6.4 8.8 5.5 6.5 1.6 16.4 0.1]" 1714506635000000000

Or break up each array into its own element like:

file ActivePower_5=248.6,Current_1=2.02,ReactivePower_6=36.6,Yesterday_2=8.8,Yesterday_4=6.5,ActivePower_3=230.6,ActivePower_6=341.8,Current_4=1.2,Voltage_2=221.1,Yesterday_6=16.4,ActivePower_0=530.1,Factor_0=0.99,Factor_6=0.99,ReactivePower_7=11,ApparentPower_6=343.7,Factor_3=0.99,Factor_4=0.99,Current_5=1.13,Energy_3=22.7,ActivePower_2=368.1,Factor_5=0.99,Today_1=0.8,Voltage_5=220.9,ActivePower_1=267.3,Energy_4=79.2,ReactivePower_1=360.8,Voltage_3=221.3,ReactivePower_0=82.6,Today_0=1.6,Yesterday_0=12.7,ReactivePower_2=52.6,Voltage_1=223,Current_2=1.69,Energy_7=1,Today_2=1.1,Today_3=0.7,Today_5=0.7,Today_6=1.8,Yesterday_1=6.4,Voltage_7=222.9,ActivePower_4=266.9,ApparentPower_7=123.4,Factor_7=1,ReactivePower_3=31.4,ReactivePower_4=27.9,Today_4=0.8,Voltage_6=221.2,Yesterday_7=0.1,Current_0=2.43,Current_3=1.05,Current_7=0.55,Energy_2=124.1,Energy_5=32.3,Today_7=0.1,Yesterday_3=5.5,ApparentPower_0=536.7,Factor_2=0.99,ReactivePower_5=35.4,Yesterday_5=1.6,ActivePower_7=122.8,ApparentPower_2=372,Energy_1=78.8,Factor_1=0.59,Voltage_4=222.7,ApparentPower_1=449.7,ApparentPower_4=268.5,ApparentPower_5=251.2,Energy_0=158.3,Energy_6=187.1,Voltage_0=221.1,ApparentPower_3=232.8,Current_6=1.55 1714506766000000000

I did the second with:

[[inputs.file]]
  files = ["file.json"]
  data_format = "xpath_json"
  xpath_print_document = true
  xpath_native_types = true

  [[inputs.file.xpath]]
    metric_selection = "/SPM"
    field_selection = "descendant::*[not(*)]"
1 Like

Sorry I think that maybe I didn’t explained it very well

  1. My SPM is a device configured with Tasmota, it send the values through MQTT and I get the Json that I detailed first, that’s why I started with the MQTT_Consumer
  2. Since internally the SPM has “channels” that receive different values I want them to appear in my influxdb something like your second option