Took me a while to get this right so maybe this will help someone else. I was having issues with the relay opening then closing the door right away if the mqtt broker was down.
Assuming that you are using a Sonoff SV with switch1 as your door status:
PulseTime 7
Switchmode1 1
PowerOnState 0
Rule1 on switch1#state do publish stat/garage/switch %value% endon
Rule1 1
You could probably benefit from doing publish2 stat/garage/switch %value% so that the status of the garage door is retained. Otherwise, if you restart HA while the door is open, it’ll show up as closed when it comes back online. In general, you want to retain statuses, but not commands.
I tihnk we have almost identical setups for our garage doors. The only other thing I’ve done is wrap the MQTT garage door in a template one so that I can’t accidentally send the close command twice and have it stay open: