Automatic gate closing with the possibility of being cancelled

Hello.
I have a Shely Uni to open and close the gate at home.
I have set up an automation that closes automatically after 2 minutes of opening the gate, and up to this point everything works.
My problem is if I wanted to leave the gate open I can’t.
I would like to set that if the close button is pressed the automation is cancelled. This way I could press close + stop (the stop is not connected to a Shelly) and the gate would remain open.
How can I do it?
Thank you.

Pushing close to leave open is not intuitive

I would create a template switch that does nothing. I would use that to disable close automation

Basically if switch ON the leave OPEN

If switch ON xx minutes send me notification “do you wanna keep gate open”. This presumes you cannot see open/close state.

Another option is use templat cover and add a new postion 0(closed) 50(open) 100(hold open) and use this logic to determine option in automation for auto closure.

In both cases i would notify gor hold open so i don’t accidentally leave it open unintentionally

I have physical open, close and stop buttons.
I can’t use the stop otherwise I would have to add another Shelly.
For this reason I would like to use the close.
What can I do so that when the close button is pressed the automation is canceled?

I would create a third state in UI that can be used as condition to cancel close

This is the code:

alias: Chiudi cancello automatico
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.shellyuni_e8db84d6ad7c_channel_1
    to: "on"
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.variabile_timer_chiusura_cancello
        state: "on"
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - type: turn_on
    device_id: 83b5258ca5b31c4a842bed4861114aa6
    entity_id: c24643f40d48e5dc4c376a9ee6bb718f
    domain: switch
mode: single

How should I do it?