I want to use variable in “when” block of rules.
My code:
val DayTime_day_start_hours = 7
val DayTime_day_end_hours = 23
val str1 = "0 " + DayTime_day_start_minutes + " " + DayTime_day_start_hours + " ? * * *"
rule "When system started"
when
System started
then
logInfo("RRRLog", "Rule 'When system started'")
if(now.withTimeAtStartOfDay.plusHours(DayTime_day_start_hours).isBefore(now) && now.withTimeAtStartOfDay.plusHours(DayTime_day_end_hours).isAfter(now)){
DayTime_day.postUpdate(ON)
}
end
and this rule
rule "DayTime_bed OFF DayTime_day ON"
when
Time cron "0 " + DayTime_day_start_minutes + " " + DayTime_day_start_hours + " ? * * *"
then
DayTime_bed.postUpdate(OFF)
DayTime_day.postUpdate(ON)
end
or this rule
rule "DayTime_bed OFF DayTime_day ON"
when
Time cron str1
then
DayTime_bed.postUpdate(OFF)
DayTime_day.postUpdate(ON)
end
I get an error:
[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'def.rules' has errors, therefore ignoring it: [91,20]: missing 'then' at '+' [92,1]: no viable alternative at input 'then'
or
Configuration model 'def.rules' has errors, therefore ignoring it: [91,15]: mismatched input 'str1' expecting RULE_STRING