Simple Motion Rule Question

Hi,

i have moved from Fibaro (lua) to openhab and trying to find a solution for my motion sensors rule as it was on fibaro system.

I want to switch lights as long as there is movement.
On lua it was running with a “for” loop

so i have did it with createTimer, triggering per “received update” from motion sensor.
most motion sensors have just a simple contact “open” as long is motion.
the problem is when the timer has expired the lights will turn off

on lua was realized with for loop with 1s sleep and checking if contact is open then stay in loop, when get closed get out loop and turn lights off.

this scenario seems to not work with createTimer and triggering with received update, couse motion will not update as long is motion.

any ideas ?

I think a good way is to use a rule like this:

rule "DoorSensor06 Motion Event"
when
Item DoorSensor06_MotionAlarm changed to ON
then
… turn on the light
end

But keep in mind, the sensor will change to off if no motion is detected within 24sec. This will turn off the light very fast. Try to play with expire binding. This looks like the best way.

item:
Switch Motion_01_Timer { expire=“1h,command=OFF” }

rule "Motion sensor triggered"
when
Item DoorSensor06_MotionAlarm changed to ON
then
Motion_01_Timer.sendCommand(ON)
end

rule "Lights on by motion"
when
Item Motion_01_Timer changed to ON
then
… turn on the light
end

rule "Lights off by no more motion"
when
Item Motion_01_Timer changed to OFF
then
… turn off the light
end

thankyou, this should work.

what happens when
Switch Motion_01_Timer { expire=“1h,command=OFF” }
gets ON command while its ON, will the expire timer restart ?

Here are the docs

“yes”, it will restart the 1-hour

thx, it is working, but the problem on “continous” motion is still there.

f.e.
Switch Motion_01_Timer { expire=“30m,command=OFF” }

if there is continous motion (contact state is always “ON” within expire time, expire time will not restart

Yes. That is very unusual kind of motion sensor, or maybe it is installed in a railway station. Are you using something that already has a timer built-in for directly working lights?

event-driven openHAB does not make it easy to deal with steady states, but it can be done. You’ll probably need to separate functions here ; trigger the light on when motion starts, start the delay timer when motion stops.

its fibaro motion sensor.
ive found a solution, its parameter 6. Motion Alarm Cancellation Delay in seconds. (be also carefull with blind time parameter)
thx @ all

its working.

here is final rule with fibaro motion sensor + rgbw + switch. running on latest snapshot #931
maybe it will help someone

requirement: expire binding

item:
Switch Motion_05_Timer { expire=“40m,command=OFF” } // MoLagerunten

rule:

//############################
rule "MoLagerunten"
when
Item zwave_device_06074ec7_node43_alarm_motion changed to ON or
Item zwave_device_06074ec7_node13_alarm_motion changed to ON
then
Motion_05_Timer.sendCommand(ON)
end
/////////////
rule "rMoLagerunten"
when
Item Motion_05_Timer received update
then
       if (Motion_05_Timer.state==ON ) {
                 zwave_device_06074ec7_node46_switch_dimmer2.sendCommand(0)
                 zwave_device_06074ec7_node46_switch_dimmer3.sendCommand(100)
                 zwave_device_06074ec7_node46_switch_dimmer4.sendCommand(60)
                 zwave_device_06074ec7_node41_switch_dimmer2.sendCommand(0)
                 zwave_device_06074ec7_node41_switch_dimmer3.sendCommand(100)
                 zwave_device_06074ec7_node41_switch_dimmer4.sendCommand(60)
                 sendCommand(zwave_device_06074ec7_node40_switch_binary, ON)
                 sendCommand(zwave_device_06074ec7_node24_switch_binary, ON)                
        } else { 
                 sendCommand(zwave_device_06074ec7_node46_switch_dimmer, OFF)
                 sendCommand(zwave_device_06074ec7_node41_switch_dimmer, OFF)
                 sendCommand(zwave_device_06074ec7_node40_switch_binary, OFF)
                 sendCommand(zwave_device_06074ec7_node24_switch_binary, OFF)
        }
end

For the Aeontec Multisensor 6 I let the device do the timing.
There is a device configuration parameter: 3: Motion sensor reset timeout that sends OFF after the last trig. I have set this to 600 which gives a 10 minute no activity timeout.
This sensor always sends an OFF so it can be trusted doing the timing.

The rule is then very simple, but the device sends multiple OFFs (polling?) so I introduced a bool in my rules so that the OFF actions are only executed once:

var boolean onLR = false

rule "MotionCloset"
when
        Item ClosetMovement received update
then

        logInfo("Motion", "ClosetMovement.state=" + ClosetMovement.state)
        if (ClosetMovement.state==ON) {
        	onLR = true        	
        	MotionTimeOn.postUpdate(LocalTime.now().toString() + " (" + LocalDate.now().toString() + ")")        	
        	sendCommand(WallplugClosetLamp, ON)        	
        } else {
        	if (onLR) {
        		onLR = false
        		MotionTimeOff.postUpdate(LocalTime.now().toString() + " (" + LocalDate.now().toString() + ")")        	
          	    sendCommand(WallplugClosetLamp, OFF)        	
        	}        	
        }
end

Rules can be triggered on Item changed

1 Like

Makes rule even simpler :slight_smile:

hI

Please could you share your settings. i am totally stucked

the lamp do not get turn off