Just a simple one from me today, as I wanted a way to turn off my external lights at night.
However, I wanted to add a bit of randomness to it, rather than the whole outside of the house being plunged into darkness at a specific time every night.
Firstly, I have a Group, and a number of Switch items which belong to this group:
rule "Turn External Lights off from 23:30"
when
Time cron "0 30 23 ? * * *"
then
gExternalLights.members.forEach[ temp |
var int randomTime = (new java.util.Random).nextInt(1800)
createTimer(now.plusSeconds(randomTime)) [|
temp.sendCommand(OFF)
]
]
end
This roughly translates to: At 23:30 every day, create a random timer (0-30 minutes) for each item that belongs to the group, and after that time has elapsed, turn that light off.
Iâm trying to use your excellent rule under OH3. The script I have is as follows but with noted error from log file. I would appreciate any suggestions. (Iâm not a coder so Iâm struggling a bit but do understand some of the syntax.) Thank you
ir.Item(âPowerOutletâ).members.forEach[temp |
var int randomTime = (new java.util.Random).nextInt(1800)
createTimer(now.plusSeconds(randomTime)) |
temp.sendCommand(OFF)
]
EOF
Log error: no viable alternative at input â|â; line 3, column 150, length 1
Iâve not tried OH3 yet, but youâve not used the âcode fencesâ to paste your code here, so Iâm not sure if itâs that, but it looks like youâre missing a [, and Iâm not sure that the first part is correct - mine is acting on a Group, yours⊠isnât?
ir.Item(âPowerOutletâ).members.forEach ___ [temp |
var int randomTime = (new java.util.Random).nextInt(1800)
createTimer(now.plusSeconds(randomTime))] [|
temp.sendCommand(OFF)]
end
Log: 1. The method or field ir is undefined; line 1, column 0, length 2
2. The method or field temp is undefined; line 4, column 157, length 4
3. The method or field end is undefined; line 5, column 180, length 3
4. Invalid number of arguments. The method createTimer(ZonedDateTime, Procedure0) is not applicable for the arguments (ZonedDateTime); line 3, column 109, length 11
5. There is no context to infer the closureâs argument types from. Consider typing the arguments or put the closures into a typed context.; line 1, column 38, length 112
6. This expression is not allowed in this context, since it doesnât cause any side effects.; line 3, column 151, length 28
Itâs not valid DSL rules language. Are you actually trying to write in DSL? The original example was in DSL, but you seem to have mangled some javascript into your reworked version.
What is PowerOutlet,is this a Group type Item?