Need help with Rule Xiaomi Motion Sensor


i need some help with a Rule for a Xiaomi Motion Sensor.

I want to check every 30 Minutes if lastmotion on the Motion Sensor is older than 15 Minutes and then shut off the light.

I have no idea how to do this. Can someone help`


Hi Karsten,

I was looking for the same thing. I think I will try this one with node red, but then without the light intensity.

But if it is possible to put this in a rule that would be nice.:blush:


Hi Rich,

that didn´t help me. i have the Motion Sensors already running. The have a DateTime State where there seen the last Motion. I want to create a Cron Rule that checks every 30 Minutes if the LastMotion is older than 15 Minutes and if yes switch off the Light.

Why not set a timer to turn off the light 30 minutes after the last motion without polling?

As a general rule, if you are polling, you are probably doing it wrong and there is almost always a better way.

The DP describes a better way. Then there is no need for the DateTime Item or a Rule to poll. Just one Rule to trigger when motion is detected and one Rule to run when motion wasn’t detected for 30 minutes (assuming you use the Expire binding example in the DP).

1 Like

This is what I use. Works with every sensor.

rule "Kitchen Motion Sensor ON" 
    Item EG_kue_motion_presence changed from OFF to ON
    if (EG_kue_motion_illuminance.state > 12){ //18 zuvor
        if(timerKue === null || timerKue.hasTerminated) {
            timerKue = null
            logInfo("Motion Küche", "Bewegung erkannt -> Licht an")
        else {
            timerKue = null
            logInfo("Motion Küche", "Bewegung erkannt -> Timer gelöscht")

rule "Kitchen Motion Sensor OFF"
    Item EG_kue_motion_presence changed from ON to OFF
    if (EG_kue_li_decke.state == OFF){
        return;} //false bevor
        logInfo("Motion Küche", "Keine Bewegung mehr erkannt -> Timer gestartet")
        timerKue = createTimer(now.plusSeconds(120), [ |
            timerKue = null
            logInfo("Motion Küche", "Timer abgelaufen -> Licht aus")

Credits to the forum, where I found the original code, which I modified for my needs.


The Problem is, that the Xiaomi Sensor give the State: true or false. Not ON or OFF.
Is there anyone with a hint to solve this Problem? I tried wit the xiaomi.js. I can see now “Ruhe” or “Bewegung” in my sitemap. But i can not work with it in rules.

Show us your Item type and your events.log showing state changes.

Not sure, how you connected your sensor.
I connected mine with zigbee2mqtt, which works like charm.

If you do as well, I recommend you this post: Zigbee2mqtt revisited: No more ugly transformations

You get rid of the transformation files, which makes the life much easier. There is also the correct setup for the motion sensors listed.

1 Like

THX so much!!! it works!

Works perfect for me. Thanck you.