@mikeycv, I recommend you use the code that @NeilDuToit92 shared on github. The code I posted at the top was a proof of concept to show that you could use two reed switches to get the state of the door fully opened or fully closed and represent it with an ESPHome cover.
The code on github is full blown and works better (because the correct state of the door is realized on boot). Anyway, you can see in that code where the reference to the relay exists starting on line 31:
switch:
# The switch that turns the UP direction on
- platform: gpio
pin: D1
id: garage_switch
# If ESP reboots, do not attempt to restore switch state
restore_mode: ALWAYS_OFF
on_turn_on:
- delay: 500ms
- switch.turn_off: garage_switch
I have three garage doors and two of them use button technology that isn’t easily manipulated (cannot just short the pins to trigger a button press event). I found this awesome post from @TaperCrimp which explains how to wire in a garage door opener remote control.
I then created three separate units:
- one that handles it’s own button and door state (fully self contained)
- one that watches its door state and has the remote wired in with two relays for hitting two of the buttons, it publishes a service to Home Assistant for pressing the button for the other garage door
- the last one that just monitors state, it has a
template
switch on it that calls a Home Assistant service to press the button on the other device.
It seems a little janky when you think about the process but in reality it’s completely transparent and the interface works like you’d expect.