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?
You don’t. If they don’t have power, they drop from the network or mesh.
This is why they make “Smart” Switches, which is probably more why you want instead of individual bulbs maybe.
If they don’t have power, they drop from the network or mesh.
That’s the problem, they don’t drop, the entity remains in a zombie state. Is there really no way to test if a device is still connected or not?
EDIT: Or just manually set an entity to “off”?
You can decrease the timeout of the devices to maybe get them to show as offline faster. Thread about it here.
The right answer: enable the online/offline detection in zigbee2mqtt. I forget the name of the setting though (edit: it’s called availability). This might increase power consumption on some battery devices. You can then check if devices are available in your scripts and ignore their state if not.
It has a delay until offline state is detected, the delay can be tweaked as far as I know, but is a tradeoff with battery powered devices consumption.
If they’re powered off shouldn’t they be listed as unavailable/unknown?
Disable or remove the lamp switches. Add more smart buttons if there is a need for a physical control near the lamp.
As it happens I’m actually looking for a smart lamp switch if anyone knows of any options.
As it happens I’m actually looking for a smart lamp switch if anyone knows of any options
I was doing the same myself earlier this year. I’d found a European product that was an inline smart switch, like one of those rocker switches they put on the wire for those decorative canister uplights. The switches were out of stock on all the sites that listed it, and the manufacturer website didn’t seem to indicate they’d be producing more any time soon.
Eventually I just settled on using an inexpensive smart button (Tuya TS0041/TZ300 over ZHA) to control a smart bulb or a smart plug on the “dumb” fixtures. It wasn’t exactly what I wanted, but nobody seems to make a smart inline switch anymore. As a bonus, the switch supports double-tap and long press gestures so I was able to program the bedside button with a few functions to toggle the bedside lamp on a short press, and turn off all the lights in the house on a double tap.
It uses a coin battery that lasts a few months. I think I’ve changed it maybe once since I got it.
So far the only inline option I’ve found is this dimmable switch from Samotech. I haven’t tried one yet myself, and there’s mixed reviews online. For the lamps I have I only want an on-off switch though, not a dimmer.
Making due with plugging them into smart plugs for now, but an inline option would be much neater.
They should just enable offline/online detection (edit: the z2m setting is called availability)
I’d say it’s always best to avoid Zigbee devices going offline, its neither convenient for automation or good for the mesh for devices to keep dropping.
This might be true for the majority of cases, but it really depends on your mesh network, what devices drop and your needs. It works perfectly in my case.
I would instead remove the lights from the button script’s condition. If it checks for the “All Lights” group, you can remove those lamps from the group.




