Update global variable in calling piston, then call a piston to use them doesn't work


#1
  1. Trying to update a global varialble, then use it. Need it to be global for other pistons. How do I do it?
  2. Global variable to update quickly, seconds at least, not after the end of the called piston.
  3. Variable not updating until called piston is done.

Putting in waits is not my ideal solution, but I am trying that next, but I’m worried that global variables don’t update until all the called pistons are finished, which makes linking them not the best idea. If I can’t link, then I have to subscribe to more stuff which I don’t want to do. But then I might as well put them all together, but the piston becomes unwieldy. I really want to separate these for function, and call from each other and pass a little data using global variables. :confused:


#2

that is the expected behavior.

is calling the other piston from this piston with the new value of the global variable as a param, an option?

if you check the execute piston task, it says the same:


#3

Well, I’d have to learn how to do that (I don’t mind that too much), and it would be more complex (since I have a global variable, why can’t I use it?).

What confuses me is why the calling and callee piston run in the same “space”. Shouldn’t the caller piston close up shop right after it calls the callee piston? What is it waiting for, I don’t have “wait for called piston” set (which is an option). I could understand if I had that set why it would behave like it does now.


#4

see my edited post above. it explains how.


#5

Sorry, but I have mine set to “false”. In other words, it’s not waiting, it’s just calling. So it calls and should just close shop immediately (or pretty darn quick.). Unless global variables take a lot of time to set, and are set at the very last operation of the closing piston, it should work.

It’s ok if it doesn’t work the way I want (sort of, I’d suggest global variables get updated as quick as possible) but I feel like it should work the way I think if I have “wait for execution” set to false.

In other words, I’m not arguing, I’m just trying to be clear and get myself clear. :slight_smile:


#6

yes, but the updates to the global variables in the global state are not done by the time the other piston is picked up for execution.

how about subscribing to the global variable changes in the other piston? if you did this you wouldnt have to call the other piston, webcore would automatically execute it when the global variable change registers.


#7

I tried that. Unfortunately six different global variables can change, often two at a time. I think I was getting multiple calls to the piston. That’s why I wanted to call the piston directly. It’s changing a heating and cooling setpoint usually at the same time.

I might be able to OR the changes for each setpoint, I’ll keep thinking on that.

Meanwhile, thanks for the ideas, all are good, just hoping to align my thinking and webCore by changing one of them to the other. :slight_smile: webCore is so awesome, I don’t care if I have to break my brain, just want to try.

PS: I bet people get confused when they try to reuse a global variable within the piston as well for the same reason. There’s an expectation of immediate update from other programming languages, but I know that can’t always be the case here in SmartThings land.


#8

ok. if you share a bit more of the use case or the pistons themselves it will probably be easier to share other ideas. :slight_smile:

you are welcome.

all credit goes to @ady624

PS: given that ST is event driven nothing is truly synchronous and with webcore being a framework on ST synchronous updates would sort of be out of character. :slight_smile:


#9

This seem to relate to exactly what I am puzzling over right now, lagging global variables.
So if I want my second piston to always get the correct variable value I basically have to stop pausing and resuming the second piston and just let it keep running. Essentially removing the reference from the calling piston?


#10

without a snapshot of the pistons not sure whats going on here.

but, if one piston is calling another piston after updating a global variable, the callee piston will not see the updated global variable value till that execution for the caller piston has ended.


#11

Reviving this thought for a moment as I’m thick.
I know globals vars don’t update until the end of the callee piston so what to do…
I have a piston that arms the DSC system in the house depending on who is around yada yada.
I created a separate piston to validate all the contacts and set a global boolean var to reflect all is closed or something is open.
If I run this from the caller piston the value created by the callee is useless as it’s not updated until the end of the piston.
Is there a method to test the result of this called piston and continue with the logic in the callee piston? I don’t really want to subscribe to events making the piston to run every time there is a change to over 50 contacts just to keep the global var current.
Or, do I just have to embed the called piston code in the callee and forget about trying to modularize the pistons?
Clear as mud.