Help with rule. When motion see you for 6 minutes

Hi
I have problem with this rule.
I need to have rule: if a motion see me for 6 minutes - turn lights
Now my rule is: if a motion see me for the second - turn lights after 6 minutes
Somebody help me

rule "P2 Biuro - RAMKA ON"
when
	Item P2_Biuro_CzujnikRuchu_Movement changed
then
	if(P2_Biuro_CzujnikRuchu_Movement.state==OPEN) { 
		timer_P2_Biuro_Powerbar_6 = createTimer(now.plusSeconds(360)) [|
		sendCommand(P2_Biuro_Powerbar_6,ON)
		sendMail("matcin@my.com", "P2 Ramka on", "TEST")
		]
	}
	else {
            if(timer_P2_Biuro_Powerbar_6!=null) {
                timer_P2_Biuro_Powerbar_6.cancel
                timer_P2_Biuro_Powerbar_6 = null
            }
	}

Hi,

looks like your rule will wait for 6 minutes after detecting the change and then turn the lights on. I think you mean something more like:

rule "P2 Biuro - RAMKA ON"
when
	Item P2_Biuro_CzujnikRuchu_Movement changed
then
	if(P2_Biuro_CzujnikRuchu_Movement.state==OPEN) { 
            sendCommand(P2_Biuro_Powerbar_6,ON)
            sendMail("matcin@my.com", "P2 Ramka on", "TEST")
		timer_P2_Biuro_Powerbar_6 = createTimer(now.plusSeconds(360)) [|
		    sendCommand(P2_Biuro_Powerbar_6,OFF)
		]
	}

Simply put; you want to handle the initial action and launch the countdown timer as soon as the change occurs. The timer will remain active in the background

Cheers,

PelliX

Not exactly what I need.
I need turn on device when motion see me for longer time (for example 6 minutes), not for only few seconds
I need it for my digital photo frame which I have in office. I wanted to use it (turn on) only when I stay longer in my office.
If I stay in office more than 6 minutes turn on frame and if office is empty more than 15 minutes turn of frame. I think that I need 2 similar rules. One for send command on and second for command off

Ah, I think I misunderstood you. In which case you just need to add a check to the timer:

rule "P2 Biuro - RAMKA ON"
when
	Item P2_Biuro_CzujnikRuchu_Movement changed
then
	if(P2_Biuro_CzujnikRuchu_Movement.state==OPEN) { 
		timer_P2_Biuro_Powerbar_6 = createTimer(now.plusSeconds(360)) [|
                    if(P2_Biuro_CzujnikRuchu_Movement.state==OPEN) { 
		        sendCommand(P2_Biuro_Powerbar_6,ON)
		        sendMail("matcin@my.com", "P2 Ramka on", "TEST")
                    }
		]
	}
	else {
            if(timer_P2_Biuro_Powerbar_6!=null) {
                timer_P2_Biuro_Powerbar_6.cancel
                timer_P2_Biuro_Powerbar_6 = null
            }
	}

Note that this is will simply check at the ‘beginning’ and the ‘end’ of the period of 6 minutes - it won’t account for the fact that you left for 4 minutes in the middle, or other such factors. Hope this helps.

Cheers,

PelliX

I will test it

It is working well,
pelnet thank you for help.
I want to add one timer more to this rule but unfortunate it is not working well
Motion should check 3 times.
If it sees me -> start timer
If it sees me again after 300 seconds -> send mail and start timer
And last if it sees me after 600 second -> send mail

rule "P2 Biuro - RAMKA ON"
when
	Item P2_Biuro_CzujnikRuchu_Movement changed
then
	if(P2_Biuro_CzujnikRuchu_Movement.state==OPEN) { 
		timer_P2_Biuro_Powerbar_6 = createTimer(now.plusSeconds(300)) [|
                    if(P2_Biuro_CzujnikRuchu_Movement.state==OPEN) { 
		        	sendMail("matcin@my.com", "P2 Ramka on", "test after 300s")
		        	timer_P2_Biuro_Powerbar_6 = createTimer(now.plusSeconds(300)) [|
		        		if(P2_Biuro_CzujnikRuchu_Movement.state==OPEN) {
		        			sendMail("matcin@my.com", "P2 Ramka on", "test after 600s")
                    }
                    }
		]
		]
	}
	else {
            if(timer_P2_Biuro_Powerbar_6!=null) {
                timer_P2_Biuro_Powerbar_6.cancel
                timer_P2_Biuro_Powerbar_6 = null
            }
	}
end```
/*rule "P2 Biuro - RAMKA ON"
when
	Item P2_Biuro_CzujnikRuchu_Movement changed
then
	if(P2_Biuro_CzujnikRuchu_Movement.state==OPEN) { 
		timer_P2_Biuro_Powerbar_6 = createTimer(now.plusSeconds(300)) [|
                    if(P2_Biuro_CzujnikRuchu_Movement.state==OPEN) { 
		        	//sendCommand(P2_Biuro_Powerbar_6,ON)
		        	sendMail("matcin@my.com", "P2 Ramka on", "test po 600")
		        	timer_P2_Biuro_Powerbar_6 = createTimer(now.plusSeconds(300)) [|
		        		if(P2_Biuro_CzujnikRuchu_Movement.state==OPEN) {
		        			sendMail("matcin@my.com", "P2 Ramka on", "test po 900")
                    }
                    }
		]
		]
	}
	else {
            if(timer_P2_Biuro_Powerbar_6!=null) {
                timer_P2_Biuro_Powerbar_6.cancel
                timer_P2_Biuro_Powerbar_6 = null
            }
	}
end*/

Hi,

glad I could help you on your way.

Now, I’m not entirely sure that I understand where you’re going with this, but I would suggest to use separate timer objects for the different actions. Although it may not prove to be necessary in the long run, it might help with debugging.

P.S.: Your first rule starts with ‘php’ ? Your second rule is commented out… but I presume that’s just for pasting it on the forum…

Cheers,

PelliX