[TASKER] [ROOT] Switch to 2G Network when your device is connected to WiFi

The 4G network in your phone is the single biggest source of battery drain apart from the Android OS and the LED screen. LTE is faster but it maintains parallel transmissions between your device and the tower it is connected to. This results in huge battery drain. Engadget noted that Google maps running on a nexus device over LTE network drains battery faster than a car charger could restore it. Also, GigaOm has an excellent write-up about why LTE sucks.

LTE networks aren’t very densely built-in most countries and our devices keep scanning for them – reaching out to the farthest LTE tower available and hence draining battery. That said, you don’t really need a 4G network 24/7 and you definitely do not need those scans to happen when you are connected to a WiFi network.

The best way to save battery when you are connected to a WiFi network is that you switch your preferred network type to 2G which is extremely stable. Doing this manually every time you connect to WiFi can be a hassle – and hence you can use Tasker for this purpose. Toggling the preferred network type via Tasker is a 2-step process except that you need to have root access on your phone.

Create a Tasker Profile To Detect WiFi Connection

Fire up Tasker on your phone and tap on the plus sign to create a profile. Select State > Net and then choose WiFi connected option. You should see the following screen:

Leave the SSID blank which means that you need the task to run when your device is connected to any WiFi network. If you wish to switch to 2G only when your device is connected to specific networks, you can specify the respective SSIDs separated by comma.

Create Task to Switch to 2G

When you go back, you will be asked to enter a Task name. Enter “Switch to 2G” or anything else you are comfortable with. In the next screen, you can create a list of actions that should run when your device enters the state you defined in your profile. Tap on the plus sign and in the Action Category choose Code > Run Shell.

In the next screen, you will be asked to fill up the command to be executed. Following is the shell command that switches your phone’s preferred network type to 2G.

settings put global preferred_network_mode 1

global is the namespace of the setting you need to modify and preferred_network_type is the actual setting you wish to change. Setting this value as 1 means the preferred network type will be set to 2G, setting it to 9 will set it back to 4G – but we don’t need to take care of that because the setting will be reset to its original value when your profile exits (in this case, WiFi disconnected). So if your preferred network type is set to 4G initially, this setup should work for you ideally.

Make sure you check the option “Use Root” in the screen where you enter the command. Here’s how your action screen should look like:

Once you’re done with this, your device will switch to 2G automatically when it is connected to WiFi and will fall back to 4G when it disconnects from a WiFi network. In case of any questions, do let me know in the comments below and I’ll be glad to help you with it.