Global vars not found in rules

Hi,

i just wrote two simple rules to automate my rollershutters a little bit on these hot days, but it’s not working and I cannot find the reason why the global vars are not seen by the rule. Can somebody please point me to the right direction? Thanks in advance! The error from the logs:

2022-06-19 16:48:32.860 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'a0ee29257a' failed:         if ( ___ BeschattungNordAktiv == false &&  ___ BeschattungNordAbgeschlossen == false && (LokaleSonnendaten_Azimut.state as Number).floatValue > 230) {
            RolllaedenNord.sendCommand(DOWN)
        }

   1. The method or field BeschattungNordAktiv is undefined; line 1, column 12, length 20
   2. The method or field BeschattungNordAbgeschlossen is undefined; line 1, column 45, length 28

My rules are both defined together with the global vars in one file:

var BeschattungOstAktiv = false
var BeschattungSuedAktiv = false
var BeschattungWestAktiv = false
var BeschattungNordAktiv = false

var BeschattungOstAbgeschlossen = false
var BeschattungSuedAbgeschlossen = false
var BeschattungWestAbgeschlossen = false
var BeschattungNordAbgeschlossen = false


rule "Sonnenschutz"
when
	Item LokaleSonnendaten_Azimut changed or
    Item LokaleSonnendaten_Position_Elevation changed
then
	if (RollladenSteuerung_Sonnenschutz.state == ON) {

        // Start Beschattung Ost
        if (BeschattungOstAktiv == false && BeschattungOstAbgeschlossen == false && (LokaleSonnendaten_Position_Elevation.state as Number).floatValue > 20) {
            BeschattungOstAktiv = true
            RolllaedenOst.sendCommand(DOWN)
        }

        // Start Beschattung Süd
        if (BeschattungSuedAktiv == false && BeschattungSuedAbgeschlossen == false && (LokaleSonnendaten_Position_Elevation.state as Number).floatValue > 20) {
            BeschattungSuedAktiv = true
            RolllaedenSued.sendCommand(DOWN)
        }

        // Start Beschattung West
        if (BeschattungWestAktiv == false && BeschattungWestAbgeschlossen == false && (LokaleSonnendaten_Azimut.state as Number).floatValue > 130 ) {
            BeschattungWestAktiv = true
            RolllaedenWest.sendCommand(DOWN)

        }

        // Start Beschattung Nord
        if (BeschattungNordAktiv == false && BeschattungNordAbgeschlossen == false && (LokaleSonnendaten_Azimut.state as Number).floatValue > 230) {
            BeschattungNordAktiv = true
            RolllaedenNord.sendCommand(DOWN)
        }




        // Ende Beschattung Ost
        if (BeschattungOstAktiv && (LokaleSonnendaten_Azimut.state as Number).floatValue > 119) {
            BeschattungOstAktiv = false
            BeschattungOstAbgeschlossen = true
            RolllaedenOst.sendCommand(UP)
        }

        // Ende Beschattung Süd
        if (BeschattungSuedAktiv && (LokaleSonnendaten_Azimut.state as Number).floatValue > 195) {
            BeschattungSuedAktiv = false
            BeschattungSuedAbgeschlossen = true
            RolllaedenSued.sendCommand(UP)
        }

        // Ende Beschattung West
        if (BeschattungWestAktiv && (LokaleSonnendaten_Position_Elevation.state as Number).floatValue < 10 ) {
            BeschattungWestAktiv = false
            BeschattungWestAbgeschlossen = true
            // nichts hochfahren, ist eh bald Sonnenuntergang
        }

        // Ende Beschattung Nord
        if (BeschattungNordAktiv && (LokaleSonnendaten_Position_Elevation.state as Number).floatValue < 10) {
            BeschattungNordAktiv = false
            BeschattungNordAbgeschlossen = true
            // nichts hochfahren, ist eh bald Sonnenuntergang
        }

    }
    
end



rule "Sonnenschutz reset"
when
    Time is midnight
then
    BeschattungOstAktiv = false
    BeschattungSuedAktiv = false
    BeschattungWestAktiv = false
    BeschattungNordAktiv = false

    BeschattungOstAbgeschlossen = false
    BeschattungSuedAbgeschlossen = false
    BeschattungWestAbgeschlossen = false
    BeschattungNordAbgeschlossen = false
end

So, why are BeschattungNordAktiv and BeschattungNordAbgeschlossen not visible to the rule?

Edit: I’m using openHAB 3.2.0 Release Build with Openhabian on a RasPi 4.

You should make item values

Item BeschattungOstAktiv "Beschattung Ost"
/* also for the other vars 
var BeschattungNordAktiv = false
var BeschattungSuedAktiv = false
var BeschattungWestAktiv = false

var BeschattungOstAbgeschlossen = false
var BeschattungSuedAbgeschlossen = false
var BeschattungWestAbgeschlossen = false
var BeschattungNordAbgeschlossen = false
*/


Then check the value with

...
if (BeschattungOstAktiv.state == false && 
    BeschattungOstAktiv.state !=null  [&& or || for other checks]) {
       BeschattungOstAktiv.sendCommand(true)
       RolllaedenOst.sendCommand(DOWN)
}
...

At midnight reset

BeschattungOstAktiv = sendCommand(false)

I only gave an example on one direction you will be able to fix it.

And

Thank for your answer. I agree, items would be an alternative solution and I already had this in my mind before writing this rule, but intentionally choose not to use items, because I don’t want to “waste” items for this simple bool flags I’ll never use in any way outside of this rules.

I will sure go the way you described above if no other solution is found, but I’m really interested in the reason why my rule (which in my eyes is valid code) is not working. Or have I missed some info about breaking changes regarding to global vars in the recent OH releases?

To get to the if()with the BeschattungNordAktiv element, the rule would have already executed the earlier if() with other “globals”. Suggests you need to look closely at just this one for typos etc. Invisible control characters can creep into rule files with copy/paste editing and are the devil to find, Generally, once you’ve got down to one line that ought to work but doesn’t, try re-typing it (no copy/paste).

Thanks man! You’re absolutely right, the globar vars could not be the problem at all, because the first three if statements were executed without an error. After retyping the complete if statement with the “BeschattungNordAktiv” element and saving the rule everything works now! What a bug, I would never have thought of that…