Passing variables through pistons


#1

1) Give a description of the problem

I am having multiple issues with executing a piston from within another piston as the variables do not seem to be properly passing through. I have looked at the community, but haven’t been able to find any solutions.

I basically have a number of dimmers that come on/off at pre-defined intervals, the actual timings vary, but the basic logic is the same. I want to cut down on the number of different pistons I have to maintain, by using one Master piston that sets the parameters for each device and then calls the same Slave piston with different variables.

2) What is the expected behavior?

If you look at the Master piston code, it essentially sets Start and End Times, the actual device being called and the duration for each pre-defined dim level (and they are getting passed correctly).

3) What is happening/not happening?

I have at least two separate issues:

It’s not working! I have turned on parallelism on the 2nd (Slave Piston), but as long as I have more than 1 device the first one always fails.

In addition, although the device name passes correctly from the calling (Master) piston, what ends up getting passed to the piston that is being called is the address (not the device name). I found a workaround by using a switch statement to set the proper device name, but I’d rather not have to.

Any help would be greatly appreciated!

**4) Post a Green Snapshot of the piston![image|45x37]

Master Piston

Slave Piston (being called)

5) Attach any logs (From ST IDE and by turning logging level to Full)

Master log (partial)

Slave log (partial)


Pass the name of $currentEventDevice as an argument to another piston
[SOLVED] Tasks not executing in parallel
#3

are you calling the 2nd piston with multiple devices passed in via args. or do you mean first one as in the first call to the 2nd piston fails?

in the piston that is being called have you tried assigning what is passed in to a device variable?


#4

No each device gets passed separately, in this example it’s 2 devices and I can tell from the notifications that the variables get passed correctly each time the 2nd piston is called.
The variable that should control the actions are setup as a device in both pistons. When I receive the device variable (CurrentSwitch) in the Slave piston, it comes in as as the address and not the name, that’s why I needed the switch statement.


#5

please clarify this part.

yes but you are using a switch statement there. tried assigning the args.currentswitch to the device variable directly?


#6

Yep, have tried multiple times, just tried it again and all I get is the address


#7

share a green snapshot of what you tried please


#8

Here you go:

And a screenshot of the notifications. It says [XXXX] device not found.


#9

i was looking for the thread where this was asked earlier … see here:

yeah its fine that you see the device hash … just try on/off on that device variable.


#10

thanks, looking for the exact syntax now, if you have it handy somewhere please share!


#11


#12

Thanks, but that’s not going to work, when I define the switch variable it doesn’t recognize it as a valid device. I thought you meant to do a ‘with location’ and then set each attribute in there. See screenshots…



#13

lines 30 - 32 will not work and is the reason for those errors in the log.

if you do this it should work:

with switch
   do turn on
end with

#14

Nope, no joy. I had tried this multiple times in the past few days. My local variable is not getting recognized as a device.



#15

lets try this:

  • line 21 just define the device variable dont set it
  • at the top of the piston
    – log the value of args.currentswitch
    – set device variable to args.currentswitch
  • with device variable turn it on

what happens?


#16

I have already tried this a few times as well, still will not recognize it as a valid device. I will try again


#17

try this:


#18

Thanks, this didnt work either


#19

share the logs please.


#20

there you go



#21

please execute the version i shared. need to see what happens when those first few statements are executed without digging thru all the conditions to understand where its failing.