End of run switches via esphome

hi,
i’m trying to build a chicken door via esphome.
components:
*an old 5V motor (no step) runs vorwards or backwards depending the polarity
*a relay board to change the polarity
*2 end of run switches to determine te end position of the door (open or closed)
*come assistant with a schutter-card

is there a way, when pushed in HA, to activate a relay until the end of run switch changes status? and preferabely directly in esphome?
thanks in advance!

my code:

...
binary_sensor:
  - platform: gpio
    device_class: door
    id: door_open
    name: "door_open"
    pin:
      number: 14
      mode: INPUT_PULLUP

binary_sensor:
  - platform: gpio
    device_class: door
    id: door_open
    name: "door_closed"
    pin:
      number: 12
      mode: INPUT_PULLUP

switch:
  - platform: gpio
    pin: 5
    id: relay1
    name: "kippen dicht 1"
    inverted: True
    restore_mode: ALWAYS_OFF
  

  - platform: gpio
    pin: 4
    id: relay2
    name: "kippen dicht 2"
    inverted: True
    restore_mode: ALWAYS_OFF


  - platform: gpio
    pin: 0
    id: relay3
    name: "kippen open 1"
    inverted: True
    restore_mode: ALWAYS_OFF
   

  - platform: gpio
    pin: 2
    id: relay4
    name: "kippen open 2"
    inverted: True
    restore_mode: ALWAYS_OFF


cover:
  - platform: template
    name: "kippenhok"
    open_action:
    - if:
       condition:
         binary_sensor.is_on: door_open
       then:
         - switch.turn_on: relay1
         - switch.turn_on: relay2
    close_action:
      - switch.turn_on: relay3
      - switch.turn_on: relay4
    stop_action:
      - switch.turn_off: relay1
      - switch.turn_off: relay2
      - switch.turn_off: relay3
      - switch.turn_off: relay4
    optimistic: true

Have you tried an Endstop Cover instead of a Template cover?

1 Like