1. Are you ready for the Galaxy S20? Here is everything we know so far!

Using tasker to monitor battery

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

  1. Valiceemo

    Valiceemo Guest
    Thread Starter

    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. Best Answer:
    Post #24 by WarriusZero, Aug 14, 2014 (1 points)
  3. codesplice

    codesplice Elite Recognized Moderator
    Moderator

    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:
     
  4. Valiceemo

    Valiceemo Guest
    Thread Starter

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

    codesplice Elite Recognized Moderator
    Moderator

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

    WarriusZero Guest
    Thread Starter

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

    Valiceemo Guest
    Thread Starter

    Sounds good. Keep us posted!
     
  8. KitWasHere

    KitWasHere Well-Known Member

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

    Valiceemo Guest
    Thread Starter

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

    KitWasHere Well-Known Member

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

    Valiceemo Guest
    Thread Starter

    worth a shot though mate thanks !

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

    WarriusZero Guest
    Thread Starter

    codesplice likes this.
  13. Valiceemo

    Valiceemo Guest
    Thread Starter

    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.
     
  14. WarriusZero

    WarriusZero Guest
    Thread Starter

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

    Valiceemo Guest
    Thread Starter

    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?
     
  16. WarriusZero

    WarriusZero Guest
    Thread Starter

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

    Valiceemo Guest
    Thread Starter

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

    electricpete Android Expert

    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.
  19. WarriusZero

    WarriusZero Guest
    Thread Starter

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

    Valiceemo Guest
    Thread Starter

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

    WarriusZero Guest
    Thread Starter

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

    Valiceemo Guest
    Thread Starter

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

    WarriusZero Guest
    Thread Starter

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

    Valiceemo Guest
    Thread Starter

    Yeah. Its bloody brilliant! 👍
     
  25. WarriusZero

    WarriusZero Guest
    Thread Starter

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

    Valiceemo Guest
    Thread Starter

    Brilliant work! Absolutely amazing.
     
Loading...
Similar Threads - Using tasker monitor
  1. King Mustard
    Replies:
    4
    Views:
    228
  2. curtis1997
    Replies:
    0
    Views:
    175
  3. Staff✅
    Replies:
    3
    Views:
    145
  4. Staff✅
    Replies:
    0
    Views:
    91
  5. LDM
    Replies:
    5
    Views:
    1,757
  6. ldm1417
    Replies:
    8
    Views:
    1,893
  7. ldm1417
    Replies:
    1
    Views:
    943
  8. haima123
    Replies:
    1
    Views:
    509
  9. amankhalid
    Replies:
    11
    Views:
    3,753
  10. Papamalo
    Replies:
    4
    Views:
    2,069

Share This Page

Loading...