1. Download our Official Android App: Forums for Android!

Using tasker to monitor battery

Discussion in 'Android Apps & Games' started by Valiceemo, May 8, 2014.

  1. Valiceemo

    Valiceemo Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    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?

     

    Advertisement

  2. codesplice

    codesplice Elite Recognized Moderator
    Moderator
    Rank:
     #17
    Points:
    1,638
    Posts:
    9,154
    Joined:
    Oct 29, 2013

    Oct 29, 2013
    9,154
    10,856
    1,638
    Male
    SysAdmin
    Huntsville, AL
    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:
     
  3. Valiceemo

    Valiceemo Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    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.
     
  4. codesplice

    codesplice Elite Recognized Moderator
    Moderator
    Rank:
     #17
    Points:
    1,638
    Posts:
    9,154
    Joined:
    Oct 29, 2013

    Oct 29, 2013
    9,154
    10,856
    1,638
    Male
    SysAdmin
    Huntsville, AL
    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.
     
  5. WarriusZero

    WarriusZero Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    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...
     
  6. Valiceemo

    Valiceemo Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    Sounds good. Keep us posted!
     
  7. KitWasHere

    KitWasHere Well-Known Member
    Rank:
    None
    Points:
    53
    Posts:
    109
    Joined:
    Mar 31, 2013

    Mar 31, 2013
    109
    39
    53
    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 (Text):
    1. A1: Variable Set [ Name:%timediffhours To:(%TIMES-%DischargeStartTime)/60/60 Do Maths:On Append:Off ]
    2. A2: Variable Set [ Name:%leveldiff To:%DischargeStartLevel-%BATT Do Maths:On Append:Off ]
    3. A3: Variable Set [ Name:%percentdrop To:(100/%DischargeStartLevel)*(%leveldiff/%timediffhours) Do Maths:On Append:Off ]
    4. A4: Variable Set [ Name:%timeremaining To:%BATT/%percentdrop Do Maths:On Append:Off ]
    5. A5: Variable Section [ Name:%timeremaining From:1 Length:3 Adapt To Fit:Off Store Result In: ]
    6. A6: Variable Set [ Name:%deathtime To:(%timeremaining*60*60)+%TIMES Do Maths:On Append:Off ]
    7. A7: Variable Convert [ Name:%deathtime Function:Seconds to Date Time Store Result In: ]
    8.  
    Reset/Set Variables (Triggered as an exit task on State-Power:Any):
    Code (Text):
    1. A1: Variable Set [ Name:%DischargeStartTime To:%TIMES Do Maths:Off Append:Off ]
    2. A2: Variable Set [ Name:%DischargeStartLevel To:%BATT Do Maths:Off Append:Off ]
    3.  
     
  8. Valiceemo

    Valiceemo Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    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?
     
  9. KitWasHere

    KitWasHere Well-Known Member
    Rank:
    None
    Points:
    53
    Posts:
    109
    Joined:
    Mar 31, 2013

    Mar 31, 2013
    109
    39
    53
    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
     
  10. Valiceemo

    Valiceemo Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    worth a shot though mate thanks !

    if you could cone up with a workaround that'd be sweet
     
  11. WarriusZero

    WarriusZero Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    codesplice likes this.
  12. Valiceemo

    Valiceemo Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    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.

    [​IMG]

    Any help would be great.
     
  13. WarriusZero

    WarriusZero Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    This system only reports 'milestones', when the battery level reaches 90%, 80%, etc... Give it a chance and check the logs after a day.
     
  14. Valiceemo

    Valiceemo Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    Ah. Of course. Apologies for the dopeyness!
    Looks to be working fine now.
    Is there anyway to get it to report on battery drain?
    For example between 100% and 90% battery drain was 'x' percent per minute?
     
  15. WarriusZero

    WarriusZero Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    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...
     
    codesplice likes this.
  16. Valiceemo

    Valiceemo Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    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.
     
  17. electricpete

    electricpete Android Expert
    Rank:
     #59
    Points:
    393
    Posts:
    2,106
    Joined:
    Jan 7, 2012

    Jan 7, 2012
    2,106
    1,057
    393
    Male
    Electrical Engineer
    I find percent per hour to be a handy unit for tracking battery usage fwiw. That's also how battery monitor widget reports it. Typically 1-2 on standby. 10-30 during use.
     
    Valiceemo and WarriusZero like this.
  18. WarriusZero

    WarriusZero Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    Very good suggestion, thanks.
    Sorry for being a bit slow, Valiceemo, but I'm on holiday under the sun (and some clouds)... It will get done at some point!
     
    D-U-R-X and Valiceemo like this.
  19. Valiceemo

    Valiceemo Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    No problem.
    I await with eager breathe!
     
  20. WarriusZero

    WarriusZero Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    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 :)
     
  21. Valiceemo

    Valiceemo Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    Brilliant work. Care to share the XML?
     
  22. WarriusZero

    WarriusZero Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    I will, very soon. I need to fix 2 small issues (formatting the time to HMS when fully charged and removing the log entry when plugging in while having not gained or lost any %).

    So are you happy with this solution?
     
    Valiceemo and codesplice like this.
  23. Valiceemo

    Valiceemo Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    Yeah. Its bloody brilliant! 👍
     
  24. WarriusZero

    WarriusZero Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    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.
     
    #24 WarriusZero, Aug 14, 2014
    Last edited by a moderator: Mar 9, 2015
  25. Valiceemo

    Valiceemo Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    Brilliant work! Absolutely amazing.
     

Share This Page

Loading...