Mqtt template value parsing

I’m adding a new mqtt sensor and I’m stuck on getting a value from what’s published. All I get is unknown.

Vera MQTT publishes this:
MQTT Last Message:{"Payload":"{\"DeviceId\":7,\"DeviceName\":\"smartmeter\",\"DeviceType\":\"urn:schemas-smartmeter-han:device:SmartMeterHAN1:1\",\"OldWatts\":911,\"RoomId\":1,\"RoomName\":\"House\",\"ServiceId\":\"urn:micasaverde-com:serviceId:EnergyMetering1\",\"Time\":1481661475,\"Variable\":\"Watts\",\"Watts\":929}","Topic":"Vera/Events/smartmeter"}

Here is my sensor:

  • platform: mqtt
    state_topic: “Vera/+/smartmeter/#”
    name: “Smart Meter”
    unit_of_measurement: “Watts”
    value_template: “{{ value_json.watts }}”

My HA logs show this:

16-12-13 12:31:22 homeassistant.core: Bus:Handling <Event mqtt_message_received[L]: payload={"DeviceId":7,"DeviceName":"smartmeter","DeviceType":"urn:schemas-smartmeter-han:device:SmartMeterHAN1:1","OldWatts":652,"RoomId":1,"RoomName":"House","ServiceId":"urn:micasaverde-com:serviceId:EnergyMetering1","Time":1481661082,"Variable":"Watts","Watts":647}, qos=0, topic=Vera/Events/smartmeter>

I think you need
{{ value_json.Watts }}

(Capital W)

I tried that as well. Also flailed and tried {{ value.Watts }} and {{ value.watts }}

It’s definitely a cap W regardless.

This works if you put it in the template dev tool. Maybe I don’t understand what MQTT is passing you.

{% set value_json={“DeviceId”:7,“DeviceName”:“smartmeter”,“DeviceType”:“urn:schemas-smartmeter-han:device:SmartMeterHAN1:1”,“OldWatts”:652,“RoomId”:1,“RoomName”:“House”,“ServiceId”:“urn:micasaverde-com:serviceId:EnergyMetering1”,“Time”:1481661082,“Variable”:“Watts”,“Watts”:647} %}

{{value_json.Watts}}

If not already, could you also try removing /# at the end of the configured state_topic. Just for the testing purpose.

1 Like

Thank you!!

  - platform: mqtt
    state_topic: "Vera/+/smartmeter"
    name: "Smart Meter"
    unit_of_measurement: "Watts"
    value_template: '{{ value_json.Watts }}'