Raise Light Level Temporarily Based on Motion

Here's another tough one - well for me anyway.

I want to do the following:

At Sunset(-20) turn on light1 and light2 and set to 25%
turn off at Sunrise

If motion1 is active while light1 or light2 are on
set level light1 and light2 to 100%
after 10 minutes set level to 25%

Easy enough to make one rule to turn on/off and set level.
Easy to create motion rule while lights are on to raise to 100%
But how do you end the motion period by setting level back to 25%???

2 Likes

Have the false for the Motion even turn the lights back to 25% instead of turning them off. And whatever rule you have turning them on at sunset and off at sunrise should also set the PB to false at Sunrise and True at sunset for whatever rules are raising and lowering the lights during motion events. So, if you wanted to do it simply:

Condition: Motion Active
If True set dimmers to 100%
If False set dimmers to 25% with a 10 minute delay with a cancel on truth change.

1 Like

Just have to say, @Ryan780 you are a freakin' genius. I forgot all about the cancel on truth change in a similar rule I wrote and I have been banging my head on it for at least 2 days now. LOL

1 Like

I know the feeling, trust me. :slight_smile: Glad I'm not the only one.

1 Like

@Ryan780 so it should look like this:?

Used the TOD restriction vs AND in the condition - should work, right?

2 Likes

Yup.

I will need something very similar for my bathroom light. Between 11 pm to 6 am, turn on scene to set light at 20% but on motion, set to 80%, till no motion for 5 mins. Do you know if this is possible from simple rule?

Should be but I got a bit confused with how itā€™s wordedā€¦ let me know if I understood:

  • Between 11pm and 6am
  • If motion is active
  • Set dimmer to 20%
  • Wait 5 minutes
  • Set dimmer to 80%
  • Wait for motion to be inactive
  • Turn dimmer off

Did I understand that correctly or completely mess it up?

Also, out of pure curiosity, what is your use case for going from 20% up to 80% before turning off the light?

Sorry for the wording! let me try to better lay down my intent:

  • Between 11pm and 6am
  • Set dimmer to 20% (working as a sort of night light)
  • If motion is active
  • Set dimmer to 80%
  • Wait for motion to be inactive, for at least 5 mins
  • Turn dimmer back to 20%
  • post 6 AM, turn dimmer off

That helps, thanks!

Let me try to clarify one last time just to be sure I got it right:

  • At 11pm set dimmer to 20%
  • If motion is active
  • Set dimmer to 80%
  • Wait 5 mins
  • When motion is inactive
  • Set dimmer to 20%
  • At 6 AM, turn dimmer off

Did I get that right?

Iā€™ve been up working for 23 hours straight today so bare with me please! Haha

Yes, that 99% correct. Just that if there was some motion, then it should wait for inactivity of atleast 5 mins, before going back to 20%

Ok so keeping in mind Iā€™ve been up for almost 24 hours now and that there are many many many many ways to do this in rule machine I am going to share the more complex example first because if I do not scare you I do think this is the best way to set yourself up for the future.

So this is how the current sleep deprived version of me would do it to minimize unnecessary hub resources and give yourself a bunch of extra options in the futureā€¦

1. Use a hub variable (Boolean with a Switch connector) to manage day and night (if itā€™s easier, modes would also work).

Basically Iā€™d create a virtual switch (named ā€œvarLux1CurrentStateā€ in my example) so that when the switch is on, itā€™s day time and when itā€™s off itā€™s night time.

While a little more work to setup initially this gives you a ton of flexibility later as you can change the start time for day or night in one rule to flip the switch and then use that switch in a bunch of other rules later if you want/need in the future.

2. Create a separate morning and night rule (modes could also be used)

While you could create one giant rule that does it all this would likely create a bunch of unnecessary trigger events constantly running to check the time and run unnecessary conditional statements. This one rule would be minor but create enough of these and youā€™ll start to experience performance issues.

In the 6am rule example below I add a predicate that my virtual switch is ā€œoffā€ meaning itā€™s currently set to night before the single trigger at 6am. Once 6am hits, I turn the virtual switch to ā€œonā€ to indicate itā€™s daytime and tell the dimmer to turn off.

Similar for the 11pm rule below, I make sure the virtual switch is ā€œonā€ meaning itā€™s set to daytime then at 11pm I set the switch to ā€œoffā€ to indicate itā€™s now night time and turn the dimmer to 20%

Once again the advantage to this is youā€™re really only pinging your hub two times and not asking it to do any crazy conditional actions (just flip a switch and set a dimmer) but most of all of you use this day/night switch for other rules and decide you prefer 10:30pm instead of 11:00pmā€¦ you only have to change the number in the single night rule.

3. Now that all that is setup all we have to do is write a simple motion rule (see example below)

Here we have a simple predicate so that it only runs at night (when our virtual switch is off) and it only triggers when your motion sensor detects active motion.

First thing it does is, if there is a delayed action already running in the rule it stops it. Then it sets the dimmer to 80%. As soon as your motion sensor stops detecting motion (most do this after 20-30 seconds) it tells your hub to wait 5 minutes and then turn the dimmer to 20%.

If your motion sensor goes active again anytime during that 5 minutes the rule will immediately re-run. It will cancel the previous 5 min timerā€¦ set the light to 80% (which itā€™s still at anyway) and wait for your motion sensor to go inactive before setting a new 5 minute timer.

This repeats indefinitely as long as the variable switch is off (night) and your sensor detects motion.

ā€”-

Thatā€™s it, I swear! Let me know if I totally overwhelmed you and I can share something simpler to setup but just keep in mind those options will likely put some unnecessarily burden on your hubā€¦ and those can really add up over time if youā€™re not careful.

So my post 2 years ago - I never got that to work as expected. I ended up using 2 time of day routines to turn on/off my lights and then this is my rule to raise level to 100 until 10 mins no activity - there may be a better way to do it, but I kept having issues where they would not turn off when desired or get stuck at 100 and this fixed it:

Screen Shot 2021-08-20 at 6.40.46 AM

2 Likes