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.


#16

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?


#17

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:


#18

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.


#19

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:

temp