User request: Automatic 3G on/off system in Tasker
One of the reasons I love my Galaxy S II is the extended battery I have in it, which essentially allows me to keep everything turned on all the time without having to worry about it for a second. Some devices, like Google’s new piece of s…hiny new phone, the Nexus 4, don’t have any battery power to spare, however. Turning WiFi, 3G, and everything else on and off to save power can be time consuming, and the existing automatic solutions might not fit your usage scenario perfectly. One of our commenters, Shiva, therefore asked for help in setting up Tasker to do it automatically:
All I want is
1. If Display is Off (Not during phone call) and Profile is NOT Home then Wait for 5 mins and Turn 3G Off. In the meantime If Display is Unlocked then do not turn 3G Off
2. If Display is Unlocked and Profile is Not Home Wait for 5 seconds and Turn 3G On
3. Every 10 mins when Display is Off and Profile is Not Home, 3G should be On for 5 mins
There’s a few different things that needs to happen here, and the easiest way to make it all work together is to use multiple profiles- three to be exact. One will handle the 10 minute timer, one the 3G deactivation, and one will handle the screen being turned on. Let’s start with the first, which requires three contexts: Display being off, Home profile being inactive, and lack of any current phone calls. Luckily, all of these three are readily available contexts, so we can just put them in directly. Use the Display State context configured for off, an inverted Profile Active context for Home, and an inverted Call profile for any type.
The task connected to this is simple. Wait for 5 minutes, then turn 3G off. Turning 3G off is not available on all devices, mine included, so you might have to skip the built-in action for that and use the Secure Settings plugin (root required) instead.
Next up is the repeating profile that activates 3G for 5 minutes every 10 minutes. This requires a simple Time context with the start/end times disabled, and the repeat set to 10 minutes, as well as the Display State and Profile Active contexts from the first profile. Note that running a 5 minute task every 10 minutes means that the task will be active for 5 minutes, then deactivated for 5 minutes, and so on. If you want a 10 minute break in between each 3G session, you need to set it to 15 minutes.
The task for this needs to enable 3G, then wait 5 minutes, then disable it again. Very straight forward.
With those two set up, it’s time for the profile that make them all work together. Start by making a new profile and choose Display On or Display Unlocked (depending on your preference) as the context (both are Event contexts). Create a new task for it, and start by adding two Stop actions. Configure one Stop action for each of the tasks for the two other profiles, in this case “3goff” and “5 min 3G”. Because this is a separate profile, it will take priority over any Wait actions, and will effectively stop executing either of the other two profiles’ tasks if the screen is turned on. This means it will stop the other profiles from turning off 3G.
Next, add an If group to the same task. Make the If condition %PACTIVE !~ (doesn’t match) *Home* (assuming your home profile is named Home). %PACTIVE contains a list of active profiles, essentially giving you a variable version of the Profile Active context. By limiting this part of the task to situations where %PACTIVE doesn’t contain *Home*, we manage to fit the 3G on feature from the second point in the wish list into the profile that stops the other tasks, without having to make a separate profile for it. Inside the If group we put a Wait action for 5 seconds, and then enable 3G. When the screen now turns on, this task will first make sure that both the other tasks are stopped (if running). Then, if the Home profile is not active, it will enable 3G.
Note that there is currently no point in having the 5 second wait. While the wish list doesn’t mention it, I suspect the actual thought behind it was to be able to unlock the screen and then relock it again within 5 seconds without having 3G turned on. If that’s the case, a Stop action for this task has to be added to the task for the first profile in order to get that sort of functionality. It’s important to remember that when a task starts running, it continues to run even if the context becomes untrue in the process, so don’t mistake the Wait action for a “wait and recheck” system.
That’s it. Assuming there aren’t any notable differences between devices here, this should work. This setup makes sure that everything works together, preventing situations where running tasks end up interfering with new, faster tasks.