Automation for Switch Gate

I am trying to create an automation to keep my gate open for a longer period of time.

Background: I have a gate opener that closes automatically after 120seconds (no way to turn it off). I have a UBNT mPort connected to it, and the mPort acts as switch on both the HomeAssistant AND Alexa. the mPort is pretty much a relay in a sense, but because it is a switch on the interface, I have to keep turning it on, and then turning the “switch” off. If I leave the switch “on” it wont have any affect as to how long the gate stays open, but regardless if i want to open the gate again i have to ensure it is off and then turn it on to give the power for the relay to run the gate opening circuit.

Bottom line: I want to set up a automation where if I press a button or tell alexa to “turn on Open Gate”, it will turn the gate “switch” on, off, and on again. This way the gate stays open without it closing automatically after 120s.

I am lost as to what I put for my trigger mostly.

The entity id is switch.gate for me.

Create an input_boolean.
All we need it for is to trigger the automation.
This should be pretty close:

input_boolean:
  igate:
    name: gate
automation:
  alias: Open Gate
  trigger:
    - platform: state
      entity_id: input_boolean.igate
      to: 'on'
  action:
    service: homeassistant.turn_on
    entity_id: script.scrOpenGate
script:
  scrOpenGate:
    alias: "Keep the gate open"
    sequence:
      - service: switch.turn_on
        data:
           entity_id: switch.gate
      - delay:
          seconds: 1        
      - service: switch.turn_off
        data:
           entity_id: switch.gate
      - delay:
          seconds: 1        
      - service: switch.turn_on
        data:
           entity_id: switch.gate
      - service: input_boolean.turn_off
        data:
           entity_id: input_boolean.igate

Hi @treno, I did set up the scripts and booleans like you stated, now the only problem is that the automation on the frontend shows up as a toggle thats on, and me pressing it on or off does nothing unless I actually press the word “trigger”.

How could I make it so that the automation runs when I press the on/off toggle, and once it is done, the toggle reverts to the off position?

Remove the automation from the UI and only put the input_boolean “igate” in the UI.