Repeating a trigger to check status

I’d like to create an automation that checks if a window is open but continually checks up to two times. The first time would be after 10 minutes then sends a message, then the second time 30 minutes and sends another message if the window is still open. I have an entry sensor trigger already but not sure how to do the rest.

Being new to HASS I’ve only been able to get to the send once and check status part. I saw there is a ‘repeat’ function but it didn’t seem to work properly. Image 2022-02-08 at 4.15.28 PM

Hi Rob,

If you only want to do the check two times, I see no need to do a repeat but simply do the check to consecutive times

  • first the trigger must be that the window has been open for 10 min
  • first action is to send the fist message
  • then wait 20 minutes
  • then a conditional action, that checks whether the window is still open, and if so sends the second message

I made this example for you:

alias: New Automation
description: ''
mode: single
trigger:
  - platform: state
    entity_id: variable.sensor_openclose1
    to: 'true'
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition: []
action:
  - service: notify.mobile_app_ghassans_iphone_12
    data:
      message: Widiow has been opren fyr 10 minutes!
  - delay:
      hours: 0
      minutes: 20
      seconds: 0
      milliseconds: 0
  - condition: state
    entity_id: variable.sensor_openclose1
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - service: notify.mobile_app_ghassans_iphone_12
    data:
      message: Window is still open

You can try it by

  • creating a new empty automation,
  • switch to the Edit in Yaml mode (by clicking on the 3 dots at the top right corner, and then choose “Edit in YAML” )
  • then paste my code into it
  • and correct to the name of your sensor, and the notification action to your device.

Please let me know if you have any challenges or questions

Kind regards,
Ghassan

Rather than using a delay (long delays in automations should be avoided) just use two triggers,

alias: Window Open
description: ''
mode: single
trigger:
  - platform: state
    entity_id: input_boolean.sensor_window
    to: 'on'
    for:
      hours: 0
      minutes: 10
      seconds: 0
    id: '10'
  - platform: state
    entity_id: input_boolean.sensor_window
    to: 'on'
    for:
      hours: 0
      minutes: 30
      seconds: 0
    id: '30'
condition: []
action:
  - service: notify.mobile_app_your_phone_here #### change this
    data:
      message: "Window has been open for {{trigger.id}} minutes!"

Is there a reason you are using an input_boolean rather then the window binary sensor?

My sensors are 443MHz RF. These are not integrated directly into HA, but through a sonoff bridge that receives the RF code and updates a home assistant “latest code” text sensor.
Then I defined one variable for each of my sensors, holding the current state as it value and the on/off codes as attributes. When then RF code received changes i do a match and update corresponding variable representing my sensor. That is why I use the variables :slight_smile:

I was actually asking Rob. His screenshot shows an input boolean rather than a binary sensor.

Sorry, I though you were asking me.

It is a very nice approach you have to the solution :+1:

1 Like

Thanks, the reason to avoid long delays in automations is that the longer the delay the more likely it could be interrupted by reloading automations or restarting home assistant. In this case this will mean the second notification may never happen if you use a delay.

Using two triggers, the times may be reset by a restart/reload but the notifications will still happen.

For time critical situations there is a method to use a timer and a routine to restore the timer after a restart (automation reloads aren’t an issue for timers). The overhead for doing this is not really warranted in this situation though. Here’s the link for interest’s sake https://community.home-assistant.io/t/restore-active-paused-timers-after-a-restart/274439

hello sir , i want some help about automation can you help me about sir