Global variable not being set


#1

1) Give a description of the problem
Global variable not being set

2) What is the expected behavior?
Global variable be set

3) What is happening/not happening?
Global variable not being set

**4) Post a Green Snapshot

**5) Attach any logs

205ms ║║Executed virtual command setVariable (1ms)
+209ms ║║Executed virtual command setVariable (1ms)
+221ms ║║Executed virtual command setAlarmSystemStatus (8ms)

Logs show variable being set, but to never occurs. Works as expected if switched to a local variable instead of global.


#2

I just tried it and it worked for me (I stripped all of the other devices though)… also I think random() expects start and end if using numbers random(start,end).

image

image

Edit:
(expression) random(1,10) »»» (integer) 2
(expression) random(1,10) »»» (integer) 8


#3

The expression I used works fine in the evaluation console to return a random number between 1 and 3. Looking at the functions syntax, I believe the expression shouldn’t be the fault. But it doesn’t set the variable at ALL, not in either portion. Simply seeing it to local though, and out works fine. I tried clearing cache from the webcore smartapp already too.


#4

Also odd that for you, it set the value for @Random to the expression and NOT the results of the expression.


#5

That @Random variable was a result of the clip below… I imported yours, just trimmed down the other devices. I didn’t change it to integer type though.


#6

I understand, but it should evaluate the expression and save the result as the variable. It works in that manor for other variables I set and when I switched this one to a local variable.


#7

Should be bracketed with {} instead of () and set as an expression instead of value. I was messing with it a lot before posting so may have changed it before posting.


#8

This is the scaled down version I’m playing with.


#9

Hmmm, that works fine. But still, couldn’t be the expression as the @Vacation variable wasn’t set either.


#10

You’re right, it doesn’t look like it’s the expression. My first test earlier didn’t evaluate correctly due to my simulated sensor state not being set to away/present, it worked after I toggled it.


#11

I’ve already re-worked the piston to use a local variable and is working as expected, just puzzling why it wouldn’t set the global variable. I have other pistons using global variables that are working just fine.


#12

I would suggest starting fresh, from the image you posted that’s the 41st revision – something might have gotten messed up in there somewhere. Make a copy and start over :slight_smile:


#13

Yeah, it’s been ever expanding and tweaking. Thanks for the help.


#14

I don’t think I’ve edited this piston this many times lol :stuck_out_tongue:
image


#15

Holy hell! But as an update, narrowed down where the issue was coming from. I have another piston that fires when this piston turns 3 switches on or off. This second piston sets 3 completely different global variables. When this second piston fires, it stops the first piston from setting the global variables. Not sure why, and no amount of TCP or anything else would stop the conflict. Ended up putting a 10 second pause before setting the global variable and that resolved the issue for whatever reason.


#16

Good deal you got it figured out! That would definitely drive me up the wall :smiley:


#17

After the piston with nothing but setting variables worked, I copied, then deleted the original piston, with no improvement, then went down to disabling all other pistons to test. It then worked correctly, to my dismay. Then it was the long process of restoring one piston at a time until it failed again. I still do not understand what was causing the issue. The 2 piston are unrelated. The switches being set were virtual switches that each control a global variable that enables or disables motion control lights. The original piston turns off the motion control lights through the virtual switch when the house is empty and turns them back on when someone arrives home. The second piston sets a global variable based on the state of the virtual switch. The motion control piston (the third piston in this complex mess) only toggles lights on or off based on the state of this variable.

But now that I typed all that out, I’m realizing the global variable is not really needed as I can just check the state of the virtual switches instead of a global variable. I’m sure there was a reason I set it up this way to begin with… But don’t recall now lol.


#18

Maybe you guys can help. I’m trying to set a random number to determine what response to use. (If randomnumber is less than 50, use response A, if randomnumber is between 51 and 90, use response B, if randomnumber is greater than 91, use response C)

When I force a number, the choices work. The problem is, I’ve tried putting the random number generator in two different places, and either it doesn’t generate a random number, or it only generates it one time. When I enter the Add New Task settings, it generates a new number every time. Why won’t it do this when the piston runs? (BTW, I’m only setting the Global Variable to see what the random number is)

[EDIT] Nvrmnd…apparently it is generating a new number every time…it’s just not updating in the Global Variable window while piston is running.