Global Variable Value Comparison


1) Give a description of the problem
Global Variable does not seem to read as a value to the piston

2) What is the expected behaviour?
Piston will read global variable and fire/not fire based on less/greater than.

3) What is happening/not happening?
It is not comparing the value of the global piston.

4) Post a Green Snapshot of the pistonimage


You can see in the second image that the comparison should be true for @rainexpected

What am I doing wrong?



Are your Variable device types set up as integers or decimals? I was able to trigger the piston with a test. My Variables were set up as Number(decimal).


@logeox is right.
If your global variable is a string (or dynamic) then it might not be seen as a number.


Your problem here is that your global variable is returning the full strings “Rain this week: 0” / “Rain expected: 0.35” rather than just the values “0” / “0.35”.

You either need to change the way your global variables are populated so as to only include the values, or use the replace() function to strip off the leading text, i.e.:

replace(@rainlog, 'Rain this week: ', '')

You may also need to wrap the above with decimal(), i.e.:

decimal(replace(@rainlog, 'Rain this week: ', ''))


btw… I also use an irrigation piston, I strongly recommend you allow for ST instabilities to avoid flooding your garden… trust me, one day it will happen!!

I would disable command optimisations (so commands are always sent, even if it won’t change the device state) and add additional ‘close’ commands with a minute wait between.

Set everything to ‘never cancel’

Run a smart lighting automation with power allowance, to prevent accidental over watering… call it a fail safe.

Oh, and in my case I’m using Fibaro relays, which have an auto off parameter hard baked into the device itself, so shut off is guaranteed even if the internet explodes… ultimate fail safe lol.

Finally, I’m using solenoid valves that return to closed on power failure.


Thanks Everyone,

This is exactly what I needed, I just didn’t know how to accomplish it.

That second picture indicates that it is comparing properly. Thanks again!


Good note. I am using a dumb-smart controller at the faucet, one of those big-box timers with several outputs. Even if the valve is open the timer must also be on (and vice versa). That provides redundancy and also allows for watering different zones.

The water valve (that you helped with) is almost exclusively for weather control. I hated looking outside in a thunderstorm and seeing my sprinklers on.

All that said, I may still add your suggestions. Thanks!

EDIT: On further review, I don’t know how to set it to “Never Cancel”. Where can I find that?


Not entirely sure how that revised piston is working for you lol… your replace() function is incomplete, you chopped out the part out that tells the expression what to replace… guessing you tweaked the global variable directly instead?

‘Never cancel’ is probably over kill in this case… it only really applies when a ‘wait’ command is involved, but the following gif file shows the two methods available:


Alright, so my ignorance is showing. I did not change the global variable. I made an assumption (you know what they say) that it was working correctly based on the log showing a comparison between two (decimal) numbers.

Should I have written the replace function exactly as written in your post above?


To be honest I’m not sure now… as your first set of logs showed words in the global variable, the second set of logs show just numbers.

Either way, copy pasting the expression exactly as I posted above will do no harm, if the text is not there it wont replace anything.


Update: We got a bit of rain yesterday (so my numbers were >0), and it didn’t look like this was firing correctly, so I replaced the expression with your recommendation above.

It still didn’t appear to see the numbers. I think, in my admitted ignorance, that the expression decimal(replace(@rainlog, 'Rain this week: ', '')) strips all values from the variable and returns 0 always.

Instead, I just inserted the variable instead of an expression.

Dang it. I just realized that this where I started. That can’t be the fix.

I’m lost.


0 IS less than 0.5
0.15 IS less than 0.2

So the above logs are correct.

I would need to see logs from when the full expression was applied, as yes, you are currently back to square one, with textual strings in your comparisons.


Please install the following piston, change logging to full and click the test button, then post logs back here:


Okay. That seems like it’s working, both stripped and not? I don’t know enough to understand why.


I just put the expression into the comparison properly… if you were comparing the non-stripped values it would fail as you have text mixed in with the values.


I feel like Costello, “Same as you!” I’m not sure what the difference was other than renaming the variable after it was stripped?

I renamed the variable like in your example:

It works!

I really appreciate your help. I looked at the WebCoRE wiki for more info on variables, and I didn’t find enough to feel educated. What is a better source?


Glad you got it working, changing the variable name makes no difference lol, you never actually posted a complete piston with the full expression so I was unable to review your error… I just made a fresh piston I knew would work :wink:


Thanks again. What is a good resource for learning how to write variables & expressions? I didn’t find a lot of detail in the Wiki on variables.


Variables can be written as Value or as Expressions. I prefer doing as Expressions because it gives you instant feedback in the grey box as you type.

The Wiki - Expressions page has a pretty extensive list of available commands…

If needed, every command found there can be nested in parentheses… That being said, I would encourage you to test it bit by bit so you can see what is happening at each step… The instant feedback with Expressions really helps with this stage.

Basic concept for Expressions?

  • Standard text is inside quotes
  • Variable names are outside of quotes
  • Formulas are usually outside of quotes
  • Quotes can be single or double, but be consistent

A few examples: