Hello,
I would like that light before the timer ends after 2min the light dims 30sec before it stops. I’ve tried different things but with timers I can’t go any further. It does not work in all conditions.
- light on with a single movement
- light on with renewed movement
- light on during continuous movement and then leave the area.
I found this function and modified it a bit.
PS: it should work like philips hue motionsensor rule.
Thanks for your help
val Map<String, Timer> LightingTimers = newHashMap //used for motion detection timers
val Functions$Function4<GenericItem, Number, Number, Map<String, Timer>, Boolean> MakeLightTimer = [ //function (lambda) to create/reschedule/cancel timer (call with time set to 0 to cancel)
item,
level,
time,
timers |
var String timerKey = item.name
var String timerKey2 = item.name + "-2"
if (timers.containsKey(timerKey)) {
var Timer timerTmp = timers.get(timerKey)
var Timer timerTmp2 = timers.get(timerKey)
if(time == 0) {
timerTmp.cancel()
timers.remove(timerKey)
timerTmp2.cancel()
timers.remove(timerKey2)
logInfo("Light Timer Function", timerKey + " Timer cancelled" )
}
else {
timerTmp.reschedule(now.plusSeconds(time))
if(timerTmp2 != null)
timerTmp2.reschedule(now.plusSeconds(time).minusSeconds(30))
else{
timers.put(timerKey2, createTimer(now.plusSeconds(time).minusSeconds(30)) [|
logInfo("Dimming Light Timer Function", timerKey2 + " Motion over, Light turning OFF" )
sendCommand(item, 30)
timers.remove(timerKey2)])
}
logInfo("Light Timer Function", timerKey + " Motion detected, Timer recheduled for " + time + " more seconds" )
sendCommand(item, level.intValue)
}
}
else {
if(time != 0) {
if(level == 0) sendCommand(item, OFF)
else if(level == 100) sendCommand(item, ON)
else sendCommand(item, level.intValue)
logInfo("Light Timer Function", timerKey + " Motion detected, Light set to: " + level)
timers.put(timerKey2, createTimer(now.plusSeconds(time).minusSeconds(30)) [|
logInfo("Dimming Light Timer Function", timerKey2 + " Motion over, Light turning OFF" )
sendCommand(item, 30)
timers.remove(timerKey2)])
}
timers.put(timerKey, createTimer(now.plusSeconds(time)) [|
logInfo("Light Timer Function", timerKey + " Motion over, Light turning OFF" )
sendCommand(item, OFF)
timers.remove(timerKey)])
logInfo("","ENDS OF FUNTION" )
}
true
]
rule "Flur OG Licht"
when
Item Flur_Hue_Motion2_motion changed to ON
then
MakeLightTimer.apply(diBrightness,80,60,LightingTimers)
end