-
nickthejam liked this
-
brendaca83 liked this
-
eafarris posted this
Android automation with Tasker
Introduction
When our AT&T contracts were up for renewal last fall, I decided to eschew the iPhone and get an Android phone to use for the next two years. I chose what was (at the time) pretty much the top of the line for AT&T, the Samsung Galaxy S II (SGS2). Overall, I’m very pleased with the phone. There are times that I wish I still carried an iPhone (mostly for the great games and media experience), but there have also been times when I’ve used my wife’s or one of my sons’ iPhones and it enforced the things I truly like about the SGS2 (mostly the keyboard and larger screen).
But if I had to choose one thing that makes this Android phone a slam dunk for me, it would be a little app called Tasker. With Tasker, many parts of the phone can be automated. I’m an old Unix guy. Shell scripts are my thing. I love Automator on the Mac. This thing is right up my alley, and it’s made the phone a much greater experience than it would have otherwise been.
Brief overview of Tasker
Tasker has been covered at great lengths in other places (it’s a particular favorite over at Lifehacker), but generally speaking it’s an automation tool for Android. Tasker is divided into two main areas: Profiles and Tasks. Profiles can be triggered when events happen, like an incoming call, an app is started, or a connection to a Wifi network. Tasks run when those Profiles are active. Tasks can do things like adjust the screen brightness, volume levels, and even things like send an SMS. It includes a location section, where GPS or cell towers can be used to set up geofences which can trigger tasks. Tasker’s recently grown to include a dialog box builder that can create specialized ‘mini-apps’ using profiles and tasks. It also includes a powerful variables system that can read information on the phone, like the name of the Wifi network you’re on, the last number that sent you an SMS, current battery level, date/time, etc. You can also create and manage your own variables.
So, in the plainest sense, Tasker runs in the background waiting for a Profile to become active, then runs the Tasks you’ve associated with that Profile. Profiles can also have a set of Tasks that run when the Profile exits.
Simple automation
Flashlight
A simple Tasker Profile I’ve set up that has proved very valuable is a flashlight function. Tasker can control the “Torch,” which is the LED flash on the back of the SGS2. I set up a Tasker Profile so that when the phone is shaken, the Torch toggles on and off. I find this quite a bit better than flashlight apps that require you to find the app and tap on it to get it going. With minimal dexterity, I can pull the phone from my pocket, unlock it, and give it a shake.
Variables
I have Profiles set up that set a variable I can use to roughly tell me where I am. I’m at home if I’m connected to my home Wifi network. I’m at work if the phone can hear certain cell towers (I can’t rely on Wifi at work, since there are parts of the building without network access). I’m at my parents’ house if I’m inside a GPS-specified geofence. GPS is much more accurate than cell towers, but at work I can’t rely on getting a GPS signal inside. And even cell towers isn’t all that great, but it’s the best of the solutions I’ve come up with so far.
All of these set a variable so I can easily access it in other Profiles. I also set the variable to “Driving” if GPS determines I’m moving faster than 20MPH.
Using Variables
One way these variables come in handy is checking them in other Profiles. For example, I have a “Plugged in” profile that is active when the phone is attached to a power source (I find myself having to plug in the Android phone much more often than I did my old iPhone 3GS. But I’m doing a lot more (like Tasker) with it.) When the Plugged in profile becomes active, I take a few steps:
- Have the phone literally speak “Now Charging.”
- Lock the phone. Here I use the variable along with the IF statement. I don’t lock it if I’m at home (according to the variable).
- Set the Display to not timeout (that is, stay on)
- Turn Wifi on. Don’t really care if it was before or not, just turn it on.
- Turn on GPS. This takes a rooted phone and the “Secure Settings” app, since Android 2.3+ doesn’t allow software to fool with the GPS radio.
There’s an exit task that runs when the phone is unplugged. It resets the display timeout and turns off GPS.
Quiet and power savings at night
I have a set of Profiles and Tasks that keep the phone quiet at night and also attempts to save battery by turning radios off and on at set intervals. Tasker can have Profiles active via time of day, and can repeat Profiles on set intervals. So, I have “Night quiet” and “Night data” Profiles that are active during night hours. The “Night data” Profile also repeats during these hours.
Night quiet simply shuts off all sounds. This Task is a saved task called “All Quiet”, so I can reuse it in other Profiles
Night data is a bit more complicated. It has to do a few things. First, it needs to turn radios on, and start an auto sync. Then, it waits for five minutes. This gives auto sync time to work. Then, it turns the radios back off. Tasker repeats this every half hour during night hours. In this way, the radios are on only 10 minutes out of every hour, resulting in a lot of power saving.
More sophisticated automation
As you can see, Tasker is a very powerful way to have a lot of control over your phone. But those are relatively simple automations compared to what Tasker’s actually capable of. See some of the step throughs in the Tasker wiki for more examples, and many more complicated ones. Tasker can even connect to HTTP URLs and act on the responses.
I do have a one more advanced Tasker setups I use. I want my phone to act differently if I’m in a meeting or otherwise busy (like, at a concert). Tasker can read and respond to calendar data.
The Tasker Profile I use for this is called “In A Meeting”, though it’s really just responding to busy times in my calendar. This Profile is active if there’s a calendar event currently active that I’ve marked as “Busy” in Google Calendar. In this way, Tasker automatically activates this Profile based on how I’ve set up the Calendar event, either as Busy (where it’s active) or Available (where it’s not).
Now, when I’ve marked myself as busy, I don’t want to be disturbed. But, at the same time, I don’t want people that are texting me to think I’m avoiding them. So, this Profile needs to do two things: set all the volumes to zero, and automatically respond to incoming SMS messages.
The Volumes thing I’ve done already, with the Night Quiet profile, so I simply reuse that named task, setting all volumes to zero.
The SMS thing is just a little bit trickier. I need another Profile to be active, one that’s fired when an SMS comes in. But obviously, I don’t want that Profile to be active for every text, just texts that come in when I’m busy. First, the “Busy Return Text” Profile.
The “Busy Return Text” Profile is triggered when an SMS comes in. The Task it runs has only one action, the “Send SMS” action. It uses the %SMSRF variable, which is the number the incoming text is from. This is a read-only variable that Tasker automatically keeps track of. Then I give the action the auto response text to send. Included in the text is the sentence that “This is an automated text.” so people know I’m not being gruff with them, my phone is responding in my behalf.
Now, the trick to this is getting this Profile to only be active (that is, allow it to only be triggered) when the “In A Meeting” Profile is also active. Tasker, of course, makes this simple: Profiles can turn other Profiles on and off. So, in the entry task for “In A Meeting” Profile to turn the “Busy Return Profile” on. That doesn’t mean it actually runs, it’s just available to be run if it’s trigger state happens. An exit task for “In A Meeting” sets the text Profile back to off, in addition to resetting the volume levels.
Summary
Tasker is a marvelous addition to my phone. It at once scratches my itch to fiddle with the technology, while also letting my phone be less fiddly. The whole “mute-means-mute” discussion that, while being iPhone-focused, is certainly not limited to iOS, is pretty moot to me, since I’ve already told my phone how to behave if I’ve told it I’m busy. And the great thing is I didn’t have to explicitly tell the phone I was busy, it knows I’m busy because it looked at my calendar. Yes, I’d love to see something like this in future versions of iOS. I am sure it’s something Apple would have to build in, since an App that tried to pull such stunts would be quickly rejected. But I’m pretty confident that Apple would ever do such a thing. Apple is very happy to have the iPhone act as an appliance, with limited, but very predictable, actions and features. I do appreciate that approach. (I carried an iPhone, after all; My wife and sons carry iPhones; I’m first in line for a retina-display iPad). But I also very much appreciate the fiddliness and control I get over the device with Android. Tasker is a very big part of what I like about my Android phone.