[Question] How to force the state of each devices after a power failure?

Tags: #<Tag:0x00007f32819bb058> #<Tag:0x00007f32819baf68> #<Tag:0x00007f32819bae28> #<Tag:0x00007f32819bad60>

Hi

I don’t know if I’m a nooby with that but today, I got a power failure at (3:00 AM) and power come back just after.

My NUC had restart directly after the power come back . 3 minutes later, it was operational (so MQTT broker, Z2M and HA was started)

I set Z2M with retain: true attribute, so it send the last state that it known.
When Z2M restarted, I saw this line for each device:

`zigbee2mqtt    | Zigbee2MQTT:info  2020-11-20 23:36:15: MQTT publish: topic 'zigbee2mqtt/switch_spots_kitchen', payload '{"state":"OFF"}'`
zigbee2mqtt    | Zigbee2MQTT:info  2020-11-20 23:36:15: MQTT publish: topic 'zigbee2mqtt/gledopto_2_bathroom', payload '{"brightness":132,"color":{"x":0.453,"y":0.432},"color_temp":375,"state":"OFF"}'

So it send the last state, perfect.

However, HA doesn’t seems to care about it (no new state in the historic view) and HA said that each bulbs are still “OFF” but it’s not true. Each light in my house are on “ON” after the power come back again …
It’s a little bit a problem ( specially in the middle of the night). I would have HA send the last state on the bulbs when he stars again.

Is it possible ? I hope so because where I live, it happens one time by week sometimes more (the power failure is often only 3 seconds) :confused:

Thank you in advance

This isnt a direct answer to your question, however if power failures are that common of an occurrence, you really should be looking into a small UPS for your NUC.
Not only to possibly prevent this issue, but because computers being hard shutdown due to a power cut is a very common way to corrupt the OS or damage the data on-disk.

You’re right :slight_smile: However, indeed my problem stay the same. I should have specified that it’s temporary. But the energy company in my country decided to do some works on the electric lines and maybe during one month that could happens… That’s why I didn’t see this problem before until to have some power down but yes that’s a little bit frustrating for my poor NUC. For the moment it survived but if it’s happens to often I will use a UPS :wink:

However, your answer gives me an idea how to workaround it if no one here has idea about my question.

If I buy an UPS (as you said, I will maybe save the life of my computer but also I could have the information about battery / AC power mode of the UPS and using it as trigger to say from battery_mode to ac_mode, if no motion_detected go switch off lights in this room ect otherwise do not nothing because someone is in this room :slight_smile:

It’s the best idea that I have in mind for the moment.