Need a Context for when the battery level changes

432 views
Skip to first unread message

Wes Stacey

unread,
May 6, 2013, 1:06:37 PM5/6/13
to tas...@googlegroups.com
I have a context that updates a Zoom Widget, the widget displays 2 variables %CurrentLoc (a custom variable set by other profiles) and the battery level (%BATT) of the phone.

I would like it to fire my tasks whenever %CurrentLoc or %BATT changes.

I've created a task that updates the widget and it works great the contexts are what i am having an issue with.

I guess since we can't "OR" contexts (which BTW would be a useful feature to add Pent *wink* ), i have to use multiple profiles the one for %CurrentLoc works great using  Event > Variable Set and leaving the value blank.

Battery is more difficult, below is what I've tried and the issue I'm having with each.

1. Event > Variable Set - this is the same context i've used for %CurrentLoc but i get the Error that it doesn't support the built in variable %BATT
2. State > Variable Value (is Even) - with this context it would at least update every 2% which would be acceptable but i get the same error as i get with Event > Variable Set
3. State Battery level - If i put the levels from 0-100 it just stays active all the time and only fires once right after it is created. in order to get it to work i would ahve to create 100 different profiles one for each battery percentage.


Anyone have a good way of launching a task whenever the battery level changes? For now i can have it update the widget every 15 minutes but i would really like a way to do this when the battery level changes.

GermainZ

unread,
May 6, 2013, 1:27:59 PM5/6/13
to tas...@googlegroups.com
Event > Power > Battery Changed.

:)

Wes Stacey

unread,
May 6, 2013, 5:37:28 PM5/6/13
to tas...@googlegroups.com
Alright then i thought I'd looked through all the options but apparently missed one. ;-/

Thank you.

electricpete

unread,
May 6, 2013, 9:50:26 PM5/6/13
to Tasker
I just tried that out... set up a profile to popup a message for that
event. Now it's popping up every 5 or 10 seconds. I don't think it's
working in 1% increments. Might be looking at minisculate change in
voltage, or something.... beats me.

I'll be interested to hear your results. I've got a battery widget
that I just update by time (every 5 minutes when screen on).

Wes Stacey

unread,
May 9, 2013, 9:44:48 AM5/9/13
to tas...@googlegroups.com
Doesn't seem to be doing that for me. it seem to update when the percentage changes. might be something to do with your device.

I'm using a Samsung Galxay Nexus (sprint version).

-Wes

GermainZ

unread,
May 9, 2013, 10:03:26 AM5/9/13
to tas...@googlegroups.com
Works fine here. Are you sure you don't have other profiles that run that same task as well?

Rich D

unread,
May 9, 2013, 8:26:37 PM5/9/13
to tas...@googlegroups.com

> Now it's popping up every 5 or 10 seconds. I don't think it's
> working in 1% increments.

My device only reports batt % in increments of 10 and using 'batt changed' context it seems to fire every 5 -10 minutes but not with the change of %BATT.  

I did a quick search but did not find exactly what is supposed to fire this context.   Does any one know??

I believe if you want to just monitor the % of batt as reported by your device you can use context / event / variable set %BATT.  

Rich..

Rich D

unread,
May 9, 2013, 8:49:06 PM5/9/13
to tas...@googlegroups.com


> I believe if you want to just monitor the % of batt as reported by your device you can use context / event / variable set %BATT.  

Oooops.... sorry..  did not read the first post.  I could have sworn I had used that before, but apparently you can not use %BATT in a variable context. 

I guess you would need to use the 'Batt changed" context then test %BATT against the value that %BATT had the last time the profile was active.  Of course this might not be practical if your "batt changed" context is firing every 5 seconds....

Rich..

Bob Hansen

unread,
May 9, 2013, 10:11:02 PM5/9/13
to tas...@googlegroups.com
Perhaps you should reconsider the desire to update the widget whenever the battery level changes. The fact is the battery level is always changing. It is only a matter of how much over a given time period. By trying to catch every change, tasker must continuously monitor the battery which leads to more battery drain.
I would argue that you are better off monitoring for a change at a fixed time interval (5 minutes?). By doing so you can even calculate the rate of charge or discharge if you want to and calculate the time to fully charges or time to shutdown. Depending upon the time interval used, you would likely not see any noticeable difference in the displayed results. It would also use less battery. 
Just a suggestion.  

GermainZ

unread,
May 10, 2013, 3:49:32 AM5/10/13
to tas...@googlegroups.com
Tasker doesn't constantly monitor the battery changes. They're directly reported by Android once it changes - no polling involved.

Rich D

unread,
May 10, 2013, 7:00:23 AM5/10/13
to tas...@googlegroups.com

I did some testing overnight And found some interesting results. As stated earlier my device only reports Battery percentages In increments of 10.  Here's the profile I use for the test..

Profile: Batt Changed (82)
Event: Battery Changed
Enter: Anon (97)
A1: Flash [ Text:%BATT Long:Off ]
A2: Notify [ Title:%TIME.  %BATT. Text: Icon:<icon> Number:0 Permanent:Off Priority:3 ]

"Apparently " the profile fired with every 1% change.   As the battery discharged I got 10 notifications of battery at 90 percent and then 10 notifications of battery at 80 percent and then 10 notifications of battery at 70 percent etc.... 

I find it strange that Android will report a battery "change" of 1 percent however it will only report my "battery percentage" in 10 percent increments.....

Bob Hansen

unread,
May 10, 2013, 9:21:38 AM5/10/13
to tas...@googlegroups.com
I tried the same thing and got the expect result - each time the notify indicated a 1% drop. 

Rich D

unread,
May 10, 2013, 10:15:27 AM5/10/13
to tas...@googlegroups.com

> What I am not sure is what exactly you. Want to do, if maybe you can show us the profile or tell us more to see how we can help you

If I am reading Tunis post correctly,  the OP "Wes" is using the "Batt Changed " context and all is well... 

However "electricpete" seems to be having problems with this particular context that seems to be related to his device or perhaps ROM.... Unless his batt is discharging 1% in 5 to 10 seconds then something is not working as it should....

Rich..

electricpete

unread,
May 10, 2013, 11:46:18 AM5/10/13
to tas...@googlegroups.com

Yes, it’s definitely firing way too often for me (every 5 to 10 seconds).

 To double-check, I deleted the profile, created brand new profile with anonymous task that has unique message (so we know it cannot be any other profile)

 Results show unequivocally that on my phone (*), the power changed context fires once every 5 to 10 seconds.

 FWIW, here is boring 2 minute video showing the entire process from creating the video to demonstrating the results

http://www.youtube.com/watch?v=xhFhoU3PeNE

*  My phone:  Rooted Samsung Infuse with Android 2.3.6, Tasker version 1.6u1m

Bob Hansen

unread,
May 10, 2013, 12:03:01 PM5/10/13
to tas...@googlegroups.com

Bob Hansen

unread,
May 10, 2013, 12:05:30 PM5/10/13
to tas...@googlegroups.com
Oops, pushed the wrong button.

I'm curious, does the value of %BATT change with every Battery Changed occurrence?

electricpete

unread,
May 10, 2013, 12:43:10 PM5/10/13
to tas...@googlegroups.com
I assume the question is for me.

I added %BATT at the beginning of the flash message.
It flashes 
85 Battery changes...
85 Battery changes...
85 Battery changes...
85 Battery changes...
etc

So the profile fires repeatedly, even when the battery reported to the nearest percent is not changing. 

GermainZ

unread,
May 10, 2013, 1:22:23 PM5/10/13
to tas...@googlegroups.com
Might be a good idea to grab a logcat so Pent can look at it, along with your device info. Unless it's a known issue related to Android fragmentation.

electricpete

unread,
May 10, 2013, 6:25:57 PM5/10/13
to tas...@googlegroups.com

Good idea - I did a logcat.   I excerpted below every record that contains the string “batt”.

It seems there are 3 closely-spaced actions that repeat at intervals of very close to 10 seconds. For example: 

[ 05-10 16:40:56.914   321:0x163 D/BatteryService ]      update start

[ 05-10 16:40:56.914   321:0x163 D/BatteryService ]            updateBattery level:38 scale:100 status:4 health:2 present:true voltage: 3721 temperature: 310 technology: Li-ion AC powered:false USB powered:false icon:17302191

[ 05-10 16:40:56.921   321:0x155 D/Tethering ]

 

Then the sequences of three actions repeats almost exactly 10 secnds later, and again 10 seconds later.  Full set of stuff containing “batt” at the end of this thread.   I don't know what is the business about Tethering... I don't do any Tethering.

Two things come to mind: 

1 - I have another program on my device that monitor battery level: Battery Monitor Widget Pro.  It “stores” the value at user-selectable intervals where the shortest possible interval is 10 seconds.  I have mine set for 3 minutes.  I wonder if possibly it is updating every 10 seconds and recording the average every 3 minutes (there is something similar to that in their documentation... I posted a question on the BMW xda thread and will let you know the results).  Maybe a coincidence but "10 seconds" is the smallest selectable logging interval in the BMW program (screen print attached)

2 - The other part of the story that I’m thinking: maybe whenever BMW “polls” Android OS to find out the battery level, it appears to Tasker as a change in battery (i.e. Tasker isn’t expecting Android to display the battery level unless it changes, but BMW is forcing Android to display it every 10 seconds).

 

Below is excerpt from my log file.  I can email the full log file to Pent if he requests but at this point I don’t want to bother him. It’s not all that important to me.... it's somewhat of a curiosity but not causing me any problems. I just update my battery widget every 5 minutes.  And by the way I do need both a Tasker/zoom battery widget along with BMW pro because they do different things... my Tasker/zoom battery widget sits in the Holo launcher bottom Dock so it's almost always visible (BMW won't display correctly in that location) ... and my Tasker/zoom battery widget is large color-coded percent number... something I can't customize to my liking with BMW.

 

[ 05-10 16:40:56.914   321:0x163 D/BatteryService ]      update start

[ 05-10 16:40:56.914   321:0x163 D/BatteryService ]            updateBattery level:38 scale:100 status:4 health:2 present:true voltage: 3721 temperature: 310 technology: Li-ion AC powered:false USB powered:false icon:17302191

[ 05-10 16:40:56.921   321:0x155 D/Tethering ]            [kjtemp]ACTION_BATTERY_CHANGED

[ 05-10 16:41:06.953   321:0x163 D/BatteryService ]      update start

[ 05-10 16:41:06.957   321:0x163 D/BatteryService ]            updateBattery level:38 scale:100 status:4 health:2 present:true voltage: 3742 temperature: 310 technology: Li-ion AC powered:false USB powered:false icon:17302191

[ 05-10 16:41:06.964   321:0x155 D/Tethering ]            [kjtemp]ACTION_BATTERY_CHANGED

[ 05-10 16:41:16.976   321:0x163 D/BatteryService ]      update start

[ 05-10 16:41:16.980   321:0x163 D/BatteryService ]            updateBattery level:38 scale:100 status:4 health:2 present:true voltage: 3745 temperature: 310 technology: Li-ion AC powered:false USB powered:false icon:17302191

[ 05-10 16:41:16.984   321:0x155 D/Tethering ]            [kjtemp]ACTION_BATTERY_CHANGED

[ 05-10 16:41:27.007   321:0x163 D/BatteryService ]      update start

[ 05-10 16:41:37.039   321:0x163 D/BatteryService ]      update start

[ 05-10 16:41:47.070   321:0x163 D/BatteryService ]      update start

[ 05-10 16:41:47.074   321:0x163 D/BatteryService ]            updateBattery level:38 scale:100 status:4 health:2 present:true voltage: 3727 temperature: 310 technology: Li-ion AC powered:false USB powered:false icon:17302191

[ 05-10 16:41:47.078   321:0x155 D/Tethering ]            [kjtemp]ACTION_BATTERY_CHANGED

[ 05-10 16:41:57.101   321:0x163 D/BatteryService ]      update start

[ 05-10 16:41:57.105   321:0x163 D/BatteryService ]            updateBattery level:38 scale:100 status:4 health:2 present:true voltage: 3732 temperature: 310 technology: Li-ion AC powered:false USB powered:false icon:17302191

[ 05-10 16:41:57.113   321:0x155 D/Tethering ]            [kjtemp]ACTION_BATTERY_CHANGED

[ 05-10 16:42:07.132   321:0x163 D/BatteryService ]      update start

[ 05-10 16:42:07.148   321:0x163 D/BatteryService ]            updateBattery level:38 scale:100 status:4 health:2 present:true voltage: 3730 temperature: 310 technology: Li-ion AC powered:false USB powered:false icon:17302191

[ 05-10 16:42:07.175   321:0x155 D/Tethering ]            [kjtemp]ACTION_BATTERY_CHANGED

[ 05-10 16:42:17.164   321:0x163 D/BatteryService ]      update start

[ 05-10 16:42:17.167   321:0x163 D/BatteryService ]            updateBattery level:38 scale:100 status:4 health:2 present:true voltage: 3742 temperature: 310 technology: Li-ion AC powered:false USB powered:false icon:17302191

[ 05-10 16:42:17.175   321:0x155 D/Tethering ]            [kjtemp]ACTION_BATTERY_CHANGED

[ 05-10 16:42:27.195   321:0x163 D/BatteryService ]      update start

[ 05-10 16:42:27.195   321:0x163 D/BatteryService ]            updateBattery level:38 scale:100 status:4 health:2 present:true voltage: 3683 temperature: 310 technology: Li-ion AC powered:false USB powered:false icon:17302191

[ 05-10 16:42:27.210   321:0x155 D/Tethering ]            [kjtemp]ACTION_BATTERY_CHANGED

[ 05-10 16:42:37.257   321:0x163 D/BatteryService ]      update start

[ 05-10 16:42:37.257   321:0x163 D/BatteryService ]            updateBattery level:38 scale:100 status:4 health:2 present:true voltage: 3732 temperature: 310 technology: Li-ion AC powered:false USB powered:false icon:17302191

[ 05-10 16:42:37.265   321:0x155 D/Tethering ]            [kjtemp]ACTION_BATTERY_CHANGED

[ 05-10 16:42:47.324   321:0x163 D/BatteryService ]      update start

[ 05-10 16:42:47.324   321:0x163 D/BatteryService ]            updateBattery level:38 scale:100 status:4 health:2 present:true voltage: 3663 temperature: 310 technology: Li-ion AC powered:false USB powered:false icon:17302191

[ 05-10 16:42:47.332   321:0x155 D/Tethering ]            [kjtemp]ACTION_BATTERY_CHANGED

[ 05-10 16:42:57.386   321:0x163 D/BatteryService ]      update start

[ 05-10 16:42:57.386   321:0x163 D/BatteryService ]            updateBattery level:38 scale:100 status:4 health:2 present:true voltage: 3696 temperature: 310 technology: Li-ion AC powered:false USB powered:false icon:17302191

[ 05-10 16:42:57.417   321:0x155 D/Tethering ]            [kjtemp]ACTION_BATTERY_CHANGED
shot_000383.png

electricpete

unread,
May 10, 2013, 6:58:49 PM5/10/13
to tas...@googlegroups.com
Update: I tried "blocking" (freezing) BMW Pro using Gemini Apps manager (didn't want to have to uninstall it and lose my settings).
The result was that the Tasker behavior was unchanged... still fired the changed battery profile every 10 seconds.
So much for that theory.

Pent

unread,
May 11, 2013, 4:15:58 AM5/11/13
to Tasker
Thanks for the log.

If the 'level' stays the same, the context shouldn't trigger again no
matter how many times the event is received.

Could you send me an SD log so I can see what Tasker is saying ?

http://tasker.dinglisch.net/userguide/en/faqs/faq-how.html#x2

Thanks,

Pent
Reply all
Reply to author
Forward
0 new messages