Monday, July 27, 2015

[Tasker] Better battery save widget - "periodic internet": 1%/hr

It's been a while. But I'm back :) So sorry for not replying to all comments.

Many things changed... I updated my Note 3 to Lollipop (feels good, looks bad), bought a smartwatch (LG Watch R, great battery life due to the OLED display, but not really stable connection to the Google Watch software, but that should be Googles fault, still working on a fix for this). Lost my xposed framework functionality due to the new ART framework and my odexed official ROM, but thats off topic ^^

I really wonder, who needs a smartphone 7 mm thick with a battery life of 1 day, if one could have instead one, which is 1 cm thick, a little heavier, but a battery life of 3 days. I would hate it, if the new Samsung Galaxy Note 5 would come without an exchangeable battery..... Anyway, as thinner means "better" for customers (grrrr) we have to deal with it. Here is my newest battery saving widget!

I know, there are programs like "Juice defender" out there. But I don't like overloaded software I have not full control of, running in the background, using RAM and CPU time.

It is much more stable (can run for hours and hours) then my previous approaches and I lose approximately 1% of battery per hour.


What will you get:
A small widget on your home screen, you click on. It will:
  • START
  • Wait 1,5 minute
  • Activate flight mode (or only deactivate data and wifi)
  • Wait 15 minuts
  • Deactivate airplane mode (or turn data and wifi on)
  • GOTO START
Thats it... It works better, then the previous approaches, because we will use the Tasker Timer option for repeating the task. That means, that it doesn't block other Tasker tasks while running.

This is how it will look like, look at the icon in the lower left corner (oh and hover the screenshot):


Off
What do you need:
  • For the icons (optional): Ipack / Crystal Project HD and Ipack / Kyo-Tux Aeon HD
  • For turning airplane mode on and off (optional): Secure Settings if you have ROOT access (HowTo Root), if you don't have ROOT, you can still continue to read - instead of toggling airplane mode, you can toggle DATA and WIFI with Tasker, no need for Secure Settings, maybe you prefer this anyway, the benefit is, you can still be called while in energy saving mode.
  • Tasker
  • 20 minutes of life time (scroll down for direct downloads)
So lets start with the profile and the associated task:

Create a new profile in Tasker, call it "Periodic Internet Widget Off". This profile will be activated, if we click on the notification while the energy saving mode is running. It will deactivate the energy saving mode.

Profile: Periodic Internet Widget Off
 Event: Notification Click [ Owner Application:Tasker Title:Periodic internet Widget ]
 Enter: Periodic internet Widget Off
 Abort Existing Task

 A1: Stop [ With Error:Off Task:Periodic Internet ]
 A2: Secure Settings [ Configuration:Airplane Mode Disabled Package:com.intangibleobject.securesettings.plugin Name:Secure Settings Timeout (Seconds):0 ]
 A3: Mobile Data [ Set:On ] If [ %MOBILDATA ~ 1 ]
 A4: WiFi [ Set:On ] If [ %WLANTMP ~ 1 ]
 A5: Notify Cancel [ Title:Periodic internet Widget Warn Not Exist:Off ]
 A6: Variable Set [ Name:%PERIRADIO To:0 Do Maths:Off Append:Off ]
 A7: Profile Status [ Name:Periodic Internet Widget Off Set:Off ]
 A8: Timer Widget Control [ Name:Periodic Internet Type:Reset ]
 A9: [X] Timer Widget Control [ Name:Periodic Internet Type:End ]
 A10: Set Widget Icon [ Name:Periodic Internet Icon:ipack:kyotuxaeonhd:network_offline_alt ]
 A11: Timer Widget Set [ Name:Periodic Internet Seconds:1 Minutes:0 Hours:0 Days:0 ] 


Now we nee a task to do the actual work. So create this task: 
Task name: Periodic internet Widget On
 Abort Existing Task

 A1: Variable Set [ Name:%PERIRADIO To:1 Do Maths:Off Append:Off ]
 A2: Variable Set [ Name:%MOBILDATA To:1 Do Maths:Off Append:Off ] If [ %AIR ~ off ]
 A3: Variable Set [ Name:%MOBILDATA To:0 Do Maths:Off Append:Off ] If [ %AIR !~ off ]
 A4: Variable Set [ Name:%WLANTMP To:1 Do Maths:Off Append:Off ] If [ %WIFII ~R CONNECTION ]
 A5: Variable Set [ Name:%WLANTMP To:0 Do Maths:Off Append:Off ] If [ %WIFII !~R CONNECTION ]
 A6: Variable Set [ Name:%noradio To:%MOBILDATA+%WLANTMP Do Maths:On Append:Off ]
 A7: If [ %noradio ~ 0 ]
 A8:   Stop [ With Error:Off Task: ]
 A9: End If
 A10: Timer Widget Set [ Name:Periodic Internet Seconds:0 Minutes:15 Hours:0 Days:0 ]
 A11: Timer Widget Control [ Name:Periodic Internet Type:Resume ] 


The last task looks like this:
Task name: Periodic Internet

 A1: Timer Widget Set [ Name:Periodic Internet Seconds:0 Minutes:15 Hours:0 Days:0 ]
 A2: Set Widget Icon [ Name:Periodic Internet Icon:android.resource://net.dinglisch.android.ipack.crystalhd/drawable/quick_restart ]
 A3: Notify [ Title:Periodic internet Widget Text: Icon:android.resource://net.dinglisch.android.ipack.crystalhd/drawable/quick_restart Number:%SCRON Permanent:On Priority:2 ]
 A4: Profile Status [ Name:Periodic Internet Widget Off Set:On ]
 A5: Secure Settings [ Configuration:Airplane Mode Disabled Package:com.intangibleobject.securesettings.plugin Name:Secure Settings Timeout (Seconds):0 ]
 A6: Wait [ MS:0 Seconds:30 Minutes:0 Hours:0 Days:0 ]
 A7: WiFi [ Set:On ]
 A8: Mobile Data [ Set:On ]
 A9: Wait [ MS:0 Seconds:0 Minutes:1 Hours:0 Days:0 ]
 A10: Secure Settings [ Configuration:Airplane Mode Enabled Package:com.intangibleobject.securesettings.plugin Name:Secure Settings Timeout (Seconds):0 ] 

Add the red lines only, if you have ROOT and want to toggle airplane mode.

You can download and import the tasks directly without the hassle here:

Profile: Periodic Internet Widget Off
Task name: Periodic internet Widget On
Task name: Periodic Internet

To see how to import them, skim this article: How to import Tasker projects, profiles, tasks and scenes 

Now we need to create the widget to actually start our "periodic internet" mode.

  1.  Add a "Tasker Timer Task" to your home screen.
  2. As the task to run select: "Periodic Internet".
  3. Set the countdown to 0:0:0:1 (One second) and activate Repeat ON
The periodic internet mode should start immediately. Don't forget, it will take 1,5 minutes, until the wifi/data or airplane mode is activated for the first time.
To deactivate the "periodic internet" mode, you should click on the permanent notification in the notification bar.

Hope it helps You :)
Leave your opinion in the comments!