說明

每天都有XD的事!!

[公告]

『本站提供各類 {整合式教學 + 短評}』

2016年3月10日 星期四

[Android] How to create battery saver with Tasker

After some researching on the Internet, I finally found out how to create battery saver profile with Tasker. Here is how.

TL;DR
1. Turn off wifi and mobile data when display is off.
2. Turn on wifi and mobile data when display is unlocked.
3. Every 1 hour, turn on wifi and mobile data, and then turn on sync. After a few minutes, turn off sync, and then turn off wifi and mobile data.
4. (optional) When syncing, turn on wifi first. If wifi is not connected, turn on mobile data.
5. (optional) When certain apps are running, don't turn off wifi when display is off. 


Usually battery savers work by turning your Internet connection and auto-sync off to avoid battery usage, so I tried to imitate this behavior with tasker.

1. Turn off wifi and mobile data when display is off.

We don't need Internet connection when we're not using the phone, so turn it off when the phone isn't displaying anything.

[Profile 1] 
Display Off  => Internet off

[Task] - Internet off
1. Wifi set off
2. Mobile Data set off

2. Turn on wifi and mobile data when display is unlocked.

We do need Internet connection when we're using the phone, so turn it on when we're actually looking at the phone.

[Profile 2] 
Display Unlocked  => Internet on

[Task] - Internet on
1. Wifi set on
2. Mobile Data set on

3. Every 1 hour, turn on wifi and mobile data, and then turn on sync. After a few minutes, turn off sync, and then turn off wifi and mobile data.

Sync data every 1 hour, nothing much to say about it. But before that we need to turn on Internet connection. Otherwise sync will have no purpose. The key point here is to leave some time for the apps to finish their sync properly, so I went for a 3-minute pause. You can use whatever time you feel like is enough.

[Profile 3]
Every 1h => Sync

[Task] - Sync
1. Wifi set on
2. Mobile Data set off
3. Auto-Sync set on
4. Wait 3 mins
5. Auto-Sync set off
6. Wifi set off
7. Mobile Data set off

*Note: It is also possible to link this sync task with internet on / off tasks with the help of exit tasks, instead of putting in wifi/mobiledata on/off again.

4. (optional) When syncing, turn on wifi first. If wifi is not connected, turn on mobile data.

 I have limited mobile data quota every month, so I prefer using wifi over the mobile network. To accomplish this, the phone will turn on wifi first, and see if wifi is connected. If not connected, we will then turn on mobile data. Unfortunately Tasker lacks a way to check if currently wifi is connected within the logical comparison part, so we need to track it ourselves.

[Profile 4]
Wifi Connected => WIFIC on

[Task] - WIFIC on
1. Variable %WIFIC set to on

[Profile 5]
Not Wifi Connected => WIFIC off

[Task] - WIFIC off
1. Variable %WIFIC set to off

[Profile 3]
Every 1h => Sync

[Task] - Sync
2. Mobile Data set on
    + If %WIFIC eq false

5. (optional) When certain apps are running, don't turn off wifi when display is off. 

Sometimes I listen to the radio on tuneIn over wifi. I don't want the wifi to disconnect when tuneIn is running.
Tasker doesn't have a native method to detect the running state of an app, so I went for a plugin. You can download it here:  Tasker Process Running (KC)

The plugin works like this: if an app or service is running, it will assign a Tasker variable to true; conversely, false. Then we can use this variable to tell if something is running, and then stop the Internet turning off process.

Tasker Process Running might be unstable as the first few times I tried it it didn't work out like I thought it would. Afterwards the settings that worked out for me were

a) Selecting both the app and its service
b) Using the default variable name, which is %apprunning

so just give it some more tries if it doesn't work initially.
 
[Profile 1] 
Display Off  => Internet off

[Task] - Internet off
1. Processes Started: Configuration tuneIn.player;tuneIn.service
2. Stop
    + if %apprunning
3. Wifi set off
4. Mobile Data set off

2 則留言: