Unexpected syntax errors in my rules

Sorry to ask again, but I can’t get rid of a syntax error.
Ich have declared several var(iables) on top of my rules, like this

var boolean alarmDeactivatedByAlarmRing

This variable is used in two rules (in the same rules file). openhab.log shows a syntax error

Rule 'Alarm system will be deactivated by alarmTimerActive immediately': The name 'alarmDeactivatedByAlarmRing' cannot be resolved to an item or type; line 54, column 8, length 27

I read articles about the syntax, but I didn’t find a solution. Few weeks ago, the rules were working.

Had anybody similar problems? Thanks

May we see a bigger snippet of your rules file? i.e. the declaration and the context of the failing line?

Thanks for your question back:

import java.util.Calendar
import java.text.SimpleDateFormat

var boolean alarmDeactivatedByAlarmRing
var Timer timer
//var SimpleDateFormat dfo = new SimpleDateFormat( "dd.MM.yyyy HH:mm:ss" )
// var Number secondsToDeactivateAlarm = 20
// var Number durationOfRinging = 1

and the rule which fails:

rule "Alarm system will be deactivated by alarmTimerActive immediately"
when
   Item alarmTimerActive changed to OFF
then
   if (alarmDeactivatedByAlarmRing == false) {
                // log the deactivation of current alarm
                val calr = Calendar::getInstance
                var SimpleDateFormat dfo = new SimpleDateFormat( "dd.MM.yyyy HH:mm:ss" )
                logInfo("rules", "alarm was manually deactivated by alarmTimerActive,  timer.state=" + timer)

                sendTelegram("bot1", "Alarm wurde deaktiviert um " + dfo.format(calr.time))

                if (timer !== null) {timer.cancel()}
                sendCommand(alarmMessageDeactivate, dfo.format(calr.time) )
   }
   alarmDeactivatedByAlarmRing = false
end

Thanks for any hint.

First time the rule runs, alarmDeactivatedByAlarmRing should be null.
I know that’s not what the error message says, but I would assign some initial value.
Rules if() function sometimes fails an odd way if it is struggling to determine first condition’s type, and the language is only loosely typed.

var boolean alarmDeactivatedByAlarmRing = false

This happened after a restart.

I don’t know then. A boolean is a primitive type, but don’t know any special issues.
I’d try it as string type “true” etc. to see what happens.

Does this error occur only when openHAB first starts up? Or does it occur any time the Rule triggers?

It occurs occasionally. Not a good answer, but I can’t nail it down. How can I detect, if the rule has been compiled?

Well your error message is telling you that it occurred within a named rule …

Just for info, rechecked this works as expected in OH2.4

testing.rules

var boolean yyy = false

rule "testing"
when
	Item test_sw changed
then
	if (yyy == false) {
		logInfo("test", "Bool test")
	}
end

That’s … weird. Any other mysterious happenings?

Am I interpreting it correctly that this happens to you sometimes after a restart, but not after every restart?

I have seen errors like this repeatedly after a restart when I cleaned out the cache and tmp files before restarting. In my case, waiting a few more minutes to allow for the system to fully start up and then stopping and starting OH (2.5M1 for me) without cleaning deleting cache or tmp files resolves this issue. Not a great solution, but it works.

@lipp_markus I have latestly cleared the cache and voilá - the syntax error was shown again. That’s my observation too!

Restarting OH (without cleaning cache) one or two times will get rid of this error