For a few months now, I’ve been using a WIFI enabled phone. It is quite useful to cut on your 3G traffic and use the cheaper (quicker?) WIFI. When I reach home, I start WIFI on the phone and 3G is stopped. And you can enjoy plumbing courses on youtube till 2am for free. However, when you live your home, your need (to remember) to cut WIFI. I don’t know for you, but myself tend to forget this step quite often. Though your home WIFI is not near, the phone keeps searching for available networks and it drains the battery.
Investigating this question, I found Tasker, an app that allows you to automate almost everything on your Android phone. After playing with it to create a good night greeting when I turn my phone upside / down at night, I embarqued on a WIFI Automator project. And yeah, it rocks. For 2 months now, I don’t have to remember to start / stop my WIFI when I reach / leave home: I’ve configuerd my Tasker to do that for me. Isn’t it cool?
The Use Case:
Before telling you how I configured my tasker, first let’s have a look at what I want my phone’s WIFI to work:
- When I get home, I want the phone to switch from 3G to WIFI.
- When I leave home, I want the phone to switch back to 3G
- When I am at the square in fron of my home, I want the phone to be on WIFI
- When I go to the corner store or the drugstore 1 block from my house, I want the phone to stay on WIFI because I’ll be back in less than 10 mins and there is no use to cut the WIFI.
- When I have to see my banker or attend a parents meeting at kids school (1 block from home), I want the phone to switch to 3G / Edge because I won’t be home before an hour at least.
- I want to minimize my battery usage
I will never forget to stop my WIFI:
These are the 6 requirements I have to my WIFI Automator. Let’s now see how to implement all that in tasker. One key part of the WIFI Automator is the way to stop WIFI. I created a profile WIFI Stopper and the associated task WIFI Stop. How does it work? According to my requirements, I decide to stop WIFI as long as my WIFI network is not within reach, that means when my phone cannot detect the said network.
The profile WIFI Stopper is composed of 2 contexts: a- Phone WIFI is activated (WIFI ON) and b- WIFI is not connected. If these two conditions are met, it can only mean two things: either my phone is in WIFI Sleep mode or my home network is not accessible. When the profile WIFI Stopper is activated, tasker starts the task WIFI Stop that runs until WIFI is stopped or the profile is deactivated. To avoid strange results when I go to my garage, come back to home and then leave, the task WIFI Stop is set to not allow multiple instances and run within a 5 mins loop while the profile is active.
To do decide whether to stop wifi or not, I query tasker’s built-in variable « WIFII » that lists all the wifi networks last seen by android. If my home network is not in the list, then my network is out of reach and I have to stop WIFI. Otherwise, I leave WIFI on to respect the wifisleep policy. [Btw, it seems it is more efficient to have wifisleep set to never according to reports on the web]. To avoid intempestive stopping, I have a 45s temporisation before trying to stop the wifi.
My WIFI will start by the virtue of Tasker:
WIFI start is triggered by the profile WIFI Starter. I want my WIFI to start when I am at home. This profile is constituted of two conditions: a- WIFI is Off and b- Cell towers covering my home are near (Cell near context). Tasker allows us different ways of monitoring location. Of all of them, I choose the cell tower way because it is the cheapest battery wise. A cell tower covers a large area, usually larger than a house. To make the best use of this location information, I organised the task WIFI Start in a stagged loop:
- For 15 mins, we check every 2 mins if the home WIFI is within reach
- After the first 15 mins, if we can’t connect and we are still under the cell tower coverage, we are probably out of home for a long time. We make a pause for 45 mins.
- After the 45 mins pause, we start the search cycle again.
- Of course, the length of each stage can be modified and you can even set up supplementary stages. For example, a stage 3 with a 2 hours pause can easily be set up.
For convenience reason, the WIFI Start task is implemented in tasker with two task: WIFI AP Search and WIFI Start. I will try to write more about it in a future post.
A few tasks to (re)initialize the system
To help this gigantic machine working well, I have two additional task. The Task WIFI Checks Params sets up all the parameters of the Automator like the names of the WIFI networks you would like to connect to, the duration of each level and each pause. The task WIFI Checks Init resets our internal timer.
How to set it up on your android
So you read until here; you deserve congratulations. To set up the WIFI Automator on your phone, execute the procedure described on Tasker Wiki.
Can someone help in converting the tasks and profiles in a plug-in?
Edit: if you want to handle multiple locations, have a look at this discussion.
Donate if you like my work.