Creating a Button with a Shelly Relay

I have a garage opener that requires a short ‘press’ to activate it.

My current ESPHome config I always felt was a bit of a hack. How do I convert this into a ‘Button’?

switch:
  - platform: gpio
    pin: GPIO4
    name: "Garage Door 1 Relay"
    id: relay
    restore_mode: ALWAYS_OFF
    internal: true
  - platform: template
    name: "Garage Door 1"
    icon: "mdi:gate"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 500ms
    - switch.turn_off: relay

Do I need the 2 parts?

I think this should work

switch:
  - platform: gpio
    pin: GPIO4
    name: "Garage Door 1 Relay"
    id: relay
    restore_mode: ALWAYS_OFF
    internal: true

button:
  - platform: template
    name: "Garage Door 1"
    icon: "mdi:gate"
    on_press:
    - switch.turn_on: relay
    - delay: 500ms
    - switch.turn_off: relay

Thanks, I’ll give it a go…

[edit]
@jsuanet perfect - many thanks :grinning: