battery life
Moderator: Martin
battery life
Hi
has someone built a flow to calculate the residual autonomy (hours and minutes) of the battery?
I can not find the right way.
thank you
has someone built a flow to calculate the residual autonomy (hours and minutes) of the battery?
I can not find the right way.
thank you
Xiaomi MI 6
Rom Miui 10 EU STABLE
Rom Miui 10 EU STABLE
 digitalstone
 Posts: 338
 Joined: 21 Oct 2017 12:36
 Location: The Netherlands
Re: battery life
I made one myself a long time ago, but it turns out that my formula is pretty flimsy.
I made it in the sense of:
Total_batt_capacity * batt% / batt_using_current
It spits out answers like: 109 minutes left.
While in fact should be 5 hours.
I would like to know this as well.
I made it in the sense of:
Total_batt_capacity * batt% / batt_using_current
It spits out answers like: 109 minutes left.
While in fact should be 5 hours.
I would like to know this as well.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)
Re: battery life
Thank you for your answer
What you mean with "Total_batt_capacity" and "batt_using_current"
where you got values ?
thank you
What you mean with "Total_batt_capacity" and "batt_using_current"
where you got values ?
thank you
Xiaomi MI 6
Rom Miui 10 EU STABLE
Rom Miui 10 EU STABLE
 digitalstone
 Posts: 338
 Joined: 21 Oct 2017 12:36
 Location: The Netherlands
Re: battery life
Well, the general formula with chargingtime of batteries is that you take the total battery capacity, and divide that with the charging amps per given time.
So let's say that you have a battery of 2400mA, and your charger's output power is 1A (1000mA).
2400mA / 1000mA = 2.4 hours
In this case, the same method reversed can be used with discharging time (using examplevalues):
battery_total_capacity * battery_percentage / currentNow = 2400mA * 50% / 230mA = 5.2 hours
Despite this is just the general formula, there are some values that have to be added in to make it work like, multiplying by 1000 to converting microAmpere to miliAmpere... and so on.
Either case, with me it just doesn't give the right result somehow.
Anyway, if you want to extract the values that are needed, you can use them from either trigger or condition called "Battery Level".
Look at the helpsection of that trigger/condition to see all of the variables provided.
So let's say that you have a battery of 2400mA, and your charger's output power is 1A (1000mA).
2400mA / 1000mA = 2.4 hours
In this case, the same method reversed can be used with discharging time (using examplevalues):
battery_total_capacity * battery_percentage / currentNow = 2400mA * 50% / 230mA = 5.2 hours
Despite this is just the general formula, there are some values that have to be added in to make it work like, multiplying by 1000 to converting microAmpere to miliAmpere... and so on.
Either case, with me it just doesn't give the right result somehow.
Anyway, if you want to extract the values that are needed, you can use them from either trigger or condition called "Battery Level".
Look at the helpsection of that trigger/condition to see all of the variables provided.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)
Re: battery life
The problem with calculation thru the currentNow is it fluctuate very much. Android has been designed to burst the CPU frequency in short moment to finish the task ASAP, then go to sleep or low frequency idling afterward. During the checking of the condition battery level, the current consumption will surge and give higher reading than the supposed current without the check, skewing the calculation result. Similar to observer effect in quantum mechanic.
I don't know how android calculate the current battery left time, it will be interesting to know the formula. Or at least if someone know which file to read the estimates time, screen on time, and battery usage time. (root required)
Simple manual calculation
Here is my simple guideline to interpolate the time left. I usually check my battery at certain random percentage and see the usage time and Screen On Time (SOT). If I am lazy, I simply dividing out the percentage used to the SOT and get how many percent/hour. Then use the remaining percentage to divide this percent/hour, I will get the remaining potential SOT. But for more detail, you still need to know the behaviour and basic value for your phone.
Example Case :
I use the phone until 71%, with 13 hours usage, all full wifi and have 4 hours 40 minutes SOT. My phone has 0,5%/hour on wifi idling. That means :
29% = 4 hours 40 minutes (4,66 hours) with 13 hours usage. Looking at 0,5%/hour in idle wifi connected, I would get 13 hours wifi = 0,5 x 13 = 6,5%. Leaving 29  6,5 = 22,5%. 22,5% / 4,66 hours = 4,82%/hour of SOT, round up to 5%/hour.
If I used my phone until 1%, that mean 70% can be used. Let's say I use the phone again for the next 40 hours, which will use up 0,5 x 40 = 20%. Leaving 50%. By calculating the 5%/hour, I can have another additional 10 hours SOT after this. Which mean at 71% left, I have 40 hours usage left with potential 10 hours SOT. But of course, this is estimation. It will change if I change the behaviour of using the phone, such as playing game, using it outdoor, turn on 4G, etc. In fact I ended having 50 hours usage with 13 hours SOT. It is lower (estimation should be 14 hours 40 minutes) because I use the phone outdoor (higher brightness) and 4G afterward, hence faster drain. It is a good estimation. I do this manually on mental calculation, just to get rough estimation.
Interpolation from last 5 %
Using the same interpolation method, we can estimate the battery left by interpolating the last 5 (or 10) percentage change. Because it makes sense to say "if you keep using your phone with current drain speed, you have xx hours left". So we need to log the last 5 percentage change (or 10 to be longer and less prone to surge usage) to the glovar. We only need the time and percentage, no other values needed. You can include them if you want, and do another calculation. But this method only care about the percentage change and the time it takes to have the change.
Use trigger Battery Level  lower than 100%, so it triggers at every percentage change.
 When it drop to 99%, let say in 5 minutes. Then log this to the glovar. To calculate the time left, the speed of the drain is 1% in 5 minutes. Hence 99% left is 99 / 1 x 5 = 495 minutes left (8 hours 15 minutes left).
 You don't use the phone, and after another 25 minutes (30 minutes from full), it drops to 98%. Log this to glovar, speed of drain is 2% in 30 minutes. Hence 98% left is 98 / 2 x 30 minutes = 1470 minutes (24 hours 30 minutes left)
 You use the phone, and after 10 minutes (40 minutes from full), it drops to 97%. Log, speed is 3% in 40 minutes. 97% left is 97 / 3 x 40 minutes = 1293 minutes (21 hours 33 minutes left)
 this continue until 94% and delete the first 100% data. Or better don't delete, just refer to the index 5 from the current one.
 So at 90%, you use the time from the 95%. If that 5% drain in 1 hour, then at 90% left, 90 / 5 x 1 hour = 18 hours left
This continues to take only last 5 (or last 10) data. And the flow should disabled when you charge the phone and resetted once you unplugged from the charger. So the cycle begin again. When you play game, the drain wil be much faster, let say the last 5% drain happened in 10 minutes. So with 75% left, you will only have 75 / 5 * 10 = 150 minutes = 2 hours 30 minutes. It is reasonable, since if 5% in 10 minutes, that means 30% in an hour. With 75% / 30%/hour = 2,5 hours; same result.
The above method doesn't estimate the SOT. To be more accurate, you can log the Display on/off state too. So you can estimate even the SOT and the usage time.
I don't know how android calculate the current battery left time, it will be interesting to know the formula. Or at least if someone know which file to read the estimates time, screen on time, and battery usage time. (root required)
Simple manual calculation
Here is my simple guideline to interpolate the time left. I usually check my battery at certain random percentage and see the usage time and Screen On Time (SOT). If I am lazy, I simply dividing out the percentage used to the SOT and get how many percent/hour. Then use the remaining percentage to divide this percent/hour, I will get the remaining potential SOT. But for more detail, you still need to know the behaviour and basic value for your phone.
Example Case :
I use the phone until 71%, with 13 hours usage, all full wifi and have 4 hours 40 minutes SOT. My phone has 0,5%/hour on wifi idling. That means :
29% = 4 hours 40 minutes (4,66 hours) with 13 hours usage. Looking at 0,5%/hour in idle wifi connected, I would get 13 hours wifi = 0,5 x 13 = 6,5%. Leaving 29  6,5 = 22,5%. 22,5% / 4,66 hours = 4,82%/hour of SOT, round up to 5%/hour.
If I used my phone until 1%, that mean 70% can be used. Let's say I use the phone again for the next 40 hours, which will use up 0,5 x 40 = 20%. Leaving 50%. By calculating the 5%/hour, I can have another additional 10 hours SOT after this. Which mean at 71% left, I have 40 hours usage left with potential 10 hours SOT. But of course, this is estimation. It will change if I change the behaviour of using the phone, such as playing game, using it outdoor, turn on 4G, etc. In fact I ended having 50 hours usage with 13 hours SOT. It is lower (estimation should be 14 hours 40 minutes) because I use the phone outdoor (higher brightness) and 4G afterward, hence faster drain. It is a good estimation. I do this manually on mental calculation, just to get rough estimation.
Interpolation from last 5 %
Using the same interpolation method, we can estimate the battery left by interpolating the last 5 (or 10) percentage change. Because it makes sense to say "if you keep using your phone with current drain speed, you have xx hours left". So we need to log the last 5 percentage change (or 10 to be longer and less prone to surge usage) to the glovar. We only need the time and percentage, no other values needed. You can include them if you want, and do another calculation. But this method only care about the percentage change and the time it takes to have the change.
Use trigger Battery Level  lower than 100%, so it triggers at every percentage change.
 When it drop to 99%, let say in 5 minutes. Then log this to the glovar. To calculate the time left, the speed of the drain is 1% in 5 minutes. Hence 99% left is 99 / 1 x 5 = 495 minutes left (8 hours 15 minutes left).
 You don't use the phone, and after another 25 minutes (30 minutes from full), it drops to 98%. Log this to glovar, speed of drain is 2% in 30 minutes. Hence 98% left is 98 / 2 x 30 minutes = 1470 minutes (24 hours 30 minutes left)
 You use the phone, and after 10 minutes (40 minutes from full), it drops to 97%. Log, speed is 3% in 40 minutes. 97% left is 97 / 3 x 40 minutes = 1293 minutes (21 hours 33 minutes left)
 this continue until 94% and delete the first 100% data. Or better don't delete, just refer to the index 5 from the current one.
 So at 90%, you use the time from the 95%. If that 5% drain in 1 hour, then at 90% left, 90 / 5 x 1 hour = 18 hours left
This continues to take only last 5 (or last 10) data. And the flow should disabled when you charge the phone and resetted once you unplugged from the charger. So the cycle begin again. When you play game, the drain wil be much faster, let say the last 5% drain happened in 10 minutes. So with 75% left, you will only have 75 / 5 * 10 = 150 minutes = 2 hours 30 minutes. It is reasonable, since if 5% in 10 minutes, that means 30% in an hour. With 75% / 30%/hour = 2,5 hours; same result.
The above method doesn't estimate the SOT. To be more accurate, you can log the Display on/off state too. So you can estimate even the SOT and the usage time.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: battery life
While this is still fresh in mind, I am building the flow for it. Seems challenging, have to think about a glovar maplistlist structure for it.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
 digitalstone
 Posts: 338
 Joined: 21 Oct 2017 12:36
 Location: The Netherlands
Re: battery life
*Looks at Desmanto's reply*
Man, sometimes i think you're an android. Either you have limitless motivation or just a lot of time
Man, sometimes i think you're an android. Either you have limitless motivation or just a lot of time
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)
Re: battery life
@digitalstone : depends on the question and my mood at the time, it might trigger my interest to find it out. Now this project has bloomed to a higher attention. I have tested out my simple concept, and it logs the estimation battery life quite well. But it seems android use the unplugged percentage as anchor, not like my calculation which use last 5%. But I still will use it as comparison, so 2 calculations. I have planned for more feature for the flow.
1. The main one is calculation of remaining time, 1 is based on last unplugged (it can be not 100%), another is based on last 5%.
2. I will just use widget as the information center. Every changes will be reflected to widget.
3. Add another way to show the information during charging and estimate how long until full. Show the current, time left and speed of charging (additional, show warning if charging slowly)
4. At every unplugged state, export out all battery life stat to a text file, so we can view it later. Clear up current one and start logging again as usual
5. Set up the display on/off logging and calculate the SOT too. The widget will show the remaining SOT and updated when tapped
6. Tapping part of widget will show the last battery history and charging.
7. Optional, use the battery history as the widget overlay, so we can have much better overview of the battery usage and SOT. Even using only percentage and time, we can output out so many insightful data.
Honestly, this all can be done by installing many 3rd party app. I used to install battery monitor in the past. I have just uninstalled BBS after troubleshooting is done. But all of them can't show the data I want. Some show duplicate data, some show to much data, graph can't be adjusted and some meaningful data is missing.
I still need the battery history, SOT, then projection of the remaining possible SOT.
This seems to be a 24 weeks project. I am typing out here, so I don't forget what I am going to do.
1. The main one is calculation of remaining time, 1 is based on last unplugged (it can be not 100%), another is based on last 5%.
2. I will just use widget as the information center. Every changes will be reflected to widget.
3. Add another way to show the information during charging and estimate how long until full. Show the current, time left and speed of charging (additional, show warning if charging slowly)
4. At every unplugged state, export out all battery life stat to a text file, so we can view it later. Clear up current one and start logging again as usual
5. Set up the display on/off logging and calculate the SOT too. The widget will show the remaining SOT and updated when tapped
6. Tapping part of widget will show the last battery history and charging.
7. Optional, use the battery history as the widget overlay, so we can have much better overview of the battery usage and SOT. Even using only percentage and time, we can output out so many insightful data.
Honestly, this all can be done by installing many 3rd party app. I used to install battery monitor in the past. I have just uninstalled BBS after troubleshooting is done. But all of them can't show the data I want. Some show duplicate data, some show to much data, graph can't be adjusted and some meaningful data is missing.
I still need the battery history, SOT, then projection of the remaining possible SOT.
This seems to be a 24 weeks project. I am typing out here, so I don't forget what I am going to do.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: battery life
I'm using a simple flow that logs the time between display on and display off. So I already have the SOT.
On the widget (see the screenshot) I display from bottom to top the SOT, the battery drain in percent per hour, the time since the last charge and the estimated time until the battery is empty.
To calculate the estimated time I simply take the time since the last charge and the lost percentage since the last charge. For example, if it took 10 hours to go from 100% to 50% then the estimated time until 0% is 10 hours. So I don't take the SOT into account.
Interestingly, the battery statistics in the android settings show almost the same values. Check the screenshots. My widget shows 1 day and 1 hour left and 3 hours SOT. And the battery statistic shows 1 day and 1 hour left and 2 hours 54 minutes SOT. The time since the last charge is rounded to 3 days in the battery statistics and 2 days 18 hours in my widget.
I haven't compared those values before, so I don't know if they are almost the same by coincidence.
On the widget (see the screenshot) I display from bottom to top the SOT, the battery drain in percent per hour, the time since the last charge and the estimated time until the battery is empty.
To calculate the estimated time I simply take the time since the last charge and the lost percentage since the last charge. For example, if it took 10 hours to go from 100% to 50% then the estimated time until 0% is 10 hours. So I don't take the SOT into account.
Interestingly, the battery statistics in the android settings show almost the same values. Check the screenshots. My widget shows 1 day and 1 hour left and 3 hours SOT. And the battery statistic shows 1 day and 1 hour left and 2 hours 54 minutes SOT. The time since the last charge is rounded to 3 days in the battery statistics and 2 days 18 hours in my widget.
I haven't compared those values before, so I don't know if they are almost the same by coincidence.
 Attachments

 battery.jpg (276.98 KiB) Viewed 4196 times

 batterywidget.jpg (12.54 KiB) Viewed 4196 times