ESPhome - turn off after 2-4 sec

Hi,

I’m trying to configure my doorbell incl. electric door opener. I’m using a 2-channel relay and I can open my door but I want it to stop the switch after 2-4 sec, otherwise it keeps the door open. I tried a bunce of delay/toggle options but I can’t seem to turn the relay switch off automaticly. Can someone point me in to the right direction?

This is my current code:

  - platform: gpio
    id: buttonBuzz
    name: Door Open Button
    pin:
      # Connected to GPIO on the ESP-01S.
      number: GPIO2
      mode: INPUT_PULLUP
      inverted: true
    filters:
      # Small filter, to debounce the button press.
      - delayed_on: 25ms
      - delayed_off: 25ms
    on_press:
      - switch.turn_on: relay2
      - delay: 1s
      - switch.turn_off: relay2
    # on_release:
    #   - delay: 1s
    #   - switch.turn_off: relay2

Try this:

  - platform: gpio
    id: buttonBuzz
     pin:
      # Connected to GPIO on the ESP-01S.
      number: GPIO2
      mode: INPUT_PULLUP
      inverted: true
  - platform: template
    name: Door Open Button
    icon: "mdi:gate"
    turn_on_action:
    - switch.turn_on: buttonBuzz
    - delay: 1s
    - switch.turn_off: buttonBuzz
1 Like