Referening to a number variable in an if statement


Part of my rule is as following:

        if (Astro_SunElevation.state >= 19.5) {
            Laadpaalaanuittrigger.sendCommand (ON)

This works fine.

I now want to change the 19.5 by a local variable that I declare in my rules.
I have done as following:

var elevation = 19.5

        if (Astro_SunElevation.state >= elevation ) {
            Laadpaalaanuittrigger.sendCommand (ON)

This does not seem to work. I get “invalid number of arguments”
Astro_SunElevation is a Number item and I know that comparing numbers is always tricky, but cannot get this to work. Any help would be appreciated as to what I’m doing wrong here.

That’s an odd error for this code. Are you sure it’s coming from this if statement? Post the full log statement.

Note that if you are using OH 3 and this Item is linked to one of the elevation Channels, it’s not a Number Item. It’s a Number:Angle Item which means that the state carries units.

I would have expected it to fail on the first if statement though if that were the case because you did provide units there either. But in the off chance that is the problem try

var elevation = 19.5 | °
1 Like

Thanks Rich. That was a good suggestion, however i found the culprit elsewhere. Seems I had declared the variable elevation 2 times in my rule and this messed it up. I had done like this:
If (…) { var elevation = 16} else var elevation = 19

While I should only have declared var elevation once upfront.