I’m trying to build a binary_sensor
template, the idea will be to check if the HVAC system is ON and if any doors have been opened.
The template will be much more complex than what I’m describing here, this is the simplified version with just the “problem”.
So, I have the following template, which works:
{{is_state('binary_sensor.kitchen_door', 'on') and is_state('climate.kitchen', 'heat')}}
But this changes to true
state immediately when a door is opened, what I want is to change to true
just a few seconds after the door is opened (the same behavior as in automations)
So, I have this:
{% set last_changed = (as_timestamp(now())-as_timestamp(states.binary_sensor.kitchen_door.last_changed)) | int %}
{{is_state('binary_sensor.kitchen_door', 'on') and is_state('climate.kitchen', 'heat') and last_changed > 10}}
The problem with the template above is that last_changed
is not updated systematically, which makes the code very erratic, sometimes it changes after 12 seconds, sometimes 20 seconds, and it has taken me about 40 seconds. which is a long time and not acceptable for my usecase.
This is very simple to do with automations, but I want to build a binary_sensor
instead.
Does anyone know a better way to achieve this?