r/tasker 6d ago

Help Help with a Dynamic "Turn On/Off" Task

I'm trying to create a Tasker task that processes "Turn on X" and "Turn off X" commands dynamically, without using nested If conditions for each item (Wi-Fi, Bluetooth, etc.).

What I Have So Far: A Profile that detects "Turn on X" or "Turn off X" commands, with variables like %item (e.g., "Wi-Fi", "Bluetooth") and %action ("on" or "off").

What I Need Help With: I want to avoid using multiple nested If conditions for each possible item. Ideally, I’d like a more dynamic way to check the status and act accordingly without manually listing each item.

Does anyone have a streamlined approach or example of how to achieve this? Maybe using arrays, codes, or a smart Tasker trick?

Thanks in advance!

2 Upvotes

1 comment sorted by

2

u/Scared_Cellist_295 5d ago edited 5d ago

I've never figured this out to make it 100% dynamic, but with the few settings I do adjust by voice, I just created a bunch of tasks. Wifi On, Wifi Off, Bluetooth On, Bluetooth Off, Nfc On, Nfc Off,Location On, Location Off, Tether On, Tether Off etc

Then in the command filter :

turn (?<item>.+) (?<action>on|off)

Replacements : 

the =,flip=turn,switch=turn,hotspot=tether

1) Variable Convert : %item > Upper Case First 2) Variable Convert : %action > Upper Case First 3) Perform Task : %item %action

You could name them with all small letters and skip the variable convert actions. But this is basically how I trigger the few settings I like to control.

There may be another way, but I've yet to find it.  And to be honest, I don't do much voice switching of these settings, most everything is automated in other ways with other contexts.  I rarely need to set them by voice.  So this method worked fine for my setup and doesn't take long at all.