How to create a toggleable task in Tasker

Creating a toggleable in Tasker is something I’ve mentioned on occasion before, but it’s such a useful little trick to know that I thought I would dedicate a post to it.

When using Tasker, you’ll often find yourself switching between various “configuration states.” You create one task that sets one or more things to state A, and then another task to set them to state B. Tasker’s profile system is even built around this concept. with enter and exit tasks made specifically to have one task for state A and one for state B.

Sometimes, however, it’s more beneficial to be able to toggle between one or more such configuration states using a single task. An example would be to have a persistent notification, where clicking it would toggle between various states, for instance various Tasker-created phone profiles. This requires that a single task is capable of containing several states and allow the user to toggle between them, which isn’t the most intuitive thing to set up, but actually very simple to do.

The key here is to use variables. Invent a new variable name specifically for the toggleable task, like for instance %Toggle for the sake of this example. Creating a toggle then becomes a matter of setting up a simple if/else scenario. For creating a task with two different states, the basic task would look like in this screenshot:

Screenshot 2013 03 29 03 14 46 - for some reason we don't have an alt tag here

What basically happens here is the following:

If %Toggle is 1, it sets %Toggle to 0. If %Toggle isn’t 1, it sets it to 1. This means that every time you run the task, it will alternate %Toggle between 1 and 0.

All you then have to do is place your other actions in the same groups (If and Else groups), like shown with Flash actions in this screenshot:

Screenshot 2013 03 29 03 17 28 - for some reason we don't have an alt tag here

The result is that it will alternate between running the contents of the two groups, as you can see in the video below:

You can put as many other actions in the groups as you want, and create complex configuration states that you can toggle between. You can also expand this to toggle between more than two states, which is just a matter of adding more If and Else actions. Below is an example of a task that toggles between four different states:

toggleable multi state task - for some reason we don't have an alt tag here

Do note that there are several ways to do achieve the above. Instead of nesting the groups in a If/Else If pattern, you could just create individual If/End If groups, if you prefer that. You can also use Variable Add in place of the Variable Set actions for all but the last one, which would need to flip it back to the first variable state. The end result still gives you a toggleable task. The more toggle states you add, the messier the task looks (especially with the nesting method), but as long as you don’t panic, it isn’t as complicated as it looks.

I personally use this toggle system for a ton of Tasker setups, especially when dealing with any situation where I would run a task directly, rather than using a profile. This includes running tasks from scene elements, from home screen shortcuts, or from widgets. Some of my Tasker widgets on my new Sony Smartwatch rely on this little trick to be able to toggle things in Tasker, and it works great.


Pocketables does not accept targeted advertising, phony guest posts, paid reviews, etc. Help us keep this way with support on Patreon!
Become a patron at Patreon!

Andreas Ødegård

Andreas Ødegård is more interested in aftermarket (and user created) software and hardware than chasing the latest gadgets. His day job as a teacher keeps him interested in education tech and takes up most of his time.

Avatar of Andreas Ødegård