Tasker: Use variable in "A Thing" action

Would be great to be able to use a variable for at least the command in the A Thing action. Variables for all fields would be fantastic.
I’d like to have all of my A Thing actions in a single task and pass the Thing variable and the Command variable to the task in the parameters.

Welcome to the community and thanks for posting. If you tap the tag icon in the action bar while editing the ‘A Thing’ action, the fields change to text fields that allow free form entry of command names or the use of Tasker variables.

Hi, sorry for reviving an old thread, but I’m trying to do this and I seem to be missing something. I have a light that I’m trying to set the level to a variable, and the level is not being affected.

I’m just hard-coding the %dim variable to 14 for testing:

And setting the level here:

Any idea what I am doing wrong?

Thanks.

You have to tap the tag in the action bar to put the plugin into Tasker Variable mode.

Additionally, it looks like you may have ‘Override Parameters’ enabled from the ... menu and have customized the data type of the parameter. You’ll want to change that back to numeric 0-9

The Tasker Variable mode did the trick, and the level is now being set to the variable value. However, while the “A Thing” action is doing what it is supposed to, it is also flashing a “Result: Unexpected Error: 400” message each time. Do you have any guess what might be causing this? There are no errors reported in the run log.

I had the Override enabled so that I could remove the second parameter which was required by default. I didn’t realize I should turn that back off after removing the extra parameter. And I had the data type as alpha, because it wouldn’t let me save the config with a variable name in a numeric field without the Tasker Variable mode set.

Thanks.

-Scott

Glad to hear that helped!

Which Run Log are you looking at – the one built into Tasker itself or the logs in the SharpTools app? Can you share your full Tasker Profile as a descriptive export so I can better understand what the profile is doing and what actions it’s taking?

Also, do you see the same 400 error message when you use a Tasker profile with just a single SharpTools: A Thing action using the normal interface for selecting a setLevel() command? (Optionally removing the second parameter if it doesn’t work).

  • Tasker Profile Export: export the Tasker profile in descriptive format by long pressing on the profile
    • Note: You will need to have Menu / Prefs / UI / Beginner Mode unchecked.

It’s OK to leave it enabled. Removing the second parameter is required with some device handlers, so that’s totally normal. I was commenting on the data type being A-Z (alpha) as that won’t work with many device handlers.

I was using the run log within tasker. For the descriptive export, is this what you are looking for?

Task: Test Light Set
   
    A1: Variable Set [
         Name: %counter
         To: 10
         Max Rounding Digits: 3
         Structure Output (JSON, etc): On ]
   
    A2: A Thing [
         Configuration: Thing: Bed Light
         Command: setLevel
         Args: %counter
         Timeout (Seconds): 0
         Structure Output (JSON, etc): On ]

If I use setLevel with the A Thing plugin without using the Variable Mode, and just providing an integer, I do not get the error.

Yes. I don’t see anything out of the ordinary.

My best guess is ‘Bed Light’ is also matching other devices that don’t support setLevel() so it’s getting a 400 for those. Keep in mind that the Tasker Variable mode uses partial matching of the name.

[Variables] support partial matching. If you have several devices with “Hall” in their name and your device field is configured for 'hall', SharpTools will match all devices with the word ‘hall’ in the name and trigger the command on each device. (eg. Upstairs Hall , Downstairs Hall , Shallow Light)

So if you have a ‘My Bed Light’, ‘Cribbed Lighting’, ‘Her Bed Light’, then all of those are matched by ‘Bed Light’… and if one of them doesn’t support setLevel() then it will would throw a 400.

So if you have a ‘My Bed Light’, ‘Cribbed Lighting’, ‘Her Bed Light’, then all of those are matched by ‘Bed Light’… and if one of them doesn’t support setLevel() then it will would throw a 400.

Ah, that’s it. I didn’t realize that was a partial match situation. I have a “Bed Light Sim” which is a simulated switch - so no dimmer functionality. I was using that to initiate a Fade_level SharpTools macro, which I’m doing here within Tasker so that I can have an interrupt if the light is turned off after the process starts. I renamed the sim switch, and the error is gone. Thanks!

1 Like