Different "script modes" depending on arguments

I have a script that I use to wrap calls to my shades to deal with an issue with them (they sometimes need to receive a command twice). If I call this script for two different shades, I want it to run in parallel. But, if the script is called for the same shade twice, it should be queued.

Is there any way to do something like this?

Make two scripts

I have more than 10 shades… I’d rather not make a separate script for each one.

Is there no way to say the script should queue for the same variables but otherwise run in parallel?

Not possible because the mode option applies to the entire script/automation and doesn’t support templates.

Sometimes replicating stuff is the fastest way. I gave up on fancy automations a while back and instead use shell scripts to generate yaml for cases like yours.

The other option is to allow the script to run in parallel and do the parallelism control in the automations.

There’s also some fancy stuff you could do use input booleans per shade to track if the script is already running and wait for the input boolean to clear. This gets complicated quick to handle items like the script failing.