Hi,
I have a light timer rule which should add a timer to every light switch and turns it off after a defined time period
Code is ihere `rule “LIGHT-TIMER”
when
Item group___powersaving_CUSTOMGROUP received update
then
val lightValue = illumination_sensor_aussendachmastlicht.state
try{
var loopBreak = 0
while(!lock.tryLock())
{
Thread::sleep(2000)
logInfo("Powersaving", "Waiting for lock")
loopBreak++
if(loopBreak > 10)
{
logInfo("Powersaving", "couldn´t get lock - exiting")
return
}
}
val mostRecent = group___powersaving_CUSTOMGROUP?.allMembers.sortBy[lastUpdate].last
logInfo("Powersaving", "Most recent"+mostRecent.name)
logInfo("Powersaving", "lightValue: "+lightValue)
//This is the value for night time (see time settings below)
var timeValue = 60
if(lightValue > 15000)
{
timeValue = 10
}
lightTimers.apply(mostRecent, timers, timeValue)
}
finally{
lock.unlock();
}
end`
and the lambda is`val org.eclipse.xtext.xbase.lib.Functions$Function3 lightTimers = [
SwitchItem relayItem,
java.util.Map<String, Timer> timers,
int timeout |
logInfo("Powersaving", "PRINTING ALL TIMERS *****************")
timers.forEach[
k, v|
logInfo("Powersaving", "TIMER ITEM :"+k)
]
logInfo("Powersaving", "PRINTING ALL TIMERS END *****************")
logInfo("Powersaving", "state of " + relayItem)
val tUid = now.millis
if (relayItem.state == ON) {
// now create a new timer for switching off
if(timers.get(relayItem.name) == null){
logInfo("Powersaving", "***************** CREATING Timer for '"+relayItem.name+"' with timeout '"+timeout+"' uid="+tUid)
timers.put(relayItem.name, createTimer(now.plusMinutes(timeout)) [|
logInfo("Powersaving", "INNER-TIMER - ENTERING LAMBDA with item ("+relayItem.name+") with timeout ("+timeout+") uid="+tUid+"***********************************************")
// switch it off afterwards, if it is not already off
if (relayItem.state == ON){
logInfo("Powersaving", "INNER-TIMER - Switching "+relayItem.name+"' OFF. uid="+tUid+"***********************************************")
relayItem.sendCommand(OFF)
logInfo("Powersaving", "INNER-TIMER - Removing "+relayItem.name+"' from timers. uid="+tUid+"***********************************************")
timers.remove(relayItem.name)
}
logInfo("Powersaving", "INNER-TIMER - LEAVING LAMBDA with item ("+relayItem.name+") with timeout ("+timeout+") uid="+tUid+"***********************************************")
])
}
}
else{
if(timers.containsKey(relayItem.name))
logInfo("Powersaving", "Removing "+relayItem.name+"' from timers 2")
timers.remove(relayItem.name)
}
]`
The problem is, that my logs are full of these logs now, because the rules is triggerd all the time, not only when a light in group___powersaving_CUSTOMGROUP gets an update …