Turn light on when motion starts


#1

1) Give a description of the problem
So simple but I can’t get it to work…

2) What is the expected behavior?
Turn light on when motion starts.
Stay on until motion stops for 2 minutes
If light gets turned on by switch, stay on until 2 minutes after motion stops.

Please help…


#2

Hey dutchman71 I am new to this but was going through a similar issue and had a similar thread. I have successfully created this scenario in the example below. Not sure it makes a difference the one thing that is different is I went with 4 mins if no activity before turning the light off. I did this because I noticed depending on the pir I was using sometimes 2 mins was not enough time for the device to acknowledge the change.

so see below and hopefully it helps. Also feel free to use the import code to restore into your instance and assign your devices and see if it works.

devices I used in the below are a aeon labs micro switch in wall - for light control and a ezmulti pir plug in multi sensor.


#3

@anthonymorris’s method works just fine…but there are more ways to skin a cat and I prefer to use a ‘wait’ instead of a second trigger:

The ‘wait’ and everything after it (in this case the turn off command) gets cancelled if motion starts up again.

As I said, both methods will work but the above is slightly quicker to build and easier to add to in the future should you want to make it more complicated.


#4

Thanks guys, you make it look so simple… Working like a charm, learned something new.


#5

After doing a little testing with your solution it appears that when the light gets turned on by the switch without going in the closet, the light will not turn off after 4 minutes. Do I need to add another statement for that scenario?


#6

yeah, for that you’ll need a separate IF statement… can be done in the same piston, something along the lines of:

IF
age ([MotionDeviceName:motion]) is greater than 270000 (that’s 4 1/2 mins)
Then
turn off the light

Alternatively you could tweak the existing block to:

If motion IS active
OR
Light changes to on
Then

But this is untested and might cause issues with the use of a trigger alongside a condition (the condition may not trigger the piston??)


#7

Sorry for hijacking an old thread but I have successfully implemented this piston and its working well for me. However, I’d like to add a condition for the switch to come on only a maximum of once per hour. How would I do that?


#8

This should do it, just change $currentEventDevice to your motion sensor (I didn’t have a motion sensor to select).


#9

michicago thanks for your assistance. I’m not a programmer and only understand the basics. With that said, I modified your script a bit to suit my case, and I think in principle I’ve kept the the logic the same. However, the piston doesn’t execute. The switch (actually a wemo outlet) never comes on under any circumstance. Any ideas why?


#10

I wonder if it’s because the last On variable isn’t initialized. Can you post a log of the piston executing once based on motion?