Global Variable Value Comparison


#1

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


image

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

What am I doing wrong?

Thanks!


#2

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).


#3

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


#4

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: ', ''))


#5

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.


#6

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!


#7

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?


#8

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:


#9

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?


#10

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.


#11

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.


#12

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.


#13

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


#14

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


#15

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.