I got sensors to check the open/close state on several windows in my home. If one of the windows is opened and has not been closed after 10 minutes a notification should be sent telling me to close the specific window.
I do not want to write an automation for every window, so I tried to write just one automation. But I am stuck with the template condition to check whether the state of the triggered window sensor is still “on”. Could someone give me a hint?
- id: fenster1
alias: Notification Window opening
trigger:
- platform: state
entity_id: binary_sensor.openclose_12
to: 'on'
- platform: state
entity_id: binary_sensor.openclose_13
to: 'on'
- platform: state
entity_id: binary_sensor.openclose_14
to: 'on'
action:
- delay: '0:10'
- condition:
condition: template
state_template: {% states('trigger.entity_id') = "on" %}
- service: notify.home
data:
title: '*Please close window {{ trigger.entity_id }}*'
message: 'Lorem ipsum'
my code evolved a bit but I have problems with my template condition.
Now, it is working so far that the first notification is sent after one window has been open for 10 minutes. The 2nd notification, however, should be sent after 5 minutes only if the window is still open. This does not work. At the moment, the 2nd notification will be sent regardless of the window state.
Thanks for sharing that config. I see two problems with this, which I fixed in my version.
mode: single only allows for one run. I have multiple windows which I want to send notifications independently. With mode: single, opening a window for 10min would cancel all notifications for other windows. The correct mode would be parallel
In your “until”-condition you are using trigger.to_state.state which, as far as I understand, should be a fixed value during the whole automation run (otherwise your time-calculation wouldn’t work). Therefore this is effectively an endless loop. I changed this to states(trigger.entity_id) which should refer to the current value.
Here is my yaml (for any future visitors stumbling upon this thread):