Battery-trend analysis (runtime forecast)

Hello fellow Home Automators,
i have to admit, i love statistics (who doesn’t? :slight_smile: ), but a lot more i love to deviate something out of it. I mean i’m happy, that all the battery-percentages are there on the dashboard, but it would be a lot better, if i would knew, how long my device will last (with the same amount of device load) and when i will need to act.
For instance, i got an aqara sensor in my fridge, which monitors temperature and humidity. The cold obviously degraded the battery charge, so it now resides at 90% or sth (after two weeks) but stays steady at it. Okay that’s fine, but if it like looses 1% each and every week, right now i’ve to compare those values or actively look at the graph (which isn’t stored for too long in the current db).

If there would be something written like “estimated 4 months left of the battery charge”, that would be awesome (sensor load of those aqaras are usually pretty consistent) I would get some CR3032-cells about 1 month before the battery will run out (automation!) and be prepared.
Also, i got a handy automation, which will tell my wife and me via telegram, when the battery charge of our main mobile phones is running low. Why the both of us? So we can charge each other phones in case of need, so at least someone is thinking about it. But it would be a lot better, if Home Assistant would tell me “dear chris, your wifes mobile is running out of juice in about 4 hours (estimated)”.

Has anyone created such a handy automation/trend sensor yet and if, please please share the code, how to accomplish that? trend-sensors so far didn’t help me with that, as i don’t want true of false states but more like values (4% battery charge lost in the past hour).

Edit: Oh, i got another use case for it: Motion frequency - I would like to measure how often motion happened in the past hour and if the frequency increases. As far as i know sleep sensors work like that to interprete if the person slept well (with weight sensors). I think there might be more use cases for a trend analysis like that…(stock markets, et cetera)

Thanks in advance!
Chris

1 Like

Two options:

  1. Simple: create an automation that alerts you to buy more batteries when the battery level falls below 33% (or whatever).
  2. Complicated: create a template sensor that estimates the time left and alerts you when this is only a week/month/whatever.

I really don’t see the advantage of option 2 over 1, especially as option 2 will only be an estimate.

I use the first approach, warning me at 25%, 10% and 5% battery. That works well enough for me.

Out of interest, what does the ‘SENDME’ mean in all your notifications?

message: "SENDME ...

For the record, I’d like Option 1, as well.

I already have a battery card in Lovelace, so I can keep an eye on it and start thinking about replacing the ones which are getting low.

But I really have no clue how long I have until then, or how long an average battery lasts. I don’t even know how many it makes sense to buy at a time, so I’ll have some number of months’ supply.

Now, I could do something like write down on a piece of paper each time I change each battery, and type all that into a spreadsheet, and do some analysis.

But, isn’t that the kind of thing we have HA for?

If you want to do it you could try this:

Set up a statistics sensor for the battery charge sensor. It has a change rate attribute.

Set up a template sensor that divides the charge by the change rate and you will have an estimate of the time remaining.

charge / ( charge / time ) = time

At least that’s the theory. In practice it has problems.

The change rate will be very, very slow so your statistics sensor needs to gather samples for a very long time and keep a very high number of samples. Weeks worth of data probably. This will use a lot of memory.

Just use the % charge automations we mentioned above and let home assistant watch it for you. It will let you know when the level is getting low.

I use a file notifier with those, so those messages starting SEND<something> get written there. I then have swatchdog running on the host, watching that file, and parsing the output. Depending on the <something> it’ll send a notification to the relevant destination. The script can use HA cli to get information from HA to make decisions about how to notify.

Basically, it gives me smart adaptive notifications.

No wonder I couldn’t find how you were doing this in your config.

Exactly! Me too…

Good point - I’ll add a summary to my README files :man_facepalming: