Automations: how to stop a sequence conditionally ("if y is not triggered after x within t, do z")

Hi! I’m still a novice when it comes to automations, scripts and templates, and I wasn’t able to find a solution here or elsewhere, so please forgive me if this is a simple matter or if this has been addressed somewhere already and I failed to find it.

I’m trying to make a local medical alert system for my mother (there are no good commercial offers where she lives). I’m looking for a way to make it possible to stop the sequence of actions if it’s a false alarm (e.g., after a tripple press of a button). So, for example, the alarm sequence is triggered after a long push is detected, and aborted if a tripple push is detected within t+x.

Here is a diagram I made to collect my thoughts and plan this out with some more info on the general idea and what I want to achieve.

Thanks for any suggestions!

Ok, I think I kind of figured this out. Please let me know if there is a better way of doing it : )

alias: Glowny alarm mama 2
description: ''
trigger:
  - type: turned_on
    platform: device
    device_id: a3f9d586a0382d4f3f31c9695465d46a
    entity_id: binary_sensor.shelly_button1_a4cf12f454f8_longpush
    domain: binary_sensor
condition: []
action:
  - device_id: ae330f308ae09baef425b0ab02dc79d4
    domain: mobile_app
    type: notify
    message: Alarm wlaczony
    title: Alarm wlaczony
    enabled: false
  - service: media_player.play_media
    target:
      entity_id: media_player.shield
    data:
      media_content_id: >-
        media-source://tts/google_translate?message=Alarm+zosta%C5%82+w%C5%82%C4%85czony%2C+
      media_content_type: provider
    metadata:
      title: 'Alarm został włączony, '
      thumbnail: https://brands.home-assistant.io/_/google_translate/logo.png
      media_class: app
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://tts
        - media_content_type: provider
          media_content_id: >-
            media-source://tts/google_translate?message=Alarm+zosta%C5%82+w%C5%82%C4%85czony%2C+
    enabled: false
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - if:
      - condition: template
        value_template: >-
          {{ (now() -
          states.binary_sensor.shelly_button1_a4cf12f454f8_triple_shortpush.last_changed).total_seconds()
          < 60 }}
    then:
      - stop: ''
    else:
      - service: notify.mobile_app_hma_l29
        data:
          message: Alarm mama
          title: Alarm mama
      - delay:
          hours: 0
          minutes: 1
          seconds: 0
          milliseconds: 0
      - if:
          - condition: template
            value_template: >-
              {{ (now() -
              states.input_boolean.alarm_off.last_changed).total_seconds() < 60
              }}
        then:
          - stop: ''
        else:
          - service: notify.mobile_app_hma_l29
            data:
              message: SMS 112
              title: SMS 112
mode: single