Simple tasmota garage door switch separate from relay

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


  • platform: mqtt
    name: “Garage”
    state_topic: “stat/garage/switch”
    command_topic: “cmnd/garage/POWER”
    payload_open: “ON”
    payload_close: “ON”
    payload_stop: “ON”
    state_open: “1”
    state_closed: “0”

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:

  - platform: mqtt
    name: garagedoor_mqtt
    command_topic: cmnd/NodeMCU02/POWER
    payload_open: 'ON'
    payload_close: 'ON'
    payload_stop: 'ON'
    state_topic: stat/NodeMCU02/POWER2
    state_open: 'ON'
    state_closed: 'OFF'
    optimistic: false
    retain: false
    availability_topic: tele/NodeMCU02/LWT
    payload_available: 'Online'
    payload_not_available: 'Offline'

  - platform: template
        friendly_name: Garage Door
        value_template: '{{ is_state("cover.garagedoor_mqtt", "open") }}'
          - condition: state
            entity_id: cover.garagedoor_mqtt
            state: 'closed'
          - service: cover.open_cover
            entity_id: cover.garagedoor_mqtt
          - condition: state
            entity_id: cover.garagedoor_mqtt
            state: 'open'
          - service: cover.close_cover
            entity_id: cover.garagedoor_mqtt

Thanks for the tip on using publish2, was wondering how to get that working.