MQTT switch set value when offline

Hello community,

this is my first post, so please appologise me, if i made something wrong :wink:

i’m searching for a solution to toggle a MQTT (to be more detailed a Tasmota relay) device to “off” or “on” even when they are offline.

The MQTT device will be powered by a ordonary lightswitch and will be powered off in the evening and powered on every morning. I have automations to switch this Tasmota switch to Off/On by several conditions whitch can happen even when the Switch is offline and should happen when the Switch becomes online again.

the Tasmota relay is “on” and will be powered off by the lightswitch. Meanwhile the Tasmota is offline, the condition changes and the automation should change him to “off”. When power comes back the Tasmota should change to “off”. Normally the last state (on/off) of the Relay will be set when the Tasmota gets power again.

Is there any simple solution for this?

Thanks and greetings from Germany!


That’s an interesting requirement. I have never tried this so what I’m proposing may not work. Try creating an automation with a State Trigger like this:

- alias: test 1
    platform: state
    entity_id: switch.my_switch
    from: 'offline'
    service: switch.turn_off
    entity_id: switch.my_switch

It is triggered when the switch’s state changes from offline to anything else.