Webcore Help with Turning off Light when no Motion

I have a motion sensor and a kitchen light hooked up via a smart wall switch. When someone turns on the light, i want it to go off 5 minutes after no motion is detected. But if motion occurs within that 5 minutes, the timer should restart.

How can I do this!?

Going crazy trying to get it to work.

This will do it.
Just import using the code and put in your devices.
This has a lux level as part of the conditions.
EDIT: Change the set level to turn on.
EDIT 2: Changed it for you. Import this one.

Curious why you have command optimization disabled on this one?

The light switches that I use are LightwaveRF which are stateless unfortunately.
So their state could have changed and ST would not know.
Because of that I disable command optimisation so that the commands will always run whether needed or not.

That would explain it, thanks.

1 Like

Thank You. I dont need the lights to turn on though. I only want them to turn off if there is no motion. So if my wife turns on the lights and then leaves the room i want them to turn off after 5 minutes.

If she turns them on, leaves the room and comes back 2 minutes later…the timer should go back to 5 minutes if there is no activity

Try this.

Thank you. I will try it shortly.

Or this.
Lots of ways to skin a cat!!! :wink:

I have this piston that does exactly that.

How about this?

1 Like

Thanks guys, this was a useful reference for me just now - nice to see a couple of different approaches as well.

What if there was never any motion to begin with. Meaning, my kids turned the light switch on, however, they never triggered the motion sensor. I’d still like to turn the light off if it was turned on manually, and the motion sensor didn’t sense any motion for 5 minutes.

Has any approach worked? This seems to be a common need for everyone but I didn’t find a solution that people said that worked. My code is like this:

With this the light turns on correctly and also turns off after 2 minutes, but if I am still in the room it doesn’t reset the timer and I have to be in a dark room for about half a minute before it turns on again.

@binil98 I believe you need to add a condition where if motion is inactive for two minutes, then turn the light off.

Your piston at the moment is essentially set as a 2 minute countdown as soon as the light came on, to turn it back off, not factoring in any existing motion.

I see the pistons here are like when motion is inactive then wait for secs then turn off which is not a correct behavior.

I think a motion needs to stay x secs in inactive then turn off the light. It should not check when the motion is inactive then wait x secs to turn off the lights because the motion can be activated again within the wait time.

Actually during the wait, if at any point the motion changes to active again, that loop is skipped, so it indeed is the behavior you are talking about, there’s no need to overcomplicate it. Try it out for yourself and you will see.

It skips after the wait? Interesting.
The simple way is just motion stays away from active for 5 minutes then if the light is one, turn it off.

I’m probably over complicating things, but I tried the last option mentioned here and the light would turn off and then back on, sometimes not even turn back on.

I ended up with this one and it appears to be working correctly:

Anyone have ideas to simplify it? I had a very simple Smart Lightning routine doing this but I’m moving everything to webCore now

[theoak] code works for me. Using “stay” put the timer on the duration of inactivity. So if new motion is detect, it stop the timer and restart from the beginning when it is inactive again.