How do I get delay before the second command sendCommand(Lights_2, ON&OFF)"?
rule “Lights”
when
Item Lights received command
then
if(receivedCommand==ON) {
sendCommand(Lights_1, ON)
??? delay 2 seconds ???
sendCommand(Lights_2, ON)
} else if(receivedCommand==OFF) {
sendCommand(Lights_1, OFF)
??? delay 2 seconds ???
sendCommand(Lights_2, OFF)
}
end
Edit:
I used the command: timer = createTimer(now.plusSeconds(1)) [|
import org.joda.time.*
import org.openhab.model.script.actions.Timer
rule "Lights"
when
Item Lights received command
then
if(receivedCommand==ON) {
sendCommand(Lights_1, ON)
createTimer(now.plusSeconds(2)) [|
sendCommand(Lights_2, ON)
]
}
else if(receivedCommand==OFF) {
sendCommand(Lights_1, OFF)
createTimer(now.plusSeconds(2)) [|
sendCommand(Lights_2, OFF)
]
}
end
Maybe this version works as well:
import org.joda.time.*
import org.openhab.model.script.actions.Timer
rule "Lights"
when
Item Lights received command
then
{
Lights_1.sendCommand(receivedCommand)
createTimer(now.plusSeconds(2)) [|
Lights_2.sendCommand(receivedCommand)
]
}
end
If you want to refer to the timer, you will need to use a var, but you may have to define it globally i.e. in the rule-file, but ahead the first rule:
var Timer myTimer = null
and then within the rule:
if(myTimer!=null) {
myTimer.cancel
myTimer=null}
myTimer=createTimer(now.plusSeconds(2))[|whatever you want to do after the timer lapsed]
1 Like
Exactly what I was looking for.
I have 4 NEXA power switches (over rfxcom433E ) for lights and they are very unreliable. Very sporadic when they manage to turn off and on.
I hope that a 30 seconds delay in between will improve the sucessrate.