I am still have some old rules in dsl format in .rules files and slowly trying to alter them to the new blockly. but this one is an old one that i have found before years in the forum and i am wonder can someone make it for me as my Knowledges are limited for so difficult rule.
var Timer tShutters = null
// val java.util.concurrent.ThreadLocalRandom random = (new java.util.concurrent.ThreadLocalRandom)
rule "close Shutters"
when
Channel 'astro:sun:local:set#event' triggered START
//Time cron "0 * * * * ?"
then
tShutters?.cancel // cancel existing timer, if there is one
val java.util.Random random = new java.util.Random
val int randomTimes = random.nextInt(60) + 20 // minimum 20 Seconds, maximum 80 Seconds
tShutters = createTimer(now.plusSeconds(randomTimes),[ |
val iGroup = gBlindsAstro.members.filter[r|(r.state as Number) < 100] // all open shutters
if(iGroup !== null && iGroup.size > 0) { // any open Shutters left?
logInfo("loggerName", iGroup.toString)
val int randomTime = random.nextInt(60) + 20 // minimum 20 Seconds, maximum 80 Seconds
val int randomShutter = random.nextInt(iGroup.size) // from 1 to iGroup.size
//val int randomShutter = random.nextInt(iGroup.size -1) +1 // from 1 to iGroup.size, to exclude an item from group
iGroup.get(randomShutter).sendCommand(DOWN) // or 100 for absolute position
iGroup.get(randomShutter).postUpdate(100) // ensure state is set to 100 immediately
tShutters.reschedule(now.plusSeconds(randomTime)) // next close @
}
])
end
Thanks Nikos