Restore state of Xiaomi switch after restart

Hi all,

Currently I have multiple xiaomi wall switches installed. When the switch is on and I restarted home assistance, the state of the switch becomes off.

May I know is there any settings that can be applied to keep the state after home assistant restart?

Thanks!

Mine don’t do this. How are they configured? Mine are using the China Server and it maintains the state and in HA they show correctly across restarts. Even if I turn switch on or off HA immediately knows and shows the changed state. Same with the Yeelights on Singapore Server.

@hktomy, @DavidFW1960, which switch version are you using - with neutra line or without it?
I’ve raised similar question here Aqara/Xiaomi double wall switch (with neutral) state lost after HA restart

I.e. in my case the switch with no N line works fine and with N line doesn’t restore state :frowning:

I might have misunderstood - mine are just WiFi switches/plug s that I plug other devices into…

@kostya you are correct! It works for those with no N line and doesn’t work with those with N line, which most of my switches are in that type … thanks for that!

I wonder why no one complained about it before (or my search skill aren’t that good:)) I would’ve just bought only the non-N line versions.

What I’m thinking to do now is to try to set up simple automations to work around that “situation”:

  • add an input Boolean component per switch and create automation to mimic status of the switch (status update works fine for me, only the init state is always off)
  • Input Boolean does preserve its state after restart
  • add an automation that runs once upon hass startup to restore switch status from the input Boolean value

I haven’t tested that and a bit worried if the second automation mike cause a loop, will try to test that later tonight.

Quick update: the hack described above works! it might be one of the dirtiest hacks but it does work for me :slight_smile:
It won’t cover cases when someone changes switch state while HASS is down but it is better than nothing :slight_smile:

1 Like