Home assistant as master for switch

Hello,

I tried to find an answer into the community but I cannot find it. I have some mqtt switch switch devices connected to HA, my setup is working fine, but when the devices reboots (power outage) they took a default state (off).

I would like that HA act as a master, when it see that the state changed of a managed device it automatically set it again to the state saved in HA (if it was on I would like to have on again or viceversa). Like if HA has the priority to these devices.

I think that is feasible with variables etc, but I would like to know if there is a simple way to do that.

Thank you in advance.

inode

That is really the job of the firmware in the mqtt client.

Tasmota flashed sonoff switches?
From the Console, for each switch,

SwitchRetain 0
ButtonRetain 0
PowerOnState 3
PowerRetain 1

here a automation that I have that run when HA start

- alias: "Tasmota State on HA Restart"
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: mqtt.publish
      data:
        topic: "cmnd/sonoffs/backlog"
        payload: "power1 ;power2 ;power3 ;power4 ;power5; dimmer; state "

this just send a Backlog to the sonoffs ( Group Topic )

the thanks goes to digiblurDIY watch his channel

First of all thank you for your help.

The devices are some camera with switches (https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks/) it seems that the firmware doesn’t download the state from mqtt at the startup, it just set again the switch from a default state.

@myle your case is when HA start, I would like that action when the device restart.

Any other idea?

1 Like

Is the status of the switch itself correct? ie if it was on when it rebooted is it still physically on?

I have a dafang-hacks flashed camera, which particular switch is wrong on reboot?

When rebooted the device reset all the states and send to the mqtt with the new state.

Infrared settings, motion etc. All the switchs mainly.