Hello,
im quite new to OH and just trying to figure out how Rules are working. Id wanted to create a Rule with my Lux/Motion-Sensor to trigger my Lights(Dimmer) in the Kitchen.
The Light goes on when Motion is detected - this ist workin in my Rule - but when it comes to the End of the Rule nothing happens.
I wanted to Swtich the Lights out after the MotionDetector geos to state off…
Maybe someone can help
Her`s my Rule
rule "kueche bewegungsmelder"
when
Item XiaomiBewegungsmelderKChe_Motion changed
then
switch XiaomiBewegungsmelderKChe_Motion.state {
case ON: {
if (XiaomiBewegungsmelderKChe_Illumination.state < 42 && now.getHourOfDay > 7) {
Licht_Kueche.sendCommand(100)
}
if (XiaomiBewegungsmelderKChe_Illumination.state < 42 && now.getHourOfDay <= 7) {
Licht_Kueche.sendCommand(30)
}
}
case OFF: {
if (XiaomiBewegungsmelderKChe_Illumination.state == 100 || XiaomiBewegungsmelderKChe_Illumination.state == 30) {
createTimer(now.plusSeconds(20), [|
(XiaomiBewegungsmelderKChe_Motion.state == OFF) {
Licht_Kueche.sendCommand(OFF)
}
])
}
}
}
end
I want to check if the LIght is 100 or 30% (Dimmer) and if so the and the MotionState is OFF (case OFF), the Timer should Start for 20s to turn the LIght out when no Motion is detected during the Timer.
OK
Your code check it the illumination is 100 or 30 which it will almost never be
You need to check if the illumination is more than 30 AND less than 100
Also you were missing an if in the timer lambda
when
Item XiaomiBewegungsmelderKChe_Motion changed
then
switch XiaomiBewegungsmelderKChe_Motion.state {
case ON: {
if (XiaomiBewegungsmelderKChe_Illumination.state < 42 && now.getHourOfDay > 7) {
Licht_Kueche.sendCommand(100)
}
if (XiaomiBewegungsmelderKChe_Illumination.state < 42 && now.getHourOfDay <= 7) {
Licht_Kueche.sendCommand(30)
}
}
case OFF: {
if (XiaomiBewegungsmelderKChe_Illumination.state <= 100 && XiaomiBewegungsmelderKChe_Illumination.state >= 30) {
createTimer(now.plusSeconds(20), [ |
if (XiaomiBewegungsmelderKChe_Motion.state == OFF) {
Licht_Kueche.sendCommand(OFF)
}
])
}
}
}
end