I need to create sensor/binary sensor which will be change to on/off based
on incoming string on topic:
meaning, whenever DahuaVTO/BackKeyLight/Event publish event
with value_json.Action == ‘Pulse’ change to ON ,
I added expire_after: 3 and i expect it will act as momentary sensor .
(turn on if true–>delay 3 second ->go back to off)
see json:
{"Action":"Pulse","Data":{"CallID":"8","LocaleTime":"2020-04-30 20:14:50","UTC":1588270490}}
and save the json_attributes value_json.Data.State.
it is working fine with the logic- it change on/off but the sensor go back to Unknown .
- I dont see the attributes at all
see:
sensor:
- platform: mqtt
name: intercom_calling
state_topic: DahuaVTO/BackKeyLight/Event
value_template: "{% if value_json.Action is defined and value_json.Action == 'Pulse' %} on {% else %} off {% endif %}"
json_attributes_topic: DahuaVTO/BackKeyLight/Event
json_attributes_template: >-
{"state":"{{value_json.Data.State}}}
#device_class: motion
expire_after: 3