I have a button that triggers a script for bedtime to turn off all lights, and, if pressed again, checks to see if all lights are off and if so, turns a few (like the bathroom light) on.
My problem is one or two of the lights (connected via Zigbee2Mqtt) are often powered off at the switch on the lamp, meaning HA still sees them as “on” until the power is restored and they can be turned “off” via the app. The lights cannot be turned “off” (in HA) manually.
Is there any good solution for detecting when a light goes missing and turning it “off” in HA?


Helpful! Thank you I will look into it.
To add, I found some old Philips switches might have reacted badly to this, because they drained battery super fast afterwards. Like a month or two. I switched them all to cheap Ikea switches which work as usual and drain very slowly. All working nicely and I can make toggle buttons work like you described even if some lights are cut off from power.
But yeah there might be problems with certain devices and drain.