Dear All,
Apologies, if my issue is very trivial, I tried to find a solution, but I have not found any .
I would like to set up an Alarm Clock solution to control my led strips and I found a code that I like very much, so I would like to use it as my base.
Unfortunately, OpenHAB gets back the following error for my rule file:
Configuration model ‘alarm.rules’ has errors, therefore ignoring it: [24,1]: no viable alternative at input ‘then’
I’m using OpenHAB 2.5, the rule code is the following:
`import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.action.squeezebox.*
import java.util.concurrent.locks.ReentrantLock
var Timer timer0 = null
var Timer timer1 = null
var Timer timer2 = null
var Timer timer3 = null
var java.util.concurrent.locks.ReentrantLock lock1 = new java.util.concurrent.locks.ReentrantLock()
rule "Alarm"
when
Item alarmTimeHour changed or
Item alarmTimeMinutes changed or
Item alarmOffset1Minutes changed or
Item alarmOffset2Minutes changed or
Item alarmOffset3Minutes changed or
then
lock1.lock()
try {
var String msg = ""
logInfo("rules","Alarm has been changed.")
var hour = alarmTimeHour.state as DecimalType
var minute = alarmTimeMinutes.state as DecimalType
if (hour < 10) { msg = "0" }
msg = msg + alarmTimeHour.state.format("%d") + ":"
if (minute < 10) { msg = msg + "0" }
msg = msg + alarmTimeMinutes.state.format("%d")
postUpdate(alarmTimeMessage,msg)
logInfo("rules","New alarm time: "+msg)
var int alarm1
alarm1 = (alarmTimeHour.state as DecimalType).intValue * 60 + (alarmTimeMinutes.state as DecimalType).intValue
alarm1 = alarm1.intValue
var int hour1
hour1 = now.getMinuteOfDay
hour1 = hour1.intValue
var int delta1
delta1 = (alarm1 - hour1)
delta1 = delta1.intValue
if (hour1 > alarm1) { delta1 = delta1 + 1440 }
var int delta2
delta2 = delta1 + (alarmOffset1Minutes.state as DecimalType).intValue
var int delta3
delta3 = delta1 + (alarmOffset2Minutes.state as DecimalType).intValue
var int delta4
delta4 = delta1 + (alarmOffset3Minutes.state as DecimalType).intValue
if (timer0 != null) {
timer0.cancel
timer0 = null
}
timer0 = createTimer(now.plusMinutes(delta1)) [|
timer0.reschedule(now.plusHours(24))
if(alarmEnabled.state == ON) {
var Number day = now.getDayOfWeek
if (((day == 1) && (alarmMonday.state == ON)) ||
((day == 2) && (alarmTuesday.state == ON)) ||
((day == 3) && (alarmWensday.state == ON)) ||
((day == 4) && (alarmThursday.state == ON)) ||
((day == 5) && (alarmFriday.state == ON)) ||
((day == 6) && (alarmSaturday.state == ON)) ||
((day == 7) && (alarmSunday.state == ON))) {
// The things to do if the alarm clock is enabled for this day of week:
}
}
]
logInfo("rules","Alarm, timer0 set.")
if (timer1 != null) {
timer1.cancel
timer1 = null
}
timer1 = createTimer(now.plusMinutes(delta2)) [|
timer1.reschedule(now.plusHours(24))
if(alarmEnabled.state == ON) {
var Number day = now.getDayOfWeek
if (((day == 1) && (alarmMonday.state == ON)) ||
((day == 2) && (alarmTuesday.state == ON)) ||
((day == 3) && (alarmWensday.state == ON)) ||
((day == 4) && (alarmThursday.state == ON)) ||
((day == 5) && (alarmFriday.state == ON)) ||
((day == 6) && (alarmSaturday.state == ON)) ||
((day == 7) && (alarmSunday.state == ON))) {
// The things to do if the alarm clock is enabled for this day of week:
}
}
]
logInfo("rules","Alarm, timer1 set.")
if (timer2 != null) {
timer2.cancel
timer2 = null
}
timer2 = createTimer(now.plusMinutes(delta3)) [|
timer2.reschedule(now.plusHours(24))
if(alarmEnabled.state == ON) {
var Number day = now.getDayOfWeek
if (((day == 1) && (alarmMonday.state == ON)) ||
((day == 2) && (alarmTuesday.state == ON)) ||
((day == 3) && (alarmWensday.state == ON)) ||
((day == 4) && (alarmThursday.state == ON)) ||
((day == 5) && (alarmFriday.state == ON)) ||
((day == 6) && (alarmSaturday.state == ON)) ||
((day == 7) && (alarmSunday.state == ON))) {
// The things to do if the alarm clock is enabled for this day of week:
}
}
]
logInfo("rules","Alarm, timer2 set.")
if (timer3 != null) {
timer3.cancel
timer3 = null
}
timer3 = createTimer(now.plusMinutes(delta4)) [|
timer3.reschedule(now.plusHours(24))
if(alarmEnabled.state == ON) {
var Number day = now.getDayOfWeek
if (((day == 1) && (alarmMonday.state == ON)) ||
((day == 2) && (alarmTuesday.state == ON)) ||
((day == 3) && (alarmWensday.state == ON)) ||
((day == 4) && (alarmThursday.state == ON)) ||
((day == 5) && (alarmFriday.state == ON)) ||
((day == 6) && (alarmSaturday.state == ON)) ||
((day == 7) && (alarmSunday.state == ON))) {
// The things to do if the alarm clock is enabled for this day of week:
}
}
]
logInfo("rules","Alarm, timer3 set.")
} finally {
lock1.unlock()
}
end
rule "Initialization"
when
System started
then
postUpdate(alarmEnabled, ON)
// postUpdate(radioEnabled, ON)
postUpdate(alarmTimeHour, 6)
postUpdate(alarmTimeMinutes, 30)
postUpdate(alarmOffset1Minutes, 20)
postUpdate(alarmOffset2Minutes, 15)
postUpdate(alarmOffset3Minutes, 50)
postUpdate(alarmMonday, ON)
postUpdate(alarmTuesday, ON)
postUpdate(alarmWensday, ON)
postUpdate(alarmThursday, ON)
postUpdate(alarmFriday, ON)
postUpdate(alarmSaturday, OFF)
postUpdate(alarmSunday, OFF)
end`
I do not understand this error message what should I review and correct in the code.
May I ask you for your help to give me some direction where should I look?
Much appreciated for your help!
Gergely