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.

Share this:

About the Author

Andreas Ødegård was an associate editor at Pocketables. He’s more interested in aftermarket (and user created) software and hardware than chasing the latest gadgets and tends to stick with his choice of device for a long time as a result of that. Currently that includes an iPad mini and a Samsung Galaxy S II.

HildyJ

I am in the same situation as you. Tasker cannot turn off 3g on my stock, unrooted GSM Galaxy Nexus. However, DS Battery Saver has no problem turning it on and off. Any idea why Tasker can’t do this as well?

Andreas Ødegård

I would assume that whatever API Tasker uses isn’t supported on certain devices, while other apps use other APIs

Shiva

Thanks a ton for this request.. I will test it right away and keep you posted on how it works..
One suggestion though: Turning 3G off on a SGS2 is possible using APNDroid and selecting Mobile Data APN from the action Net.

Alessandro

Many thanks for your post. I have read carefully instructions..but I wonder: the Secure Settings configuration “mobile data” seems to me that only “cuts off” mobile data and not force the phone to toggle from 3g to 2g (and viceversa). So the phone is still connected on 3g network (high battery drain)…Am I right? Anyway I learned a lot from your work.
Thanks again.

Andreas Ødegård

I don’t know. I always buy devices with enough battery power for my use, and I just leave everything turned on all the time for my own devices. As such, battery drain is not something I ever look into.

Michael

Hey Andreas!

I too am a Tasker fanatic and enjoy reading, and learning from your posts.For this I thank you!

I have an additional question about this automatic 3g on/off profile. I recreated this for my own SII. It works perfectly, but it made me wonder wether these profiles need to toggle ‘Auto-Sync’?

I thought the auto-sync would still try to get information from online sources every x number of time.

Is this true? Or doesn’t Auto-Sync do anything when there’s no internet connection?

Andreas Ødegård

Unfortunately I cant comment on the behavior, as like I said in the article, I dont ever turn anything off, sorry

Michael

No problem. Thanks for replying.
I’ll have to browse the Google Tasker groups.

javeed jalal

Could you help me setting up the tasker in following way :
when screen is off mobile switches to 2G but when screen is on the mobile switches to 3G.But when screen is off during calling,3G data stays on.