I have a few Zigbee smart bulbs which are also connected to smart wall switches. When the switch is turned off, the bulb in HA still shows as on. I’ve turned on availability in Z2M and they show offline but HA still keeps the last know state.
How could I resolve this? An automation that sets the state when the switch is off?
This isn’t what you want to hear - but, besides the difficulties you’re already having with entity state - you also will cause a lot of other issues you’re not thinking about.
You resolve this issue by taking the smart bulbs off of smart switches and/or never turning the power off at the line.
Reasons:
The obvious, when power is off at the switch nothing works. - But you know this already. and why you’re asking about state.
If those aren’t Sengled bulbs (and ARE acting as Zigbee repeating devices - Sengled bulbs specifically do not setup their bulbs as repeaters) then every time you kill power to that switch you are negatively impacting your Zigbee repeating mesh. (Having Zigbee problems elsewhere for no apparent reason? This is why.)
There’s a tiny but real possibility flipping power to these bulbs can corrupt the bulb themselves. Smartbulbs weren’t meant to be turned on and off at power on a regular basis. Personally, I don’t consider this one an issue, but I include it for completeness.
Even more so if there are little kids around that like flipping lights on and off. Kids will find a way of initiating a reset no matter how obscure the on-off pattern is.
This is because of how I built out the house, and lack of knowledge at the time. I bought Hue bulbs to work with Alexa to start. I liked the ability to dim them (i.e. 25% for kids bed time). Then the kids started toggling the switch to reset the brightness (and not sleep), so I put in smart switches for on/off and only use the bulbs for dimming.
I don’t have a huge zigbee network, so I’m not seeing problems, but I get your point.
I haven’t has the bulbs reset (yet), but I wouldn’t put it past my kids.
Right now, this is not a huge problem, it just shows as a light this is on in the house, even though it’s not really on. I don’t think I can intercept the physical button and stop it from turning off, so at best I think I could quickly turn it back on then dim the bulb, but I have a feeling the delay between those actions will cause more harm than good. Likely someone will hit the switch off, see it come back on, then try to turn it off again, creating a bit of a loop.
If you’re in the states, look at switches by Zooz or Innovelli (there are a few others…) you’re looking for a switch that supports ‘smart bulb mode’
In essence, a switch that supports thiscan be configured to act as a scene controller and NOT kill power to the load. Then you can use the ‘switch’ like a scene controller to automate the lights.
I did find that by default Z2M doesn’t send device availability to the correct topic. You need to disable legacy_availability_payload in the configuration, which I could not find in the Settings UI. Now the bulbs show as unknown which is a little better than on IMO.