New to community - creating first automation - motion sensor and lights


I am fairly new to the community and kinda lost in creating one of my first rules for Kitchen lights, I have a motion sensor (Sonoff) and two sets of lights (controlled by Lutron Caseta dimmer switches).

This is the scenario that I want to create but I am not even sure if all of these can be done within one rule or I should create multiple rules - I was trying to create these rules using Rule Machine, if there is another app that I should use instead please direct me to that.

  • If any of the lights are on and motion detected do nothing.
  • If both of the lights are off and motion detected and it's between sunrise and sunset turn the side table lights on at 75%.
  • If both the lights are off and motion detected and it's between sunset and 9pm turn the main lights on at 65%.
  • If both of the lights are off and motion detected and it's between sunset and 9pm and 11pm turn the main lights on at 35%.
  • If both of the lights are off and motion detected between 11pm and sunrise turn the side table lights on at 20%.
  • If any of the lights are on and motion not detected for 1 minute turn the lights off.

Let me know even if my logic is off as well.

Thank you so much and so happy to be part of this amazing community.

I use Hubitat's Mode feature to help with automation like you're describing. I use the built-in "Mode Manager" app to control the "Mode" of the hub based on time of day and whether or not anyone is at home. This "mode" can then be used in a variety of automations, instead of having to set specific times repeatedly in automations.

I then create a Hubitat Scenes using Hubitat's built-in "Groups and Scenes" app, to capture the lighting I want for various modes of Hubitat. Each Scene can include multiple lights, with different on/off/dim states.

I finally tie it all together using Hubitat's built-in Motion Lighting app as shown below. There are a lot of options available in that application. IMHO, it is worth exploring and seeing if you can achieve your goals using it versus jumping into Rule Machine.

Hope this helps a little.


While your needs can be met easily with the Mode & Motion lighting app as pointed out above by @ogiewon, I want to point out that the it would be very simple to also create this as a single rule in Rule Machine, which I have pasted below as an example:

This rule will run only when both lights are off (Bar & Dining in my example). They are triggered by a motion detected event, and turn on either bar or dining to a different level depending on the time of day, with the times chosen from your example.

The rule also tuns off both lights when motion is not detected for 1 minute.

Hope this helps!


I second @ogiewon 's suggestion of motion lighting, but also acknowledge that sometimes simpler rules can be setup as @aaiyar suggests as well.

Not so much a problem with your logic, just a nuance to rule design to be aware of:

These two may bring you unstuck if you don't treat it correctly. If the lights are on when motion is detected and your rule / automation does nothing, you need to make sure you detect that this is what occurred, and not react to motion becoming inactive and turning off lights someone turned on or another rule / automation is controlling. @aaiyar 's rule handles this with the combination of the Required Expression and the fact it is triggered by motion becoming active. The Required Expression means the rule will not even look for the trigger occurring and so will not fire if any of the lights are on. If they are off, and the trigger of motion fires, then that sets in train the turning of the lights on and detection of when motion becomes inactive.


This definitely helped a lot, and helped me learn the concepts of how the motion and mode lighting app works. I've created my rule per your suggestion and everything seems to be working fine, except that I am losing my connectivity to the motion sensor constantly, but when it's connected the rule seems to be working fine. I will try to recreate the rules using @aaiyar suggestion in order to get myself familiar with Rule Machine as well (Thank you sir). @sburke781 correct! That's why I had provided my logic too, I know that I have to find a fine balance between control and automation - my partner wants full control (she had Audit background) and I personally want full automation (I have IT background) lol it seems Rule Machine is very powerful in terms of customization but I need find my way around it first.
Thank you all for the help.

Off-topic, the Sonoff motion sensor is the first sensor that I have installed, so far I have a few Philips Hue lights, 2 Lutron Caseta (wishing to change all of the light switches to this but slowly as these are expensive haha) - the sensor is around 30 feet away from the HE. Do you think that's the reason that the connection drops after a while? What do you recommend to improve this? I assume I should get some repeaters, but how close should be repeaters to each other? Thanks again for your help :slight_smile: