Best way to check Zigbee lights after power outage?

After a power outage (which doesn’t happen a lot on it’s own, but could also be triggered by me), many Zigbee lights start at the “on” state. For example my Ikea Floalt. However, my HA doesn’t detect that and sees this lights as “off”.

This is annoying, because any automation to set devices to off (for example while I’m away) don’t exactly turn them off. In fact, I have to switch those lights to on and then to off again manually. Of course you always forget some, so in the evening when I enter the bedroom I’m like “hmmm, this has been on all day”. Not even wanna think about a holiday power outage.

So I’m looking for a way to detect and read the proper state after a power outage. Any ideas?
I know you can detect a power outage, but that doesn’t solve the problem of having to switch some lights “on” and then “off” again.

BTW: I’m using Zigbee2MQTT

1 Like

Does Zigbee have a polling capability?

In zwave, I poll important powered devices periodically to

A). Make sure the state is correct
B). Make sure the device is alive an able to respond.

I will check that out, good starting point. Thanks

Zignee2MQTT seems to report fine. When I unplug my Floalt panel for example and plug it back in, Zigbee reports the correct state within seconds. This is also reported back to HA.
However after a power outage, HA is restarted, building up it’s Zigbee network again and then it’s not detected by or reported to HA.
So I need a polling mechanism indeed

I think you should put your HA device on a UPS. That would go a long way to helping this issue. Also, given that your HA device is also the Zigbee coordinator part of the Zigbee network would remain intact. This is the setup I have, however, for me I have some WiFi bulbs that end up in an on state and I will need an alternative solution. I’ll be putting together a Zigbee power outage monitoring device with a door/window sensor and a relay.

I was thinking about a UPS also. Don’t like the fact that I need one for such occassions though.
And yeah I know they are especially for such occassions :sweat_smile: But just because HA (or Zigbee2MQTT) isn’t able to detect the right state after a power outage is frustrating.

Ha, yeah, and I have the same problem with my WiFi bulbs. When the power goes out they aren’t reporting back to HA that they are now on. So HA thinks they are off but they are really on. This is why my solution is going to be using my power outage detector the basically send the off/on request based on what HA reports as the state. This will effectively make sure that the bulbs are returned to the state they were as last recorded in HA.

I’m not having any troubles with my Wifi bulbs. Might be the fact that I use LocalTuya integration

My WiFi bulbs are using Meross LAN. Though it may also be partly because of some problems with how I have that integration setup. It’s a finicky one to get working and can use both HTTP & MQTT, and the MQTT only setup I’m using on my bulbs seems to be finicky, however, it may also be just the nature of the Meross bulbs not reporting their On state after a power outage via MQTT like I would expect them to. :man_shrugging:

MQTT might be the problem here, don’t know. For what I see Zigbee2MQTT picks up the correct state in seconds.
Either way, will be thinking about a UPS.

1 Like

Yep, that a good idea. At a minimum put the HA box, router / modem on it. Look for one that has a USB port as then you can get notified of the power outage, send out some texts, and the do a proper shutdown when battery reaches low threshold

1 Like

A more simple work-around would be to make a script to turn off all entities which would (hopefully) reset the to the state Home Assistant expects them to be in. In a holyday type of situation this would be difficult as you would possibly have no clue of the outage.

Unfortunately no, that doesn’t work. If I try to switch off an entity which already has the state “off” (according to HA), then nothing happens. First I have to switch it on, then I can switch it off for real.

So if we have a detection of a power outage, we can switch on all of the Zigbee lights and switch em back to off again. It would even be better to return them to the state they were, but that’s a step further.

@elstupid ugh, thanks for confirming this. My hope with with using power outage detection was that I was going to be able to do a simple call to turn the lights off, assuming that it would send the request regardless of whether HA thought they were already off. Currently, I have to quickly toggle my lights on then off to get them off and I thought maybe that was just a UI thing. :frowning:

I have an UPS which is integrated in HA via NUT, and I still get some bulbs that do not avertise their state via Zigbee on power up. It seems there is some kind of polling, or periodic push from the bulbs, because when I wait long enough at least some of them get the correct state.

Note that this is without HA nor its coordinator (under ZHA) ever stopping.

And of course, recently we had a 4-5 hours outage and my UPS is not able to last that long since both the RPi and the fiber modem are powered.

I have several Cree Zigbee bulbs that always turn themselves on after the power is restored. I use another Cree bulb in my attic as a ‘canary’ - it’s never used and always turned off, and an automation checks it every 30 minutes to confirm it’s off. If the automation determines it’s powered on it must be due to a power outage, and the automation can turn it off, as well as all the other Cree bulbs that came on after the power was restored. You could do something similar and just switch them on and off again so HA picks up the correct state.

I also have a startup automation that in addition to notifying me when HA is back up after a restart, could easily check or toggle those bulbs.

I highly recommend an inexpensive UPS (and the NUT Integration) that will power your Home Assistant, modem and router, so you can get alerts when the power is lost and gracefully shut things down. When the power goes out I still have internet for more than an hour with just a 750Va UPS.

1 Like

For now I find it totally unuseful to get myself a UPS especially for this occasion. I don’t care to get notified on power outage, I only want things to come back to a normal state afterwards.
My AH device powers up after power loss, so that’s no problem.

I thought of creating an input boolean helper, which holds the state for “Clean power Cycle”.
Home Assistant has two triggers, one at “start up” and one at “shut down” event.
My idea was to set the status to “on” (clean) at shutdown and then have an automation check the state at startup, do something when it’s “off” and when “on” set the state to “off”.

That could have been nice, but unfortunately the event “shut down” isn’t triggered at all when I restart HA (as we need to do after updates etc). So the automation is run after every restart. :zipper_mouth_face:

I’m thinking of making a feature request now, to add a trigger at “restart”

Any other ideas?

So I don’t recall if you are using ZHA or Z2M, but if you are using Z2M you could enable the Retain option that should ensure when HA starts up your ZigBee lights state is maintained. Then on startup just always go through your lights and check the light state and then just send a on & off or off & on for all the lights based on what HA thinks the state is. I know this would be extra work to have happen on a normal non-power outage startup but I don’t think it would harm anything.

One other thought, is there a restart trigger? If so just setup your logic to run on shutdown or restart.

I have Z2MQTT but can’t find an option for “retain” or something similar. Only option, and only for my Ikea Floalt device, is power on state (on/off/previous). This works fine, but that’s only one device.

There is a restart trigger as I mentioned, so I’m running checks there, but this only works reliably when you can detect there has been power loss.

The “Retain” setting is on the device itself in Z2M, right underneath the “Friendly name” field under “Settings”.