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