[SOLVED] Rule not working properly - Lights out after Timer

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
            if  (XiaomiBewegungsmelderKChe_Illumination.state == 100 || XiaomiBewegungsmelderKChe_Illumination.state == 30) {

What exactly does you want do test in this line?

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.

Hope my intention is clear ?

But aren’t you testing the lux sensor, not the dimmer value?

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

@rossko57 & @vzorglub
Thanks for your Help - this solved my Problem.
Thank you very much !

Bear in mind your rule will switch OFF after twenty seconds even if motion occurs during that twenty seconds.
See also

Please mark the thread as solved
hc_292