Calculate battery remaining as hours

934 views
Skip to first unread message

Mark

unread,
Nov 12, 2011, 4:27:39 PM11/12/11
to tas...@googlegroups.com
Just been trying to get to grips with tasker, it looks amazing!  

One quick question I have is, how do I calculate in hours the remaining for my battery.  I'm looking for something to display like this on my wallpaper:

"43% you have 17hours remaining "

I can get the 43% bit working but I'm not sure how to work out the calculation for hours remaining.
Once I have this the next thing will be, when I plug the phone in I want to know how long it will be until it's 100% charged.

Rick Nyman

unread,
Nov 13, 2011, 12:10:58 AM11/13/11
to Tasker
If you check battery at intervals, you can calculate how fast the
battery is draining and use that to generate your estimate.

I've had mixed results with this (I get very different results based
on which time periods I use data from).

Rick

Matthieu Berthomé

unread,
Nov 13, 2011, 7:40:30 AM11/13/11
to tas...@googlegroups.com
Your best bet for that kind of thing would be a linear interpolation from a set of data. Like Rick said,"log" the batteryvalue. Push all the values in an array, so you have, like, 5 values prior to the instant you're looking at. Then, calculate a regression line using the formula http://en.wikipedia.org/wiki/Simple_linear_regression#Fitting_the_regression_line. Then calculate the intercept, where the line gets to 0. Some phones go to sleep when the battery is at 0,5 or even 15 %. It depends on the calibration, etc, so take what is the lowest bound for your phone. You'd have to take into account the possibility of upwad trend (charging), and probably reset the array as soon as the phone is unplugged from charging.
I've done a similar profile, so if you want mine or if you want more help to do that, tell me

Another option is having a dedicated app do that (I've used battery diviner), which might be more powerful (can adapt depending on your usual schedule), and get the value from the app, by shamelessly getting it from it's sqlite database maybe. Depends if you're rooted or not.

Mark Darwin

unread,
Nov 13, 2011, 5:01:43 PM11/13/11
to tas...@googlegroups.com
Thanks guys for your input.  I do a good amount of scripting at work but as this is literally my 3rd profile if I could get a copy of yours Matthieu I think it sounds complex enough that I should be able to learn a few different functions in one go.  Hoping that this way  I can pull apart a few tasks and quickly get to grips with how it all works.

Matthieu, my phones are rooted so I can hack around with them until my hearts content :)


Mark

Matthieu Berthomé

unread,
Nov 14, 2011, 2:32:56 PM11/14/11
to tas...@googlegroups.com
Sheesh, I have over estimated myself. I've lost the task I did (it was a long time ago :-S). Can't help you with my own stuff. As an exercise I'll try to re-do it, maybe use the new features like array in the meantime ;-) But try to go about logging the %BATT and %TIME values, and do a linear regression future trend. Some maths needed, but should be doable.

So, you're rooted: Try to look into "battery diviner" or "battery monitor" apps. Most of them have some kind of "predictor". Once you have them, try to look into their sqlite databases in /data/data/nameoftheapp and see if you can catch the value of the time left for the battery. I have battery monitor widget, in the file /data/data/ccc71.bmw/shared_prefs/ccc71.bmw_preferences.xml there is a lot of data, notably "dataEstimates" which might be the value you're looking for.

Mark

unread,
Nov 15, 2011, 5:09:06 AM11/15/11
to tas...@googlegroups.com
Thanks Matthieu.  When I'm finished my current project I'll dig around on this and report back my findings.
Reply all
Reply to author
Forward
0 new messages