Tasmota detached switch with connectivity failure fallback

I have a number of Shelly 1 devices flashed with Tasmota that I have been running in a detached switch mode (SetOption114 1) as their relay is connected to a smart light/fan.

I get occasional wifi/mqtt drop outs and want the wall switches to work even if the network or MQTT broker drops out. Having a non functional wall switch is simply unacceptable.

Whilst there are other topics that tangentially cover this, I thought I would share to see whether my set up can be improved, or help someone else out.

In order to prevent the switch doing nothing, I have rule configured on within tasmota to disable detached switch mode (SetOption114 0) should connectivity be lost for any reason.
This was causing issue in Home Assistant as it would mean that the switch sensor detected for the tasmota devices (available when SetOption114 1 and SwitchMode 1 are set) would occasionally disappear, taking my automations based on switch state changes with it.
I was also getting issues where on reconnection, the switch state would change from undefined to its actual value and trigger automations within Home Assistant.

My solution to this is:

  • SetOption114 1
    • Detached switch mode
  • SwitchMode1 0
    • Set switch to toggle mode (0 = TOGGLE , 1 = TOGGLE ).
  • Rule1 on Wifi#Disconnected do SetOption114 0 endon on Mqtt#Disconnected do SetOption114 0 endon on Mqtt#Disconnected do MqttRetry 10 endon on Mqtt#Connected do SetOption114 1 endon
    • Disable detached switch mode on wifi/mqtt disconnect and re-enable on reconnect.

Within Home Assistant, I no longer have a sensor for the switches. I simply need to add automations that listen for the TOGGLE event and act accordingly.

trigger:
  - platform: mqtt
    topic: stat/<tasmota devicename>/RESULT
    payload: "{\"Switch1\":{\"Action\":\"TOGGLE\"}}"

I’ve been happy with reliability of this set up so far.