Extract Current from Tasmota MQTT message

Hi All,
Looking for your help again.
My Tasmota flashed switch sends me periodic MQTT message on

“sonoff/tele/SENSOR”

The payload looks like

{
“Time” : “2019-04-10T21:27:23”,
“ENERGY” : {
“TotalStartTime” : “2019-04-08T17:35:14”,
“Total” : 1.717,
“Yesterday” : 0.88,
“Today” : 0.837,
“Power” : 0,
“ApparentPower” : 0,
“ReactivePower” : 0,
“Factor” : 0.0,
“Voltage” : 232,
“Current” : 0.0
}
}

out of which I want to extract the value of Current.
As this is nested JSON and Assuming “Template” is the way forward, I have added value_template: “{{ value_json[‘ENERGY’][‘Current’] }}” in my configuration. So configuration looks like,

switch:
- platform: mqtt
name: SomeThing
command_topic: “sonoff/cmnd/Power”
state_topic: “sonoff/stat/POWER”
payload_on: “ON”
payload_off: “OFF”
json_attributes_topic: “sonoff/tele/SENSOR”
value_template: “{{ value_json[‘ENERGY’][‘Current’] }}”
retain: true

Still HA, is not able to extract the data. In my configuration I see error

Error parsing value: ‘value_json’ is undefined (value: ON, template: {{ value_json[‘ENERGY’][‘Current’] }})

Any idea what am I doing wrong…

You need to create a sensor, not a switch.

That is my example. If you don’t have your files split like mine, be sure that bit of code is under ‘’’ sensor: ‘’’ in your config file.

If I make a sensor, I guess I won’t be able to control it via HA…
Or should I create 2 separate entities… one switch and another sensor for current ?

One switch, and a sensor for each value you want (current, voltage, etc.)

Thanks. Will try it…

This works too:

    value_template: '{{ value_json.ENERGY.Current }}'
2 Likes