Completely automate your Android device with Tasker

Alberto Piras
Geek Culture
Published in
7 min readJul 23, 2021
Photo by Azamat E on Unsplash

Tasker is a powerful tool that allows Android users to perform operations called Tasks when it detects specific conditions described in a Profile. The best thing about this is that you can create profiles for every situation you face daily.

Here I’ll explain how I’ve set Tasker to perform automatically the operations I need my phone to do every day.

Requirements

You’ll need Tasker installed on your Android device and an analysis of your habits. Good knowledge of Tasker actions is required.

I’ve also used some actions that need root access to change the device settings.

Update 29/07/2021: You can now use this tool (download and source code) the developer of Tasker just published to bypass this limit.

Original: You can grant some ADB permissions to Tasker to bypass this limit. Read more about it on this Reddit thread or the ADB Wifi Permission page.

Step 1. Understand your habits

During the year I have a work mode and a holiday mode.

In the first mode:

  • I wake up and go to sleep every day at the same hour.
  • I start and finish working and have my lunch break at the same hour.

In the latter, I have no specific timetables.

Sometimes a week I also go to the gym and to move around I drive my car. These two things happen independently of the mode.

Phone settings

I have some settings profiles based on the situation I find myself in.
First of all, my phone always has the alarm and in-call sounds at full volume. The display rotation is also off all the time.

At night, I turn on wifi, turn off mobile data, enable the do not disturb mode, mute the media volume, disable location services, turn on the battery saver and disable auto-sync.

At home, I turn on wifi and enable location services.

At work, I turn on wifi, disable location services, enable the do not disturb mode, set the media volume to mute, disable location services and disable auto-sync.

When I am at the gym, I enable the do not disturb mode, mute the media volume, disable location services, and auto-sync.

When I am in the car, I set the media at full volume.

I then set mobile data, location services, auto-sync turned on, do not disturb mode disabled, battery saver turned off in every other situation.

Step 2. Create the tasks in Tasker

I have defined the following tasks:

  • Base: with the general settings of my phone.
  • Home: with settings for when I’m home.
  • Work: with settings for when I’m at work.
  • Night: with settings for when I’m sleeping.
  • Gym: with settings for when I’m at the gym.
  • Car: with settings for when I’m in my car.
  • Default: with settings for every other situation.

In each task, I set the “profile” name and a priority number in a variable. The first is related to the situation I am going to use the task. I will use the priority later to automatize the tasks; higher priority tasks will win over lower ones.

My tasks call the Base one, using the Perform Task action, passing the profile name and the priority number. The Base task reads these two parameters (%par1 and %par2) and sets them in their respective variables. It also set the execution time in another variable, called %profileStart.

You can download the Base task description here and import it in Tasker from here.

After creating all tasks, I have something like this.

Step 3. Create the profiles in Tasker

As I said before, I have two modes: Work and Holiday. I have also added a third one called Off to disable some automation, just in case I need it. I have created a variable to store the mode enabled.

When Work mode is enabled, I have the following conditions. The Work task runs from 8:30 to 13:00 and runs again from 14:00 to 17:30. The Night task starts at midnight every day but ends at 07:00 only during the weekdays.

I’ve described some conditions according to the time, but you can do the same thing, for example, when you connect to your work wifi network.

In Holiday mode, I only need the Night task to starts at 02:00.

Regardless of the mode, I run the Car task when I connect to the Bluetooth of my car and the Gym task when I am at the gym. The Home task runs when my device connects to my home wifi.

The Default task runs when all of the other ends.

Here are a few of the profiles discussed before that runs at a specific time and day.
These are other profiles that run with different conditions. The first profile runs when a Wifi network is connected, the second when a Bluetooth device is connected, and the third when a wifi network is near. The last one is a condition based on the location; you can read more here.

Step 4. Priority management

Now the automation is working, but some conditions may overlap.

For example, what should happen when I need to drive my car during working hours? Should it start the Work task (triggered by the Mornings/Afternoons at Work profile) or the Car task (triggered by the Car profile)? If the Car task wins, the Default task will run instead of the Work one on the first profile exit.

These confusing cases are the reason I have defined a priority number for each profile. N.B. I have not used the Launched Task Priority in the Profile Properties. This way, I can also start each task manually.

I have defined the following priorities, and remember, a higher priority wins over a lower one.

  • Home: 1
  • Work: 2
  • Night: 3
  • Gym: 4
  • Car: 5
  • Default: 0

I can now add a condition for each profile I’ve defined previously so that a task runs only if the priority is lower than or equal to its own.

In the last two images, the second condition is the %profileMode in AND with the %profilePriority.

Profile end

Now, when the Car task runs, and we are in the scenario I’ve shown at the beginning of the step, the priority rise. The Work profile exits and runs the Default task, creating more confusion.

To fix this issue, I have created a generic exit task called Profile End. This task receives the name of the exiting task as a parameter and, if no other has run in the meanwhile, it lowers the priority until one runs or it reaches 0 and starts the Default. By other profiles, I mean a profile with a different name and a lower priority or the same one but ran later.

You can download the Profile End task description here and import it in Tasker from here.

In the following image, you can see the Profile End flow that happens when Work and Car conditions overlap. The circles are the conditions, the rectangles are the tasks running, and the orange rectangles explain what happens.

Step 5. Change mode

In Step 3, I’ve created the variable %profileMode to define which tasks should run. To change mode without changing the variable manually, I have written a task to add, for example, to the home screen.

Furthermore, I have a calendar event for every day I am in Holiday mode. Therefore, I have created a condition to change to Holiday mode at the beginning of those events and then switch back to Work mode at the end of them. It also enables and disables my Fitbit alarms. You can read more on how to do it in this other article.

The first screenshot is the task to change mode, the second shows my condition, and the third is the task that automatically enables Holidays Mode and disables my Fitbit alarms.

Step 6. Create a Scene

Using Tasker scenes, I have created a popup to start manually all the tasks I have shown before. You can read more about it in the Scenes user guide.

I have a quick setting that opens this scene. It allows me to run, in the first row, Default, Home, and Night tasks, and in the third row, Gym and Work tasks. The last button on the third row shows the current mode, stored in %profileMode, and a click runs the Change Mode task. The central row has some information, such as sunrise time, current task, stored in %profileActive, and sunset time.

--

--

Alberto Piras
Geek Culture

Software development engineer at Amazon. Thoughts and articles are my own.