Global Variable not Setting Properly


#1

1) Give a description of the problem
I have a simple piston which turns off water when vacation mode is enabled, and turns on water when vacation mode is left. I have a global variable (WaterShutoff) which changes as well. The water shuts off perfectly fine, but the variable does not set.

This post here seems to be quite similar. Here

I tried the wait as the last post suggests, with no luck. I also tried an exit at the end, but it did not work either.

I do have to say this used to work really well. Up until this last weekend when I changed the location mode to vacation it would not update properly. The weekend before I used it too, and it worked just fine from what I can remember.

Just for context, this variable is used in an expression to let me know if the water has been shutoff. If I press a button on my phone it sends me a notification with the location mode, water status, and other statuses. Seemed to be working good from when the piston was designed up til this point.

Has there been any changes to Webcore or Smarthings that could have made this become an issue?

2) What is the expected behaviour?
When location mode changes to vacation:
Turn off water, turn on motion override, set WaterShutoff to true

When location mode changes from vacation:
Turn on water, turn off motion override, set WaterShutoff to false

3) What is happening/not happening?
The WaterShutoff variable is not setting.

When the piston is ran (and when I had a wait at the end (5s)) I could see the variable change in the variables box, but once the piston finished, it reverted back to its old value.

**4) Post a Green Snapshot of the piston

5) Attach logs after turning logging level to Full
Log 1 below is when entering Vacation Mode
Log%201%20Entering%20Vacation%20Mode

And Log 2 is when Leaving Vacation mode


#2

Your description of the ā€˜waitā€™ suggests the piston has written the global variable correctly (twice) but that it is being changed back again almost straight away by something else.

Is the global variable being used by other pistons, and could they be messing with it?

Sorry, I see you have already said it is being used in an expression. Perhaps that needs looking at more closely.


#3

From what I can remember this is the only statement where the variable is used. Well I actually have 2 of these because one statement has a wait in front of it, and the other does not. So this exact notification is used in 2 separate if statements in the same piston.

Hereā€™s what Iā€™ll do. I am going to disable all of my pistons except this one and the location changing one. That way if there is any interference, it would take it away. I will report back once I have tested.


#4

Well it looks like something is messing with it.

I have only enabled the Vacation Mode Piston (one shown above), my location mode piston (which changes between vacation and away based on a virtual switch), and my status report piston (which sends the notification based on location mode change).

It works as advertised with only these pistons enabled. I am going to slowly start enabling pistons to see what could be messing with it, and hopefully find out why.


#5

Well found my culprit. It seems my thermostat controller piston is messing with it. Though I have no idea why. The Variable WaterShutoff isnā€™t mentioned in the piston once.

Just got an ecobee installed last week (switched from nest) and began building this piston up to control it based off of my and my wifes locations. It seems to be fully functional, but donā€™t know why its messing with my other piston. I know it references vacation mode quite alot, so Iā€™m thinking thatā€™s why. Iā€™m going to keep looking at it, as I noticed something else I want to change on it (though unreleated).


#6

Vacation mode is though possibly the cause?


#7

Most Likely. Havenā€™t had much of a chance to look into it, but I may start another piston and rewrite it to see if that helps too. I typically end up doing this after my first draft piston to improve efficiency. I also noticed it had a few waits at a semaphore yesterday and 2 days ago so I want to do what I can to prevent those too.

But if anyone thinks of anything in the meantime, or wants me to try anything Iā€™d be happy to help as I can


#8

Ok so in my thermostat controller piston I was setting a Global variable called Thermostat to what my thermostat was going to be set to. This I am also referencing in my status update piston (same expression that the WaterShutoff variable uses)

I removed setting the thermostat variable in that piston, and now it works. Is it because the pistons both run at the same time (location mode changing) that could be causing this?

@WCmore I believe once told me that you can only set a global variable once per piston run thru. Does this issue Iā€™m seeing have any relation to that?


#9

If two pistons are running at nearly the same time, and both are writing to or reading from the same @global, then yes, there is a good chance that one piston may write new data after another piston has already read the old data.

Normally, a @global is not written until the very last line has executed.


#10

That helps, though they are writing to two different global variables. One is WaterShutoff, and is a true/false value; and the other is Thermostat which is a dynamic.

Does it make sense that one being written could ā€˜mess upā€™ the writing to the other? Especially if it is happening at nearly the same time?


#11

I donā€™t believe so, or at least, I have never seen this happenā€¦

Although, to be fair, I make it a strong point in all of my programming to only use a trigger once, so only one piston fires at any execution.


For example, I might combine the following:

pic

into your complex ā€œee2uā€ piston aboveā€¦ Since they share the same trigger.


#12

Ironically, this is how my Vacation Piston came to life. I ended up merging when it changes to and from vacation mode into one piston (as I had it separated before). The more I think about it, I will probably break up the temperature controlling into pistons I already have for controlling location mode changes.

Well back to re-configuring my stuff haha but this should solve the problems I am seeing


#13

I was trying to think of a way in which a status update piston might confuse the issue, but even if it subscribed to both of the global variables and had a convenient ā€˜waitā€™ in the middle of it, I couldnā€™t think of a failure mode that would change the global variable. Display the ā€˜wrongā€™ value in a notification perhaps, but not actually change it.