I have an issue with the rule I am trying to port from OH1.
I want to update every minute the time since security system zone was triggered. The rule used to work on OH1, but it gets rejected by OH2.
rule "Update time since open"
when
Time cron "20 * * ? * *"
then
Zone_Times?.members.forEach (zone|
var Number minutes = 0
if (zone.state instanceof DecimalType) {
minutes = zone.state as DecimalType
if (minutes < 49)
minutes = minutes + 1
else
if (minutes > 49 && minutes < 99)
minutes = minutes + 1
}
postUpdate (zone,90)
//logInfo("DSC","Updating zone to {} minutes",minutes)
)
end
I get the following error message:
2018-05-26 21:49:53.290 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'dsc.rules' has errors, therefore ignoring it: [78,8]: no viable alternative at input 'var'
[89,5]: extraneous input ')' expecting 'end'
I have found the right syntax by trial and error: {} around the code did the trick:
rule "Update time since open"
when
Time cron "20 * * ? * *"
then
Zone_Times?.members.forEach (zone|
{ var Number minutes = 0
if (zone.state instanceof DecimalType) {
minutes = zone.state as DecimalType
if (minutes < 49)
minutes = minutes + 1
else
if (minutes > 49 && minutes < 99)
minutes = minutes + 1
}
postUpdate (zone,90)
//logInfo("DSC","Updating zone to {} minutes",minutes)
}
)
end
You’re right, the original OH1 posted variable minutes of course, but what I pasted was a version I was playing around with, trying to figure out why it complains on syntax.