Help with lights dimming and brightening with motion sensor


I am a new HE user (4 days) and I am having heck of a time trying to figure out how to get a rule working properly. I am a decent IT guy but sucks at programming.

I would like to:

When the this light is already on, and when a motion is detected, turn the this light to 100%.
after 5 minutes with no motion, turn it down to 5%.
if motion starts before that 5 minutes timeout, keep light at 100% and start counting 5 minutes again after the motion stops, cycle repeats.
If the light is off, don't do anything.

What I know is my motion sensor (Bosch Zigbee PIR) triggers for 3-4 seconds, then won't trigger again for about 4 minutes.

I have been looking online for examples that I can use. This is what I have so far...

I am running into a issue by looking at the log.

Instance collision

Looks like multiple triggers of the same rule. How do I fix this?

And lastly, is this code ok for what I need? Is there a better / more efficient way to accomplish what I am looking for?

Thank you all!

Is there a reason you're using the running variable? There may be some oddity with your sensor that I don't understand (going "active" and then not generating another "active" event for several minutes isn't uncommon--and should be fine as long as it doesn't get stuck at "inactive" in the interim), so it may be simpler to leave that out. The only problem I see is that your lights are going to dim to 5% after motion stays inactive for 5 minutes since the ELSE will run anytime the IF condition isn't true, which would include any time the lights are off.

I'd start with something simple like this and see if it works for you:

Trigger: Motion active


IF (NOT Light is on) Exit Rule
Dim: Light to 100%
Wait for events: motion inactive
Wait for events: elapsed time --> 0:05:00
Dim: Light to 5%

(I'm using a slightly different paradigm than you did above since I think using the "active" trigger with "Waits" makes things easier than using IF THEN/ELSE with delays and cancellations, but it's otherwise pretty similar aside from how it handles the light already being on as something that will prevent anything from happening; that's a simple conditional, but you could make it a "full" one if you wanted or wrap this entire set of actions in such a conditional instead of using Exit Rule.)

1 Like

Thank you bertabcd1234! That was beautiful!

Question, I have another set up that uses 2 motion sensors to control one light. How would I go about setting that up? Because one of the motion will be motion "inactive".

Thanks again for your help!


You could write two sensors into a rule with a bit more work, but I'd probably take the easier route: use the built-in Zone Motion Controller app to "combine" those two sensors into a single sensor, then write a rule in the same manner as the above with that device instead.

It should also be noted that if you just want a normal "turn lights on with motion, then turn off" setup, then the built-in Motion Lighting or Simple Automation Rules apps can handle that without the "zone" sensor; you can just choose more than one sensor in those apps, and they do all the work for you. But because your "only change if on" and "dim instead of turning off" thing, you'll need something else (actually, I think you could trick Simple Automation Rules into doing this if you use the right restrictions and whatnot, but the rule is pretty easy to write and gives you more flexibility if you need it).

Ahh.. forgot about the motion controller app!

Thank you so much for this!!


You can achieve this simply and elegantly using the built-in Motion Lighting app coupled with a Scene.

First, create a scene called something like "Dim Main Entrance after motion", that sets your Main Entrance Table light to 5% brightness.

Next, create a Motion Lighting rule. The controls for selecting your motion sensor(s), light(s), and on/off delays are intuitive. The three less obvious settings you need are:

  • Add your Main Entrance Table light in the "Switch to disable turning on" setting
  • Activate the "Disable when off? Default is on" toggle under the "disable turning on" setting above, to achieve your desired rule of ignoring motion if the light is off
  • Add your after-motion scene in the "Activate a scene when turned off" setting
1 Like

I will try this. Thanks for the great suggestion!

The Zone Motion Coroller is great! I just discovered it myself. I use it to turn on the kitchen lights at a low level at night when approaching the kitchen from any of three possible directions.