Keep sending notification until I click it off / click a button

I have an automation that when triggered sends me notifications every minute until a specific door is closed.

I would like to set it up in a way where the notifications would stop coming, despite the door not being closed, when I click on the notification or click a notification button.

Is that possible? If so, could you please point me in the right direction?

The alert integration should be able to help you. Add a boolean helper and have the notification action toggle the boolean thus turning off the alert.

1 Like

I have this:

repeat:
  sequence:
    - service: notify.mobile_app_honza_phone
      metadata: {}
      data:
        message: TTS
        data:
          tts_text: Heating is on! Close bathroom door!
          media_stream: alarm_stream_max
    - service: notify.mobile_app_honza_phone
      metadata: {}
      data:
        message: test
        data:
          media_stream: alarm_stream_max
          actions:
            - action: DISABLE_NOTIFICATION
              title: Disable notification
              icon: sfsymbols:bell
        title: test
    - wait_for_trigger:
        - platform: event
          event_type: mobile_app_notification_action
          event_data:
            action: DISABLE_NOTIFICATION
      timeout:
        hours: 0
        minutes: 1
        seconds: 0
        milliseconds: 0
      continue_on_timeout: false
    - service: input_boolean.turn_on
      target:
        entity_id: input_boolean.honza_door_open_acknowledged
      data: {}
    - delay:
        hours: 0
        minutes: 1
        seconds: 0
        milliseconds: 0
      enabled: true
  until:
    - condition: or
      conditions:
        - condition: state
          entity_id: input_boolean.honza_door_open_acknowledged
          state: "on"
        - type: is_not_open
          condition: device
          device_id: foo
          entity_id: bar
          domain: binary_sensor

Basically, it has do until block, when it sends actionable notification, then it waits for trigger which has a timeout of 1min and continue on timeout set to False.

The expectation is that it will fire the notifications, wait for the actionable trigger for one minute and:

  • if it comes, it will continue setting the bool to ON
  • if it doesn’t come, it sends another set of notifications (since we’re in a do until block) and again wait for the trigger.

However that is not what is happening when I test the part of the automation (click Run). It waits for the 1min timeout and if it doesn’t come, the automation just ends.

Either the timeout truly kills the whole automation (and not just the relevant part) or I’m doing something wrong.

You set continue_on_timeout to false so when it times out, the automation ends.

Change it to true.

1 Like

That doesn’t make any sense, though. I don’t want to continue triggering actions below the wait for trigger action. However, again, we are in a do until loop so the loop should start again, despite the timeout.

Here’s the documentation for Wait Timeout.

You can also get the script to abort after the timeout by using optional continue_on_timeout: false .

Without continue_on_timeout: false the script will always continue since the default for continue_on_timeout is true .

You can check the wait variable to determine if the wait_for_trigger was triggered or simply timed out (and then have it decide what to do next). Of course, continue_on_timeout must be true in order to do that.

The general idea is that you want to wait for something to happen but you don’t want it to wait forever. You check to see if that “something” actually happened or it just gave up waiting for it to happen.

Thanks for the link. I already looked through that previously.
Still, it doesn’t make sense.

I have basically a loop that does x things, like so:

while conditions match do:
    do 1st thing
    do 2nd thing
    wait for the response from 2nd thing for 1 min
    if not timeout:
        do 3th thing

Normally, what would happen is that the script would do 1st and 2nd, then encounter a timeout, and the loop would start from the beginning. If we do not encounter a timeout, 3rd thing would get done.

But what you’re telling me it basically works like this:

while conditions match do:
    do 1st thing
    do 2nd thing
    wait for the response from 2nd thing for 1 min
    if timeout:
        exit the whole thing

Which, IMO, doesn’t make sense.

Maybe, the disconnect is due to the difference between visual editor and yaml. Because in the visual editor the Repeat action is set as “topmost” with all the other actions being nested within it (as it should IMO), whereas in YAML the Repeat action it is listed at the end. In which case, it would be slightly more understandable but still wonky.

Be that as it may, is there a way to make an automation like this?

while conditions match do:
    do 1st thing
    do 2nd thing
    wait for the response from 2nd thing for 1 min
    if not timeout:
        do 3th thing

You can check the wait variable to determine if the wait_for_trigger was triggered

I’ll look into that. Thanks

Yes.

The if not timeout part of your example is what I described in my previous post. The decision to execute the third “thing” will be based upon the value of the wait variable.


EDIT

Here’s an example:

  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.motion
        from: 'on'
        to: 'off'
    timeout: '00:15:00'
  - if: "{{ wait.trigger == none }}"
    then: 
       ... timed out waiting for trigger to occur ...
    else:
       ... triggered ...

Thanks mate, that helped!

Just for my peace of mind, I guess the representation of the original would be sth along the lines of:

while conditions match do:
    do 1st thing
    do 2nd thing
    wait for the response from 2nd thing for 1 min
    if continue on timeout == False and timeout:
        raise TimeoutException
    do 3rd thing
1 Like