Value Template MQTT

Hi!

I am trying to establish a value template to identify an MQTT state that qualifies by returning two json measures.

MQTT Topic: \light\light2
JSON variables that identify the state as “ON” are: “write”:“01” AND “success”:“true”
JSON variables that identify the state as “OFF” are: “write”:“00” AND “sucess”:“true”

This is a workaround for the devices that are BLE and do not respond to a “read” response and don’t have a direct “ON” characteristic.

Thanks!

Assuming you have not changed the default payload_on and payload_off options:

state_value_template: >
  {% if value_json.write == "01" and value_json.success == "true" %}
    ON
  {% elif value_json.write == "00" and value_json.success == "true" %}
    OFF
  {% else %}
    unknown
  {% endif %}
1 Like