Hi all,
I’m trying to use the UpdatedSince function to determine if a Light status has (manually) been changed and if so, then not to turn off the lights after motion detection expires.
The usecase for this is, that if someone’s in our kitchen, the lights go on automatically at a given percentage of the dimmer and depending on the time of the day, light strenght, etc… If someone feels the light is too dim or bright, and adjusts it to her/his own convenience, then the light should stay on and not turn off upon end of the timer.
Here’s the full rule:
var Timer waitTimerKitchen = null
rule "Bewegung Küche"
when
Item GF_Kitchen_Sensor_MotionEvent changed from OFF to ON
then
val KitMot = (GF_Kitchen_Sensor_Licht.state as DecimalType).intValue
logInfo("Bewegung Küche","GF_Kitchen_Sensor_Licht: {}", KitMot)
if((KitMot <= 45) || (Nacht.state == ON)) {
logInfo("Bewegung Küche","GF_Kitchen_Sensor_Licht: {}", KitMot,Tag +" ist der Tag")
if (waitTimerKitchen !== null) {
logInfo("Bewegung Küche","Hoppala, ein Timer ist schon da -> mach ma nochmal 2 Minuten")
waitTimerKitchen.reschedule(now.plusMinutes(2))
} else {
if (now.getHourOfDay() >= 6 && now.getHourOfDay() < 10) {
logInfo("Bewegung Küche FRÜH", "Jetzt geht das Licht an Licht1: {} Licht2 {}",GF_Kitchen_Light1,GF_Kitchen_Light2 + "% ist die Dimmung")
GF_Kitchen_Light1.sendCommand(100) //Kaffeemaschine
GF_Kitchen_Light2.sendCommand(100)} //Küche
if (now.getHourOfDay() >= 10 && now.getHourOfDay() < 21) {
logInfo("Bewegung Küche TAG", "Jetzt geht das Licht an Licht1: {} Licht2 {}",GF_Kitchen_Light1,GF_Kitchen_Light2 + "% ist die Dimmung")
GF_Kitchen_Light1.sendCommand(75) //Kaffeemaschine
GF_Kitchen_Light2.sendCommand(60)} //Küche
if (now.getHourOfDay() >= 21 && GF_LivingDining_Power4.state == ON || Heimkino.state == ON) {
logInfo("Bewegung Küche NACHT KINO", "Jetzt geht das Licht an Licht1: {} Licht2 {}",GF_Kitchen_Light1,GF_Kitchen_Light2 + "% ist die Dimmung")
GF_Kitchen_Light1.sendCommand(0) //Kaffeemaschine
GF_Kitchen_Light2.sendCommand(9)} //Küche
if (now.getHourOfDay() >= 21 && GF_LivingDining_Power4.state == OFF || Heimkino.state == OFF) {
logInfo("Bewegung Küche NACHT", "Jetzt geht das Licht an Licht1: {} Licht2 {}",GF_Kitchen_Light1,GF_Kitchen_Light2 + "% ist die Dimmung")
GF_Kitchen_Light1.sendCommand(32) //Kaffeemaschine
GF_Kitchen_Light2.sendCommand(50)} //Küche
logInfo("Bewegung Küche", "Jetzt mach ich einen 2 Minuten Timer")
waitTimerKitchen = createTimer(now.plusMinutes(2))[|
logInfo("Bewegung Küche", "Ich checke ob Bewegung erkannt: " +
GF_Kitchen_Sensor_MotionEvent.state + " ist der Status, so schauts aus")
if (GF_Kitchen_Sensor_MotionEvent.state == ON) {
logInfo("Bewegung Küche","Weil Bewegung erkannt, Timer neu setzen")
waitTimerKitchen.reschedule(now.plusMinutes(2))
if (now.getHourOfDay() >= 6 && now.getHourOfDay() < 10 &&
GF_LivingDining_Sensor_MotionEvent.state == ON) {
logInfo("Bewegung WZ MORGEN","Weil Bewegung erkannt, Timer neu setzen")
waitTimerKitchen.reschedule(now.plusMinutes(7))}
} else {
logInfo("Bewegung Küche", "Check ob Lichtstärke verändert wurde")
if (GF_Kitchen_Light1.updatedSince(now.minusSeconds(119)) ||
GF_Kitchen_Light2.updatedSince(now.minusSeconds(119))) {
KKL.sendCommand(ON)
} else {
logInfo("Bewegung Küche", "Jetzt geht das Licht aus Licht1: {} Licht2 {}",GF_Kitchen_Light1,GF_Kitchen_Light2 + "% ist die Dimmung")
GF_Kitchen_Light1.sendCommand(0)
GF_Kitchen_Light2.sendCommand(0)
logInfo("Bewegung Küche", "Ende der Regel -> Timer aus")
waitTimerKitchen = null
}
}
]
}
}
end
all is working fine, except this part:
} else {
logInfo("Bewegung Küche", "Check ob Lichtstärke verändert wurde")
if (GF_Kitchen_Light1.updatedSince(now.minusSeconds(119)) ||
GF_Kitchen_Light2.updatedSince(now.minusSeconds(119))) {
KKL.sendCommand(ON)
} else {
which never seems to really be triggered. Do I need to connect it somehow to my persistance? I’ve rrd4j and an influx running (the later one since some time only, to tap into this DB and experiment a bit with Grafana).
For lack of creativity, I’ve decided to send an ON command to the KKL item. This is a groupswitch of both lights.
Any help & guidance on how to use the updatedSince function correctly, would be appreciated.
thanks,
Kurt