Fire an action only after state change occured 30 min ago

Hi there,
i wanna fire an action when my windows keeps open for more than 30 minutes.
What I am trying to do is tell everybody that the windows is open for more than 30 minutes.
I played around with

{{ states.binary_sensor.schlafzimmer_fensterkontakt_links.last_changed.strftime(' %H:%M')}}
but can not figure our how to compare it with the current time to fire an action when 30 minutes are gone, but the

{{ states.binary_sensor.schlafzimmer_fensterkontakt_links.state}}

is ON only. So in short, I wanna fire an action when the window state is on from more than 30 Minutes

Try something like this -

  trigger:
    platform: state
    entity_id: binary_sensor.schlafzimmer_fensterkontakt_links
    to: 'on'
    for:
      minutes: 30

You could also try an alert:

alert:
  name: 'Bedroom Window Open Alert'
  entity_id: binary_sensor.bedroom_cold_outside
  state: 'on'
  repeat:
    - 30
    - 5
  can_acknowledge: True
  skip_first: 'true'
  notifiers:
    - ios_iphone

This will activate an alert when the specified sensor turns on.
It will send out the first notification after 30 minutes and then every 5 minutes until the sensor’s state changes (-> window closed).

I use a template binary sensor that also looks at the temperature difference between inside and outside.
(i.e. I didn’t want to receive notifications when it’s like 25°C outside in the summer)

Sebastian

how does this template binary looks like?

It’s a template binary sensor, i.e. a binary sensor defined by a template:

For my example above, it looks like this:

binary sensor:
  platform: template
  sensors:
    bedroom_cold_outside:
      value_template: '{{ states.sensor.bedroom_window.state == "Open"
                        and ( 7 <= now().strftime("%H") | int < 22 )
                        and (( states.sensor.fibaro_fgk_bedroom_temperature.state | int )
                          >= ( states.sensor.yweather_temperature.state | int + 5 )
                          or ( states.sensor.yweather_temperature.state == "unknown" )
                          or ( states.sensor.yweather_temperature.state | int <= 14 )) }}'

This will switch to “on” when all of the following conditions are true:

  • the window is open
  • the time is between 7:00 and 22:00 (as it’s my bedroom window, I dont’t want to be alerted when sleeping with an open window)
  • and at least one of the following conditions:
    • the outside temperature more than 5°C below the inside temperature
    • the yweather component is failing and does not currently return a temperature value (don’t want to freeze in winter times because of a failing component :wink: )
    • it’s below 14°C outside (that’s an arbitrary value I chose for cases where the inside temperature is within the 5°C range but it’s still “cold” - like 17°C inside, 14°C outside)

Hope that helps!

Sebastian

EDIT: as for the alert: as soon as the alert is active, it shows up in the HA web interface with an on/off switch next to it.
Turning it off will silence the notifications (for cases where you want to decide to leave the window open).
Closing and re-opening the window will restart/rearm the alert.