Restore last known state for battery sensors (instead of 'unavailable')

Many times in the past, I had to troubleshoot zigbee devices that went unavailable. But I don’t want to make this thread specifically tied to zigbee because my point applies to other cases as well.

When we have battery sensors, I would like their state to be restored instead of them being unavailable.
So I can tell what was their last state, (useful information).
This way I can tell apart if a device is unavailable because its last battery state is 0%, versus an unavailable device with good batteries, and unavailable for other reasons (network,pairing,configuration issues etc).

So what you are saying is that when it is unavailable you are unable to take whatever action is necessary to make it available again (such as reloading the integration or loking at the sensor to resolve whatever the issue is)? I guess maybe this is the ame question but… There are ways to store the state whenever it changes (such as in a helper) so that you can refer to that when the sensor becomes unavailable to see the previous state - but when it does become unavailable - my reaction is to go resolve the issue instead and try to see what I can do to stop it from recurring - wouldn’t that be your action…?

Thanks for the reply and participation.
Well, some extra details:
Physically going to the sensor and resolving it (rewaking it/ repairing/ finding out the battery is good or not, then replace it if its the case) is obvisously an action to be taken.

However my point is discussing how HA could be better.
And restoring states is already a thing for some integrations. If it was chosen and coded to be.

I have 30+ zigbee battery based devices in my system. Some has a seasonal importance. I care about them more or less depending on the time of year, or don’t care at all for a time period. Also I’m prety active at improving my HA setup and I’ve being doing that for since HA 0.64, a while ago, so restarts, and reshufling things around is frequent.

All that means that with time you lose the perfectionism trait of having everything perfectly paired and working 100% all the time. Busy life.

I do restart my system often (mostly due to hacs integration updates). And also ZigBee ZHA has its share of blame to losing devices pairing from time to time.

So I’m not always sure what portion of the devices I do need to replace batteries vs just repair. ( I know, eventually I’ll have to check each one anyways one by one, physically).

But the knowledge on the state of the battery still stands.

I thought about creating a whole convoluted way of storing the information using extra helpers, automations, etc, but, but that is just a workaround of something that could be simpler. I might still do it anyways.

It’s not only zigbee devices, but I have a bunch of phones, regular tablets, kids tablets and wall mounted tablets that would benefit from that battery information sticking around on the state machine surviving HA reboots.

1 Like

May be better to replace before the device goes unavailable. Battery Notes helps a lot with battery management.

https://andrew-codechimp.github.io/HA-Battery-Notes/

I use Variables+History to save the last state of motion sensors (for tracking purposes).

Setting it up for every battery device would be quite a big job, though.

I also have 30-odd battery Zigbee devices and I have to say that I can’t remember the last time one of them went unavailable, other than immediately after a restart (which is normal). As @KruseLuds says, your time might be better spent finding out why yours do.

I bit the bullet and manually added everything into a UI-Minimalist dashboard which I would rather be able to scroll through all of them and the ones that get down to 50% or 25% I just gernerally go replace them once or twice a month. Once I get a new one to add - it’s not a big deal adding just one - so I am good to go. It also shows at a glance if any of them are therefore offline as well. Rather than a notification or view of just those needing attention it does add a bit of comfort knowing the state of all of them, good or not, at a glance. Yes this scrolls endlessly - I have maybe 100 of them lol - but once set up, you can scroll through and just see the state of everything