Function to turn on lights and off with timer


#1

1) Give a description of the problem
Trying to create a function to turn on devices and turn them off after x time. Different pistons will use this function. It seems like the time is overridden every time a other piston gets triggered even with parallelism turned on.

On a side note, i would also like to pass a list of devices directly with the arguments but this doesn’t seem to work. Only works for 1 device, not multiple devices. Anyone got an idea on this aswell?

2) What is the expected behaviour?
Each piston would create a new instance of the function with each a own timer.

3) What is happening/not happening?
Timer get reset by other pistons.

4) Post a Green Snapshot of the pistonimage

5) Attach logs after turning logging level to Full
(PASTE YOUR LOGS HERE THEN HIGHLIGHT ALL OF THE LOGS AND CLICK ON THE </> ICON TO FORMAT THEM CORRECTLY)


#2

In the piston options there is an option to make the piston not “cancelable”, turn it on (can’t log in to webCore at the moment to give you a screen shot). As to your other question, have you tried passing the piston an array of devices (not the device names) as an argument?


#3

Can you show the definition / setting of the global variable? (In piston view, under variables)


#4

I’m unsure what setting you mean:


I tried to pass the devices directly in the main piston:

and in the control lights i use the arg.turnOnDevices but this gives a null error. It does work with passing only 1 device though with some extra code to remove [ and ]

So what does not work:

Error:
image

This does work with only 1 device with extra code though (already tried this for multiple devices and also removing spaces):
image


#5

What would be wrong with the global? I set the local var immediately with the global and use this in the sub piston. Changing the global afterwards shouldn’t interfere with the set local var right?
image


#6

These errors show that the piston variables are not updated to match devices present on your system.

So the settings of the variable needs to be updated to show devices.

ie the :asdfasdfasdfadsf: suggests the device is not available in this webcore.

This happens when you import a piston, but don’t edit it to match devices to the current installation.


#7

This is not possible because i set the variable from a other piston and all devices are available in the pistons/webcore instance. Please check my answer to thebearmay for extra info what i have tried before.
I set a variable in the main piston

And give it as arg to the other piston:

Logs:
image


#8

It looks like the passed args is json, so you might try a parseJson(arg.xxxx) to see if that converts it back.

(I think the result of parseJson is put into $json variable)

I’ll have to try to test this further when I have time.


#9

Doesn’t seem to work
image

image

Also tried to remove the brackets:
image

Also tried removing the quotes:
image

Arguments look like this:
image

Documentation:


#10

so parseJson is a command

parseJson($arg…)
then use $json as the result.

I’m guessing you need to remove the {}

ie the string to pass would look like “[:sdsfsdafdf:, :asdfasdfasdf:]”


#11

No luck… Removed the { }:


#12

This is not how webcore works. There is only one piston. So if you call it from one function with one set of devices and then later call with a different set of devices, the later set will override the earlier set. It does not create “new instances” of the “function”. There is only one piston and it is run by every piston that executes it.


#13

Could you explain what parallelism does then?


#14

Well, I stand corrected. Parallelsm does allow multiple instances of a piston to spawn but I’m not sure if it can truly track those across waits. @WCmore may be able to shed some light here. I never use parallelism so am not familiar with the intracacies.


#15

I never use parallelism with WAITS… and rarely use it in other cases.
I like my pistons streamlined, and intentionally code so it completes everything before the next execution.

In other words, whenever possible, I code so parallelism is never even a consideration.