Make a double tap on a switch control another one.
exemple with 2 switch and and one switch.
you need the timer when controlling 2 switch with double tap. or you will have an infinite loop.
import org.joda.time.*
import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
var int tapDelay = 500
var DateTime timeSwitchKitchen = new DateTime().minusMinutes(5)
var boolean sendingDinning = false
var DateTime timeSwitchDinning = new DateTime().minusMinutes(5)
var boolean sendingKitchen = false
var DateTime timeSwitchBed1 = new DateTime().minusMinutes(5)
rule "Double TAP Kitchen"
when
Item Light_Kitchen received update
then
if(sendingKitchen==false) {
if(timeSwitchKitchen.plusMillis(tapDelay).afterNow) {
sendingDinning = true
sendCommand(Light_Dinning, (Light_Kitchen.state as OnOffType))
var Timer timerAlarmDelayKitchen = createTimer(now.plusMillis(tapDelay)) [|
sendingDinning=false
]
}else{
timeSwitchKitchen = new DateTime()
}
}
end
rule "Double TAP Dinning"
when
Item Light_Dinning received update
then
if(sendingDinning==false) {
if(timeSwitchDinning.plusMillis(tapDelay).afterNow) {
sendingKitchen = true
sendCommand(Light_Kitchen, (Light_Dinning.state as OnOffType))
var Timer timerAlarmDelayDinner = createTimer(now.plusMillis(tapDelay)) [|
sendingKitchen=false
]
}else{
timeSwitchDinning = new DateTime()
}
}
end
rule "Double TAP Bed1"
when
Item Light_Bed1 received update
then
if(timeSwitchBed1.plusMillis(tapDelay).afterNow) {
sendCommand(Light_Bed2, (Light_Bed1.state as OnOffType))
}else{
timeSwitchBed1 = new DateTime()
}
end