Help with Light Rule based on certain times and/or motions

Hello all, another Smartthings deflector here :smiley:

Need some help with a rule that I would like it to work like this.

Lamp turn on daily at 4:35pm. Turn off daily at 9:30pm unless any 4 motion detectors downstairs detect motion then keep Lamp on until no motion is detected for 20 mins. After 20 mins of no motion detected at all, then that lamp can turn off.

I then have another rule that I created based on that lamp being off, that I believe I created correctly. If that lamp is off, then I want a light on the staircase to turn on when motion is detected by the motion detector mounted near the staircase (not one of the 4 above) and to turn off after 30 seconds delay of no more motion.

Any help would be appreciated. Thank you.

First the easy one...I would create a "Trigger" for 4:35 pm that turns the light on.

The next rule is going to sound counter intuitive but just trust me. You create a "Rule" that has the following conditions:

  1. a time range of 9:10 until some time you pick and you have within that range be true
  2. All 4 motion sensors together and and have ALL be INACTIVE.

Then when you go to build the rule, attach them with an and.
In action for true have a delay of 20 min with cancel on truth change + turn the lights off.
Put no actions in action for false.

Then, when the time is after 9:30 with no motion the lights will go off.
Now, you didn't say you wanted to turn the lights back on if motion was detected after 9:30 and the lamp was off. But that would be another triggered rule, IMO.

I trust you and I'm going with it :slight_smile:

Once the lamp is off I do NOT want it to turn back on. It's done its lighting job for the day. The next lighting job will be for the staircase light until Sunrise.

What happens if there is motion until 9:29pm and it stopped for a few minutes. Would the Lamp then turn off at 9:30pm? I want the lamp to basically stay on for at least 20 min until all motion stops on the 4 motion detectors I will be putting in that rule. Ideally a scenario of motion happens until 9:29pm which means we are still downstairs, so the rule at the earliest will turn off the lamp 20 mins after that last motion so 9:49pm as long as no other motion was detected. If motion was detected after 9:29pm then it will stay on until 20min of no motion is finally true.
I do not want a case of where we are still downstairs past 9:30pm and the lamp is off for good because the last motion it detected was 9:29pm and then the next motion that happened was 9:31pm.

Hope this all makes sense.

I like virtual switches. So here's a variation using a Virtual switch and another rule.

Create a virtual switch. Then create a rule that turns on that switch at 9:30.

In the rule that Ryan laid out instead of a time frame make condition one be the virtual switch is on and condition 2 be all motion inactive, join them with an and. In the actions for truth also add turning off that virtual switch so it is ready for the next night.

Yeah...but that's having a REALLY unnecessary virtual switch. You only need two rules to accomplish this. Not 4.

On your #1. Does it matter what time range I set from 9:10pm to ???. What do you recommend based on what I laid out above?

True but with a time frame if motion continues past that end time, the rule will not be true and won't turn off the lights

Based on my comment above a long enough time that you are sure the motion will become inactive in that room. Is that an hour or could it be 3 am.

1 Like

Well, what time do you want it to stop turning the light off by lack of motion? It would all depend on how you have other things set up. I handle one lamp like this a little differently. I have one rule to turn the lights on by motion or mode change to night (which happens at sunset). Then I handle turning them off with lack of motion and a virtual switch being off. When mode change to night happens, the virtual switch is turned on as well as the action to turn it off after so many minutes. That way, the light stays on during this period of time since the switch is on. But my setup is a LOT more complicated. I would just use 3 or 4 am unless you're a real night owl.

It's only adding one rule and could also be done with 2. Have the first rule that turns them on be a time frame from 4:35 to 9:30, truth turns on lights and false turns on virtual switch.

1 Like

If that works for you, great. But a "beginner rule" that ain't. I am a firm believer in crawling before you try and run a marathon.

1 Like

Really I don't ever want it to stop try to turn off the lamp. Wether its past 9:30pm or even 3am. When there is finally no motion for 20 mins whatever time it is before daylight finally comes into the house, I would like it to turn off. So I guess making it 5am or something would be the best/only solution.

I don't know how it would handle a range of 9:30pm to 4:30pm. But you could try that. that way it would fire even during the day.

I figure worst case if there is still motion happening downstairs at 5am and the rule couldn't trigger an off then I could just turn off the lamp manually. Hopefully never have a situation like that.

Pretty simple logic really. At 4:30 turn on the light at 9:30 turn on the switch. If the switch is on and motion stops for 20 minutes turn off the lights whether motion stop is at 9:50pm or 10am doesn't matter.

For this: In action for true have a delay of 20 min with cancel on truth change + turn the lights off.

Would that be the option for "Turn On or Off these switches after a Delay, pending cancellation (Default is Off) ?

That seems interesting as well. I will have to read up on Virtual Switches.

@AP1 a Virtual Switch (or dimmer or thermostat...) are often used as "storage" -- to retain some condition or state. In the example above, it's retaining the answer to the question of "what time is it?" and the answer is, it's between the times you are interested in, or it's not. True/False == On/Off

Elsewhere you will see Virtual Dimmers holding numbers. You set the Dim to 30, 60 or 90 and then can test to see which one it was. It's a Variable, an Integer Variable while a Virtual Switch would be a binary variable. :smiley:

A more common use is to create a Word (or set of words) that Alexa or Google Home might respond to.

I can create a Virtual Switch called "the pod bay doors hal" and an then ask Alexia to close the pod bay doors hal. The state of that Virtual Switch would then, via a Rule, actually close or open the Garage Door Opener.

2 Likes

Go to devices, in the upper right pick add virtual device.
image

Then create the first rule. I also added turn off the virtual switch at 4:35 to make it bulletproof. So if some reason motion stays active until after 4:35pm the next day and then goes inactive before 9:30 they won't turn off early.

image

2nd rule

image

1 Like

Wow! Thanks so much Drew. I will give it a shot!

1 Like