I have a template sensor that stores the number of doors/windows currently open in the home. This is for external doors only.
I have an automation, that is triggered by the main entrance doors and the condition that checks if number of open doors is more than 1. Idea is to get a warning if any other door beside the entrance door is open when I try to leave the home.
Template sensor for number of doors open includes the entrance door itself. So if the entrance is open, value is more than 0.
- sensor:
- unique_id: d1c3df62-ddd4-4139-ad5d-1ecec8f94bcc
name: "Number of doors and windows open"
state: >
{{
states.binary_sensor
| selectattr('entity_id', 'search', '(door|window).*_contact')
| selectattr('state', '==', 'on')
| list
| count
}}
state_class: total
Then, I have an automation like so, that is triggered when I open the main door:
alias: Notify user about open doors when leaving
description: ""
triggers:
- trigger: state
entity_id:
- binary_sensor.entrance_door_contact
to: "on"
from: "off"
conditions:
- condition: numeric_state
entity_id: sensor.number_of_doors_and_windows_open
above: 1
- condition: state
entity_id: binary_sensor.entrance_motion
state: "on"
actions:
- action: notify.alexa_media_echo_spot
data:
message: "\"More than one door is open"
mode: single
The condition is that number of doors or windows open must be above 1 (including the entrance door itself).
At the time of writing this message, it is 10:00 AM local time. Automation says it was last triggered 14h ago (see picture), while when I open the automation, it says triggered 08:30 - how is that 14hours ago?
Now the final question - how do I guarantee that HA will use the template sensor value in the conditions part with the latest value, so sensor must be re-evaluated before automation is triggered.