• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Using tasker to monitor battery

V

Valiceemo

Guest
How would I go about this? I'd like tasker to help me monitor my battery, without heavily contributing to the drain?
Something simple like noting the battery level at set intervals perhaps?

Anybody doing anything similar and care to share?
 
How would you like to monitor - just a notification?

Condition:
• Event: Power > Battery Changed

Task:
• Alert: Notify; Title: Battery; Text: %BATT

You can even set an icon if you'd like (there's a nice battery one built-in), you can make it permanent (so it can't be dismissed), and even set an action to take you directly to battery usage details if you want. :thumbup:
 
Upvote 0
Thanks. But this isn't really what I'm after. This would just replicate what most roms can do, i.e show battery percent in status bar.
I was looking for a more detailed monitoring method. For example battery drain / hr or min? Time to charge, etc.
 
Upvote 0
I'm sure what you want is probably possible, but I'm not sure why you would want to go through that effort instead of using one of the already-working battery management apps. Battery Widget Reborn and GSam Battery Monitor are two that I can strongly recommend.

They are both significantly easier to configure than trying to build a Tasker profile to accomplish the same, and probably more stable and reliable (and battery-friendly) as well. :thumbup:

Don't get me wrong - I use Tasker for a ton of things; I just think this is one task better handled by a dedicated app.
 
Upvote 0
Would you be interested in having some logging done when:
- the battery level reaches 'milestones', for example every 10%
- the phone is put in charge
- the phone is plugged off (with some stats)

I'm currently working on something and I'm just ironing out the last details...
 
Upvote 0
All you're really looking for is math on the times and charge percentages. I'll get you started.

This here will estimate when your battery will die based on how much it's dropped since you took it off the charger. Takes two profiles (need one to reset when charging), I'll cut out the notification bit to keep this post relatively short.

Main Profile (Triggered whenever you want):
Code:
A1: Variable Set [ Name:%timediffhours To:(%TIMES-%DischargeStartTime)/60/60 Do Maths:On Append:Off ] 
A2: Variable Set [ Name:%leveldiff To:%DischargeStartLevel-%BATT Do Maths:On Append:Off ] 
A3: Variable Set [ Name:%percentdrop To:(100/%DischargeStartLevel)*(%leveldiff/%timediffhours) Do Maths:On Append:Off ] 
A4: Variable Set [ Name:%timeremaining To:%BATT/%percentdrop Do Maths:On Append:Off ] 
A5: Variable Section [ Name:%timeremaining From:1 Length:3 Adapt To Fit:Off Store Result In: ] 
A6: Variable Set [ Name:%deathtime To:(%timeremaining*60*60)+%TIMES Do Maths:On Append:Off ] 
A7: Variable Convert [ Name:%deathtime Function:Seconds to Date Time Store Result In: ]

Reset/Set Variables (Triggered as an exit task on State-Power:Any):
Code:
A1: Variable Set [ Name:%DischargeStartTime To:%TIMES Do Maths:Off Append:Off ] 
A2: Variable Set [ Name:%DischargeStartLevel To:%BATT Do Maths:Off Append:Off ]
 
Upvote 0
All you're really looking for is math on the times and charge percentages. I'll get you started.

This here will estimate when your battery will die based on how much it's dropped since you took it off the charger. Takes two profiles (need one to reset when charging), I'll cut out the notification bit to keep this post relatively short.

Main Profile (Triggered whenever you want):
Code:
A1: Variable Set [ Name:%timediffhours To:(%TIMES-%DischargeStartTime)/60/60 Do Maths:On Append:Off ] 
A2: Variable Set [ Name:%leveldiff To:%DischargeStartLevel-%BATT Do Maths:On Append:Off ] 
A3: Variable Set [ Name:%percentdrop To:(100/%DischargeStartLevel)*(%leveldiff/%timediffhours) Do Maths:On Append:Off ] 
A4: Variable Set [ Name:%timeremaining To:%BATT/%percentdrop Do Maths:On Append:Off ] 
A5: Variable Section [ Name:%timeremaining From:1 Length:3 Adapt To Fit:Off Store Result In: ] 
A6: Variable Set [ Name:%deathtime To:(%timeremaining*60*60)+%TIMES Do Maths:On Append:Off ] 
A7: Variable Convert [ Name:%deathtime Function:Seconds to Date Time Store Result In: ]

Reset/Set Variables (Triggered as an exit task on State-Power:Any):
Code:
A1: Variable Set [ Name:%DischargeStartTime To:%TIMES Do Maths:Off Append:Off ] 
A2: Variable Set [ Name:%DischargeStartLevel To:%BATT Do Maths:Off Append:Off ]

Thanks for this.
Ive tried it and it doesnt seem to work.
Do the variables need to be global in order to work with each other as enter and exit tasks?
 
Upvote 0
Hmm, you're right this doesn't work. I hadn't used it in so long, but it used to work. Task fails for me on the Variable Convert

I looked into it and it seems Unix Time/%TIMES is too big now for my phone to do math with, defaults to scientific notation which messes up everything. I'll have to find a workaround, but it will probably be a while as I kind of don't use Tasker all that much these days
 
Upvote 0
Hmm, you're right this doesn't work. I hadn't used it in so long, but it used to work. Task fails for me on the Variable Convert

I looked into it and it seems Unix Time/%TIMES is too big now for my phone to do math with, defaults to scientific notation which messes up everything. I'll have to find a workaround, but it will probably be a while as I kind of don't use Tasker all that much these days
worth a shot though mate thanks !

if you could cone up with a workaround that'd be sweet
 
Upvote 0
  • Like
Reactions: codesplice
Upvote 0
Sorry for the lateness, here is my solution, ready to import:
https://docs.google.com/file/d/0B3R3a2WGs6rYVWZTVzNTUEN4eFk/edit?pli=1

Feel free to comment, ask, criticise and adapt to your own needs.

EDIT: I've included my boot task (any actions not related to this thread should be commented out) as it sets the context for the logging process.
Hey thanks for this.
Sorry ive not fed back sooner. Been really busy and has stuff going on.
I tried your project and it doesn't seem to work.
The plugged in and out profiles work and write to the eventlog.txt file correctly.
But the battery changes doesn't.
I don't really understand what the variable section action is for?
It seems to stop there. At the 'If batterylevelunits = 0' action. As it doesn't it equals the second figure of current battery level. i.e 31% becomes 1.
I.e attached a screenshot to show the amount of 'reds' throughout.

yqe7u2u4.jpg


Any help would be great.
 
Upvote 0
OK, I'll add some stats for every 10% lost.
What's better? x min per % or x % per min?
I'd go with x min per % as it should be the one that's >1. Hopefully anyway!

Also you can report every 5% if you want. Add a "Or %BatteryLevelUnits = 5" condition to the "If %BatteryLevelUnits = 0" test...
 
  • Like
Reactions: codesplice
Upvote 0
OK, I'll add some stats for every 10% lost.
What's better? x min per % or x % per min?
I'd go with x min per % as it should be the one that's >1. Hopefully anyway!

Also you can report every 5% if you want. Add a "Or %BatteryLevelUnits = 5" condition to the "If %BatteryLevelUnits = 0" test...

Thanks. if you could add it in and post them that would be ace!
Ive tried to figure it out but just cant get my head around it!
Im not sure what way round to go, i think it would be more useful to see the percentage drop per minute? i.e. -1% per so many minutes
But i guess this is more work, so x minutes per -10% is OK to help monitor.
 
Upvote 0
I'm not completely done but for now I'm getting this kind of stuff (for testing purposes, I report milestones every 5% and every 30 min. I also haven't added stats for the % milestones yet):

Wednesday 13-08-2014, 05.33: Battery down to 90%
Wednesday 13-08-2014, 05.44: Battery down to 85%
Wednesday 13-08-2014, 06.00: 15% lost over the last 30 min
Wednesday 13-08-2014, 06.21: Battery down to 75%
Wednesday 13-08-2014, 06.38: Power on at 73%
Wednesday 13-08-2014, 06.38: 26% lost in 1 hrs, 43 min, 20 sec
Wednesday 13-08-2014, 06.40: Battery up to 75%
Wednesday 13-08-2014, 06.51: Battery up to 80%
Wednesday 13-08-2014, 07.00: 6% gained over the last 30 min
Wednesday 13-08-2014, 07.02: Battery up to 85%
Wednesday 13-08-2014, 07.15: Battery up to 90%
Wednesday 13-08-2014, 07.29: Battery up to 95%
Wednesday 13-08-2014, 07.30: 11% gained over the last 30 min
Wednesday 13-08-2014, 07.31: Fully charged (1.981 min per %)
Wednesday 13-08-2014, 08.00: 5% gained over the last 30 min
Wednesday 13-08-2014, 09.19: Power off
Wednesday 13-08-2014, 09.59: Power on at 98%
Wednesday 13-08-2014, 09.59: 2% lost in 39 min, 58 sec
Wednesday 13-08-2014, 09.59: Power off at 98% (no charging rate available)
Wednesday 13-08-2014, 09.59: Power on at 98%
Wednesday 13-08-2014, 09.59: 0% lost in 0 sec
Wednesday 13-08-2014, 10.00: 2% lost over the last 30 min
Wednesday 13-08-2014, 10.27: Power off
Wednesday 13-08-2014, 10.27: Power on at 100%
Wednesday 13-08-2014, 10.27: 0% lost in 2 sec
Wednesday 13-08-2014, 10.30: Power off
Wednesday 13-08-2014, 10.30: Power on at 100%
Wednesday 13-08-2014, 10.30: 0% lost in 3 sec
Wednesday 13-08-2014, 10.45: Power off at 99% (-15.067 min per %)
Wednesday 13-08-2014, 11.00: 1% gained over the last 30 min
Wednesday 13-08-2014, 11.14: Battery down to 95%
Wednesday 13-08-2014, 11.30: 8% lost over the last 30 min
Wednesday 13-08-2014, 11.30: Battery down to 90%
Wednesday 13-08-2014, 11.44: Battery down to 85%
Wednesday 13-08-2014, 12.00: 9% lost over the last 30 min
Wednesday 13-08-2014, 12.25: Battery down to 80%
Wednesday 13-08-2014, 12.30: 2% lost over the last 30 min
Wednesday 13-08-2014, 12.46: Battery down to 75%
Wednesday 13-08-2014, 13.00: 9% lost over the last 30 min
Wednesday 13-08-2014, 13.02: Battery down to 70%
Wednesday 13-08-2014, 13.12: Battery down to 65%
Wednesday 13-08-2014, 13.42: Battery down to 60%
Wednesday 13-08-2014, 13.51: Power on at 60%
Wednesday 13-08-2014, 13.51: 39% lost in 3 hrs, 6 min, 1 sec
Wednesday 13-08-2014, 13.51: Power off at 60% (no charging rate available)
Wednesday 13-08-2014, 13.51: Power on at 60%
Wednesday 13-08-2014, 13.51: 0% lost in 2 sec
Wednesday 13-08-2014, 14.00: 8% lost over the last 30 min
Wednesday 13-08-2014, 14.02: Battery up to 65%
Wednesday 13-08-2014, 14.11: Battery up to 70%
Wednesday 13-08-2014, 14.19: Battery up to 75%
Wednesday 13-08-2014, 14.29: Battery up to 80%
Wednesday 13-08-2014, 14.30: 17% gained over the last 30 min
Wednesday 13-08-2014, 14.33: Power off at 81% (1.977 min per %)
Wednesday 13-08-2014, 14.35: Battery down to 80%
Wednesday 13-08-2014, 14.53: Battery down to 75%
Wednesday 13-08-2014, 15.00: 7% lost over the last 30 min
Wednesday 13-08-2014, 15.15: Power on at 72%
Wednesday 13-08-2014, 15.15: 9% lost in 41 min, 48 sec
Wednesday 13-08-2014, 15.22: Battery up to 75%
Wednesday 13-08-2014, 15.30: 6% gained over the last 30 min
Wednesday 13-08-2014, 15.30: Battery up to 80%
Wednesday 13-08-2014, 15.39: Battery up to 85%
Wednesday 13-08-2014, 15.46: Power off at 88% (1.96 min per %)
Wednesday 13-08-2014, 16.00: 8% gained over the last 30 min
Wednesday 13-08-2014, 16.07: Battery down to 85%
Wednesday 13-08-2014, 16.12: Power on at 85%
Wednesday 13-08-2014, 16.12: 3% lost in 25 min, 56 sec
Wednesday 13-08-2014, 16.22: Battery up to 90%
Wednesday 13-08-2014, 16.32: Battery up to 95%
Wednesday 13-08-2014, 16.33: Power off at 94% (2.127 min per %)
Wednesday 13-08-2014, 17.00: 5% gained over the last 30 min
Wednesday 13-08-2014, 17.04: Battery down to 90%
Wednesday 13-08-2014, 17.13: Battery down to 85%
Wednesday 13-08-2014, 17.30: 11% lost over the last 30 min
Wednesday 13-08-2014, 17.30: Battery down to 80%
Wednesday 13-08-2014, 17.59: Battery down to 75%
Wednesday 13-08-2014, 18.00: 6% lost over the last 30 min
Wednesday 13-08-2014, 18.30: 2% lost over the last 30 min
Wednesday 13-08-2014, 19.13: Battery down to 70%
Wednesday 13-08-2014, 19.25: Battery down to 65%
Wednesday 13-08-2014, 19.30: 9% lost over the last 30 min
Wednesday 13-08-2014, 19.39: Battery down to 60%
Wednesday 13-08-2014, 19.53: Battery down to 55%
Wednesday 13-08-2014, 20.00: 11% lost over the last 30 min
Wednesday 13-08-2014, 20.07: Battery down to 50%
Wednesday 13-08-2014, 20.21: Battery down to 45%
Wednesday 13-08-2014, 20.29: Power on at 41%
Wednesday 13-08-2014, 20.29: 47% lost in 4 hrs, 42 min, 43 sec
Wednesday 13-08-2014, 20.30: 11% lost over the last 30 min
Wednesday 13-08-2014, 20.36: Battery up to 45%

I don't find the results very satisfying, it looks messy. Not sure if it's because I report too often or because I report 2 types of stats at the same time. Any suggestions?

EDIT: small note because I'm picky, there's no 'Battery down to 80%' at the very beginning probably because I was in the middle of editing my profiles and tasks... There are also some useless stats probably when I started the car right after plugging in the phone.

EDIT 2: "(2.127 min per %)" is now "(2 min, 7 sec per %)", thanks to a reusable "ConvertToHMS" (Hours/Minutes/Seconds) task :)
 
Upvote 0
I'm not completely done but for now I'm getting this kind of stuff (for testing purposes, I report milestones every 5% and every 30 min. I also haven't added stats for the % milestones yet):

Wednesday 13-08-2014, 05.33: Battery down to 90%
Wednesday 13-08-2014, 05.44: Battery down to 85%
Wednesday 13-08-2014, 06.00: 15% lost over the last 30 min
Wednesday 13-08-2014, 06.21: Battery down to 75%
Wednesday 13-08-2014, 06.38: Power on at 73%
Wednesday 13-08-2014, 06.38: 26% lost in 1 hrs, 43 min, 20 sec
Wednesday 13-08-2014, 06.40: Battery up to 75%
Wednesday 13-08-2014, 06.51: Battery up to 80%
Wednesday 13-08-2014, 07.00: 6% gained over the last 30 min
Wednesday 13-08-2014, 07.02: Battery up to 85%
Wednesday 13-08-2014, 07.15: Battery up to 90%
Wednesday 13-08-2014, 07.29: Battery up to 95%
Wednesday 13-08-2014, 07.30: 11% gained over the last 30 min
Wednesday 13-08-2014, 07.31: Fully charged (1.981 min per %)
Wednesday 13-08-2014, 08.00: 5% gained over the last 30 min
Wednesday 13-08-2014, 09.19: Power off
Wednesday 13-08-2014, 09.59: Power on at 98%
Wednesday 13-08-2014, 09.59: 2% lost in 39 min, 58 sec
Wednesday 13-08-2014, 09.59: Power off at 98% (no charging rate available)
Wednesday 13-08-2014, 09.59: Power on at 98%
Wednesday 13-08-2014, 09.59: 0% lost in 0 sec
Wednesday 13-08-2014, 10.00: 2% lost over the last 30 min
Wednesday 13-08-2014, 10.27: Power off
Wednesday 13-08-2014, 10.27: Power on at 100%
Wednesday 13-08-2014, 10.27: 0% lost in 2 sec
Wednesday 13-08-2014, 10.30: Power off
Wednesday 13-08-2014, 10.30: Power on at 100%
Wednesday 13-08-2014, 10.30: 0% lost in 3 sec
Wednesday 13-08-2014, 10.45: Power off at 99% (-15.067 min per %)
Wednesday 13-08-2014, 11.00: 1% gained over the last 30 min
Wednesday 13-08-2014, 11.14: Battery down to 95%
Wednesday 13-08-2014, 11.30: 8% lost over the last 30 min
Wednesday 13-08-2014, 11.30: Battery down to 90%
Wednesday 13-08-2014, 11.44: Battery down to 85%
Wednesday 13-08-2014, 12.00: 9% lost over the last 30 min
Wednesday 13-08-2014, 12.25: Battery down to 80%
Wednesday 13-08-2014, 12.30: 2% lost over the last 30 min
Wednesday 13-08-2014, 12.46: Battery down to 75%
Wednesday 13-08-2014, 13.00: 9% lost over the last 30 min
Wednesday 13-08-2014, 13.02: Battery down to 70%
Wednesday 13-08-2014, 13.12: Battery down to 65%
Wednesday 13-08-2014, 13.42: Battery down to 60%
Wednesday 13-08-2014, 13.51: Power on at 60%
Wednesday 13-08-2014, 13.51: 39% lost in 3 hrs, 6 min, 1 sec
Wednesday 13-08-2014, 13.51: Power off at 60% (no charging rate available)
Wednesday 13-08-2014, 13.51: Power on at 60%
Wednesday 13-08-2014, 13.51: 0% lost in 2 sec
Wednesday 13-08-2014, 14.00: 8% lost over the last 30 min
Wednesday 13-08-2014, 14.02: Battery up to 65%
Wednesday 13-08-2014, 14.11: Battery up to 70%
Wednesday 13-08-2014, 14.19: Battery up to 75%
Wednesday 13-08-2014, 14.29: Battery up to 80%
Wednesday 13-08-2014, 14.30: 17% gained over the last 30 min
Wednesday 13-08-2014, 14.33: Power off at 81% (1.977 min per %)
Wednesday 13-08-2014, 14.35: Battery down to 80%
Wednesday 13-08-2014, 14.53: Battery down to 75%
Wednesday 13-08-2014, 15.00: 7% lost over the last 30 min
Wednesday 13-08-2014, 15.15: Power on at 72%
Wednesday 13-08-2014, 15.15: 9% lost in 41 min, 48 sec
Wednesday 13-08-2014, 15.22: Battery up to 75%
Wednesday 13-08-2014, 15.30: 6% gained over the last 30 min
Wednesday 13-08-2014, 15.30: Battery up to 80%
Wednesday 13-08-2014, 15.39: Battery up to 85%
Wednesday 13-08-2014, 15.46: Power off at 88% (1.96 min per %)
Wednesday 13-08-2014, 16.00: 8% gained over the last 30 min
Wednesday 13-08-2014, 16.07: Battery down to 85%
Wednesday 13-08-2014, 16.12: Power on at 85%
Wednesday 13-08-2014, 16.12: 3% lost in 25 min, 56 sec
Wednesday 13-08-2014, 16.22: Battery up to 90%
Wednesday 13-08-2014, 16.32: Battery up to 95%
Wednesday 13-08-2014, 16.33: Power off at 94% (2.127 min per %)
Wednesday 13-08-2014, 17.00: 5% gained over the last 30 min
Wednesday 13-08-2014, 17.04: Battery down to 90%
Wednesday 13-08-2014, 17.13: Battery down to 85%
Wednesday 13-08-2014, 17.30: 11% lost over the last 30 min
Wednesday 13-08-2014, 17.30: Battery down to 80%
Wednesday 13-08-2014, 17.59: Battery down to 75%
Wednesday 13-08-2014, 18.00: 6% lost over the last 30 min
Wednesday 13-08-2014, 18.30: 2% lost over the last 30 min
Wednesday 13-08-2014, 19.13: Battery down to 70%
Wednesday 13-08-2014, 19.25: Battery down to 65%
Wednesday 13-08-2014, 19.30: 9% lost over the last 30 min
Wednesday 13-08-2014, 19.39: Battery down to 60%
Wednesday 13-08-2014, 19.53: Battery down to 55%
Wednesday 13-08-2014, 20.00: 11% lost over the last 30 min
Wednesday 13-08-2014, 20.07: Battery down to 50%
Wednesday 13-08-2014, 20.21: Battery down to 45%
Wednesday 13-08-2014, 20.29: Power on at 41%
Wednesday 13-08-2014, 20.29: 47% lost in 4 hrs, 42 min, 43 sec
Wednesday 13-08-2014, 20.30: 11% lost over the last 30 min
Wednesday 13-08-2014, 20.36: Battery up to 45%

I don't find the results very satisfying, it looks messy. Not sure if it's because I report too often or because I report 2 types of stats at the same time. Any suggestions?

EDIT: small note because I'm picky, there's no 'Battery down to 80%' at the very beginning probably because I was in the middle of editing my profiles and tasks... There are also some useless stats probably when I started the car right after plugging in the phone.

EDIT 2: "(2.127 min per %)" is now "(2 min, 7 sec per %)", thanks to a reusable "ConvertToHMS" (Hours/Minutes/Seconds) task :)
Brilliant work. Care to share the XML?
 
Upvote 0
Here it is, with a list of changes that I could think of. I haven't had time to test the project separately from the rest of my stuff but hopefully I've copied in all the required content. Let me know if something doesn't work.

A note mainly for the other forum users, feel free to also use only bits that interest you, including the time converter and the logging platform...

https://drive.google.com/open?id=0B3R3a2WGs6rYWVpzWnNHc2xwWTg

Changes (some stuff wasn't required but it corresponds to my own needs):

- Added extra reports every hour. It can easily be changed to 30 min but you then need to amend the text logged in the task 'Periodic Battery Report' (where it says '... over the last hour')
- Added discharge rate to Power On log
- Now using local variables whenever possible (I need to do that on the rest of my stuff)
- Added reusable task ConvertToHMS. Use it with a parameter. Then use the variable HMSnum or HMStext
- Added reusable task Log Event. String to log goes in parameter 1. Set parameter 2 to yes to also get a toast
- Added a scene to show the logs (set up for Nexus 4, not tested elsewhere). Add a shortcut to 'Show Logs' to your home screen for easy access
- Added a notification when the battery is overheating

Any question, anyone, please ask.
 
Last edited by a moderator:
Upvote 0
Here it is, with a list of changes that I could think of. I haven't had time to test the project separately from the rest of my stuff but hopefully I've copied in all the required content. Let me know if something doesn't work.

A note mainly for the other forum users, feel free to also use only bits that interest you, including the time converter and the logging platform...

https://docs.google.com/file/d/0B3R3a2WGs6rYTmNLZjhLeVZTSUU/edit?usp=docslist_api

Changes (some stuff wasn't required but it corresponds to my own needs):

- Added extra reports every hour. It can easily be changed to 30 min but you then need to amend the text logged in the task 'Periodic Battery Report' (where it says '... over the last hour')
- Added discharge rate to Power On log
- Now using local variables whenever possible (I need to do that on the rest of my stuff)
- Added reusable task ConvertToHMS. Use it with a parameter. Then use the variable HMSnum or HMStext
- Added reusable task Log Event. String to log goes in parameter 1. Set parameter 2 to yes to also get a toast
- Added a scene to show the logs (set up for Nexus 4, not tested elsewhere). Add a shortcut to 'Show Logs' to your home screen for easy access
- Added a notification when the battery is overheating

Any question, anyone, please ask.

Brilliant work! Absolutely amazing.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones