Hello,
I’m trying to create a sensor that contains the last time a different sensor was in a certain state. The below template sensor contains the correct value when the binary_sensor is on, otherwise it contains ‘Unknown’. Why is this? When the bvinary sensor is not on, it should set itself to the previous state of the sensor therefor always containing a timestamp.
- sensor:
- name: "Front door last opened time"
unique_id: sensor_frontdoor_last_opened_time
state: >
{% set current = states("sensor.sensor_frontdoor_last_opened_time") %}
{% if states('binary_sensor.frontdoor_sensor_window_door_is_open') == 'on' %}
{{ int(as_timestamp(now()), 0) }}
{% else %}
{{ current }}
{% endif %}
2 posts - 2 participants