Hi Everyone,
I’m trying to use a modified version of the rule in openhab2, but I’m not having much luck.
Only thing I see in the log is "Configuration model ‘randomlights.rules’ is either empty or cannot be parsed correctly!"
Can anyone see a problem with this?
var Timer tRandomLights = null
rule "Randomly turn on & off lights between 16.00-23.00 if after sunset and nobody is home"
when
Time cron "0 0/5 16-23 * * ?"
then
if ((Presence.state == OFF) && (now.isBefore((LocalSun_Rise.state as DateTimeType).calendar.timeInMillis) || now.isAfter((LocalSun_Set.state as DateTimeType).calendar.timeInMillis))) {
// Only turn a light on/off ocasionally
if ((new java.util.Random).nextInt(2) == 1) {
// Create a timer with a random value
var int randomTime = (new java.util.Random).nextInt(300)
logInfo("org.openhab","Setting random lights timer to " + randomTime + " seconds.")
tRandomLights = createTimer(now.plusSeconds(randomTime), [|
var randLightIndex = (new java.util.Random).nextInt(RandomLights.members.size)
var randLightStateCurrent = RandomLights.members.get(randLightIndex).state
var randLightStateNew = if (randLightStateCurrent == ON) OFF else ON
logInfo("org.openhab","Switching light " + RandomLights.members.get(randLightIndex).name + " from " + randLightStateCurrent + " to " + randLightStateNew)
sendCommand(RandomLights.members.get(randLightIndex), randLightStateNew)
])
}
}
end
rule "Turn all random lights off at 23.10 if nobody is home"
when
Time cron "0 10 23 * * ?"
then
if (Presence.state == OFF) {
logInfo("org.openhab","Turning all the random lights off.")
sendCommand(RandomLights, OFF)
}
end
Regards,
Josh