MQTT Payload sensor problem

hello
i am facing a problem cant get the payload value from mqtt sensor
my payload is the following:

21:27:19 RSL: Energy/tele/SENSOR = {“Time”:“2019-12-01T21:27:19”,“ENERGY”:{“TotalStartTime”:“2019-08-17T11:47:41”,“Total”:48.812,“Yesterday”:11.081,“Today”:4.948,“Period”:0,“Power”:141,“ApparentPower”:278,“ReactivePower”:239,“Factor”:0.51,“Frequency”:51,“Voltage”:223,“Current”:1.249}}

i need to extract each value alone
can anybody helo me ?

It’s easier to think about when you view it when it’s been formatted. I just plugged it into this website:

{ 
   “Time”:“2019-12-01T21:27:19”,
   “ENERGY”:{ 
      “TotalStartTime”:“2019-08-17T11:47:41”,
      “Total”:48.812,
      “Yesterday”:11.081,
      “Today”:4.948,
      “Period”:0,
      “Power”:141,
      “ApparentPower”:278,
      “ReactivePower”:239,
      “Factor”:0.51,
      “Frequency”:51,
      “Voltage”:223,
      “Current”:1.249
   }
}

So you could access any of these values in a template by using something like:

{{ value_json.Time }}

or

{{ value_json.ENERGY.TotalStartTime }}

The values are case-sensitive.

2 Likes

strange this is what i tried and still not getting data

  • platform: mqtt
    name: “Voltage”
    state_topic: “Energy/tele/SENSOR”
    value_template: ‘{{ value_json.ENERGY.Voltage }}’

read this

strange still not getting any data on home assistant
the broker log is :
1575313374: New connection from 192.168.1.113 on port 1883.
[INFO] found lebhack on local database
1575313375: New client connected from 192.168.1.113 as EM (p2, c1, k15, u’user’).
1575313535: Saving in-memory database to /data/mosquitto.db.

the logs for the tasmota is the following:
20:31:39 RSL: tasmota/tele/SENSOR = {“Time”:“2019-12-02T20:31:39”,“ENERGY”:{“TotalStartTime”:“2019-08-17T11:47:41”,“Total”:55.367,“Yesterday”:5.435,“Today”:6.068,“Period”:1,“Power”:223,“ApparentPower”:373,“ReactivePower”:300,“Factor”:0.60,“Frequency”:51,“Voltage”:222,“Current”:1.680}}
20:31:42 RSL: tasmota/tele/HASS_STATE = {“Version”:“7.1.0(tasmota)”,“BuildDateTime”:“2019-11-30T20:52:32”,“Core”:“2_6_2”,“SDK”:“2.2.1(cfd48f3)”,“Module”:“Generic”,“RestartReason”:“Software/System restart”,“Uptime”:“0T00:28:55”,“WiFi LinkCount”:1,“WiFi Downtime”:“0T00:00:06”,“MqttCount”:1,“BootCount”:143,“SaveCount”:198,“IPAddress”:“192.168.1.113”,“RSSI”:“66”,“LoadAvg”:19}
20:31:49 RSL: tasmota/tele/STATE = {“Time”:“2019-12-02T20:31:49”,“Uptime”:“0T00:29:02”,“UptimeSec”:1742,“Heap”:25,“SleepMode”:“Dynamic”,“Sleep”:50,“LoadAvg”:19,“MqttCount”:1,“Wifi”:{“AP”:1,“SSId”:“Hackerz-Gate”,“BSSId”:“D8:EB:97:25:19:50”,“Channel”:1,“RSSI”:66,“LinkCount”:1,“Downtime”:“0T00:00:06”}}
2

the config file is the following :

  • platform: mqtt
    name: “Power”
    state_topic: “tasmota/tele/SENSOR”
    value_template: ‘{{ value_json[“ENERGY”][“Yesterday”] }}’
    unit_of_measurement: “kWh”

  • platform: mqtt
    name: “Sonoff_PowerFactor”
    state_topic: “tasmota/tele/SENSOR”
    value_template: ‘{{ value_json[“ENERGY”][“Voltage”] }}’

  • platform: mqtt
    name: “POW Current”
    state_topic: “tasmota/tele/SENSOR”
    value_template: ‘{{ value_json[“ENERGY”].Current }}’
    unit_of_measurement: ‘amps’

  • platform: mqtt
    name: “POW Power”
    state_topic: “tasmota/tele/SENSOR”
    value_template: ‘{{ value_json[“ENERGY”].Power }}’
    unit_of_measurement: ‘watts’

  • platform: mqtt
    name: “POW Voltage”
    state_topic: “tasmota/tele/SENSOR”
    value_template: ‘{{ value_json[“ENERGY”].Voltage }}’
    unit_of_measurement: ‘volts’

This may seem trivial, but it’s really difficult to examine your YAML and logs when they’re not in a monospaced font with whitespace preserved. Can you surround your copied and pasted stuff with three back ticks before and after on their own lines?

Please read this post:

1 Like

i think my problem is getting RSL not MQT in the tasmota logs
that means no connection to broker

Can you monitor your mqtt messages from an app or the command line and not from tasmota itself? This would confirm that theory.

Is mqtt configured properly for that device?

this is my setup

my console

image

  - platform: mqtt
    name: "Washing Power"
    state_topic: "tele/SONOFF-POW1/SENSOR"
    value_template: "{{value_json['ENERGY'].Power }}"
    qos: 1
    unit_of_measurement : "W"
  - platform: mqtt
    name: "Washing Current"
    state_topic: "tele/SONOFF-POW1/SENSOR"
    value_template: "{{value_json['ENERGY'].Current }}"
    qos: 1
    unit_of_measurement : "A" 
  - platform: mqtt
    name: "Washing Energy Today"
    state_topic: "tele/SONOFF-POW1/SENSOR"
    value_template: "{{value_json['ENERGY'].Today }}"
    qos: 1
    unit_of_measurement : "kWh" 

1 Like

Steve, you have suggest very good too, I also use https://jsonformatter.org for some advance operation like validation and converting json to xml, csv and much more.