I made some slight modifications and it works. Appriciate your support very much @jimtng
How can we make it in the format of 01:20:59 ?
var Timer motionDelayTimer = null
var RuleFlag = null
val int timeoutMinutes = 20
rule "Office Motion Sensor ON"
when
Item Office_Multisensor_6_Motion_Alarm changed from OFF to ON
then
if (RuleOfficeLight.state == ON){
RuleFlag = true
if(motionDelayTimer === null || motionDelayTimer.hasTerminated) {
motionDelayTimer = null
Office_FIBARO_Double_Switch.sendCommand(ON)
Office_FIBARO_Dimmer.sendCommand(2)
logInfo("Motion Office", "Movement recognised -> Light ON")
}
else {
logInfo("Motion Office", "Movement recognised -> Timer stop.")
motionDelayTimer.cancel
motionDelayTimer = null
CountdownItem.postUpdate(0)
}
}
else{
logInfo("Motion Office", "Rule deactivated")
}
end
rule "Office Motion Sensor OFF"
when
Item Office_Multisensor_6_Motion_Alarm changed from ON to OFF
then
if(RuleFlag == true) {
CountdownItem.postUpdate(timeoutMinutes * 60) // reset the timeout
logInfo("Motion Office", "No more movement -> Timer start.")
RuleFlag = null
motionDelayTimer = createTimer(now.plusSeconds(1), [ |
val timeout = (CountdownItem.state as QuantityType).intValue
if (timeout == 0) {
motionDelayTimer.cancel
motionDelayTimer = null
Office_FIBARO_Double_Switch.sendCommand(OFF)
logInfo("Motion Office", "Timer elapsed -> Light OFF")
}
else {
CountdownItem.postUpdate(timeout - 1)
motionDelayTimer.reschedule(now.plusSeconds(1))
}
])
}
else{
logInfo("Motion Office", "Rule deactivated already")
}
end