Cancel running automation when message ist clicked

Hello Everyone,
Im quite new to the home assistant world.
Currently im using an automation that triggers when noone is at home and the vacuum starts.
Sometimes i dont want it to start and get a notification with some kind of timer to cancel it. When i do nothing it starts a usual.
Here is my current skeleton with curicial parts missing.

alias: Clean when leaving
description: ""
trigger:
  - platform: state
    entity_id:
      - person.x
      - person.y
    from: home
    to: not_home
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: person.y
        state: not_home
      - condition: state
        entity_id: person.x
        state: not_home
      - condition: template
        value_template: >-
          {{ now() - states('sensor.roborock_last_clean_end') | as_datetime |
          as_local > timedelta(hours=16) }}
        alias: Last clean time check
      - condition: state
        entity_id: input_boolean.roborock_routine
        state: "on"
      - condition: state
        entity_id: input_boolean.guest_mode
        state: "off"
action:
  - service: notify.notify
    data:
      message: Roborock will start cleaning in 5 minutes
      data:
        actions:
          - action: CANCEL_CLEANING_START
            title: cancel cleaning
  - device_id: xxxxxxxxxxxxxxxxxxxxxxxx
    domain: vacuum
    entity_id: vacuum.roborock
    type: clean
mode: single

any ideas?

Use a wait_for_trigger to wait 5 minutes for the cancellation action. Proceed with cleaning only if the wait timed out by checking the wait variable:

alias: Clean when leaving
description: ""
trigger:
  - platform: state
    entity_id:
      - person.x
      - person.y
    from: home
    to: not_home
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: person.y
        state: not_home
      - condition: state
        entity_id: person.x
        state: not_home
      - condition: template
        value_template: >-
          {{ now() - states('sensor.roborock_last_clean_end') | as_datetime |
          as_local > timedelta(hours=16) }}
        alias: Last clean time check
      - condition: state
        entity_id: input_boolean.roborock_routine
        state: "on"
      - condition: state
        entity_id: input_boolean.guest_mode
        state: "off"
action:
  - service: notify.notify
    data:
      message: Roborock will start cleaning in 5 minutes
      data:
        actions:
          - action: CANCEL_CLEANING_START
            title: cancel cleaning
  - alias: "Wait for cancellation"
    wait_for_trigger:
    - platform: event
      event_type: mobile_app_notification_action
      event_data:
        action: CANCEL_CLEANING_START
    timeout:
      minutes: 5
  - if: "{{ wait.trigger is none }}"
    then:
    - device_id: xxxxxxxxxxxxxxxxxxxxxxxx
      domain: vacuum
      entity_id: vacuum.roborock
      type: clean
mode: single
2 Likes