I thought that I understood $args in webcore. But I may not have the grasp of it that I thought. Is there a tutorial about $args? I read several posts here but nothing really explained it. I can figure out how to use it. My question? Why would I use $args?
You don't need to use it directly, but if you choose to set a variable to the value of an argument that was sent when calling the piston, you can see it is just a value in the piston $args map. I guess you could call it that way in an expression, but I always just set variables for arguments to be set when the piston is called.

I don’t use $args. Should I be? Why?
Maybe an example will help.
I have one piston that handles all of my Echo Speaks calls for motion or open doors or washer/dryer activity - uses different devices and volumes depending on time of day, etc. Calling that piston have a number of other pistons that handle the initial trigger to perform various activites related to the sensors' triggers and then pass a couple of arguments, including the message to the Echo Speaks piston.
The organization and flow works for me, but I will admit that it may seem overly complicated from the outside. (Was needed when I did my first setup on ST and was using close to 200 pistons to run things - down to around 20-25 now.)
Thanks. Your example makes sense. I can definitely see why someone would use $args to pass variable arguments to the same piston, without having to code each individual action/response.
One example, when I ran everything from Webcore, was that I had a scene scheduler piston, that was based on a list of timers for scene changes. When the timer for a scene fired in that piston, it called the scene executer piston, and sent the scene to run as an argument for the scene executer to run that scene.
Having generic pistons that run off the args sent to them, avoids repeated code, acting sort of like a method you would call with code, except the piston can't return a value to the caller.
I have multiple subroutines that I call from various pistons.
One handles all Speak calls and I pass the text and Chromecast group via $args.
Another does all the blinds and I pass Open/Close and what blinds to act upon.
I also pass the name of the piston so when I’m debugging I know who called he subroutine.
$args has been great for reusing code. My only wish is that it could return a value like a Function but I’m being picky. ![]()
I sincerely appreciate this question. In my current situation, I have lots of duplication or band-aid approaches with global variables. We are moving into a new house in a few weeks and this will help me to rethink my approach.
For those looking for a really succinct example, below is an example (pulled from the webore community) that made it click in my head:
I have looked at this example several times. I do not see the results of the receiver piston.
The demonstration of syntax and the assignment of the device variable were enough to get me thinking. It also shows that devices can be passed as a list or array (not sure which might be appropriate here).
It will be a month or so before I can really dive into this but will try to remember to share anything interesting or useful that I learn.
I see.
