Hi everyone,
I’m struggling with an automation and can’t figure out the best approach.
My goal is to receive a notification when:
- a window has been open for a certain amount of time, and
- a specific weather condition is true (for example, the outside temperature exceeds a certain value).
The problem is that the order in which these two conditions become true matters.
Scenario 1:
- The window is opened.
- After the configured time (e.g. 15 minutes), the automation is triggered.
- The weather condition is not true yet.
- Ten minutes later, the weather condition becomes true.
In this case, I don’t receive a notification because the trigger already fired earlier, and conditions are only checked at that moment.
Scenario 2: If I instead use the weather condition as the trigger and check whether the window has already been open for at least 15 minutes as a condition, it works for the scenario above. However, the opposite case no longer works:
- The weather condition is already true.
- I open the window.
- The window stays open for 15 minutes.
Since the weather condition doesn’t change, the automation never triggers, so I don’t get a notification.
Basically, I want a notification whenever both conditions are true, regardless of which one becomes true first.
What would be the recommended way to implement this in Home Assistant? Is there a common pattern for this, or should I use multiple automations, template triggers, or something else?
Thanks in advance!
Here is some code:
alias: Fenster - schließen OG Balkontür
description: ""
triggers:
- entity_id:
- trigger: state
entity_id:
- binary_sensor.haus_fenster_meldung_bedingung
to:
- "on"
from:
- "off"
conditions:
- condition: state
entity_id: binary_sensor.og_panorama_balkontur_fensterkontakt
state:
- "on"
for: >-
{{ states('input_number.fenster_offen_meldung_zeitspanne_initial') |
multiply(60) | int }}
actions:
- repeat:
while:
- condition: state
entity_id: binary_sensor.og_panorama_balkontur_fensterkontakt
state: "on"
- condition: state
entity_id: binary_sensor.haus_fenster_meldung_bedingung
state:
- "on"
sequence:
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.og_eingang
message: Bitte OG Balkontür schließen
target:
entity_id: tts.google_de_de
enabled: true
- choose:
- conditions:
- condition: template
value_template: "{{ repeat.index > 2 }}"
sequence:
- action: telegram_bot.send_message
metadata: {}
data:
message: OG Balkontür Fenster schließen
enabled: true
- delay: >-
{{
states('input_number.fenster_offen_meldung_zeitspanne_wiederholen')
| multiply(60) | int }}
mode: single