New to Rule Machine - need help room lights

So I have many light switches and plugs but finally got some motion sensors to test this out.

I was able to set up a rule that when motion was sensed the light came on. But then it went downhill...

  1. Do I need a separate rule for the lights to go off? Can this all be in one rule?
  2. I really need to set parameters. I know "restrictions" were part of the old rules but those are gone now.

Here's what I'd like the rule to be:

  1. When motion is detected between 7:15AM and 11:00PM the light should go on (I think I got this to work, but not sure I did it the right way)
  2. Between 8:30AM and 6:00PM, if there is no motion for 10 minutes the light should go off
  3. From 6:00PM until 8:30AM the light should go off after 45 minutes of no motion

I think this is the best way for me to handle the light in the bedroom. Part of my issue (and maybe there is a better way to handle it) is that if we are up and reading in bed, I don't want to have to start waving my arms to keep the lights on. Not sure if there is a "presence" mode for my phone being in the bedroom. But I am certainly open to suggestions.

I appreciate any help with this. I think once I see how this rule is done, I'll be able to adapt it to my other rules.

Thanks again!

It looks to me like you really have three screnarios defined.

  1. If motion Active between 7:15am and 8:30am, turn on the lights (but do not turn them off)
  2. If motion active between 8:30am and 6:00pm, turn off the lights. If motion inactive for 10 minutes, turn off the lights.
  3. If motion active from 6:00pm to 11:00pm, turn on the lights. If motion inactive for 45 minutes, turn off the lights.

If you think about your requirements like shown above, I think you may find it simpler to attack this problem in more manageable chunks.

Thanks! I can do the following:

If motion between X and Y turn on the lights.

But how do I add, if inactive for Z minutes turn them off?

I may have gotten it, rule machine is not quite as simple to figure out

I made trigger Motion Active and Motion Inactive
Then I made:
If Time between X and Y and Motion Active then lights on
Else if time between X and Y and Motion Inactive then lights off with 10 min delay

is that correct?

That should work OK.

Just for info though, you could have just used trigger Motion changed
This will cover both active and inactive.

I know I sound like a broken record to people who read my posts, but if you haven't checked out Motion Lighting or even Hubitat Simple Lighting, I'd encourage you to see if that fits your needs first. I think they can handle everything you're asking for, though you'll need three separate child apps.

If you do want to use Rule Machine, I'd suggest readingthe documentation if you haven't already. There is a basic motion-lighting example you could base yours on in those docs--you'd just have to add in conditions for the time (which will make it much longer than that simple example, but it should provide a framework to start from).

Where you'll have to get creative is the "if we are up and reading in bed, I don't want to have to start waving my arms to keep the lights on" part. There are a few workarounds I can think of:

  1. Assuming you don't want to use a location mode for this (I personally wouldn't), you could create a virtual switch that you turn on when you're reading and use this virtual switch as something to extend the "off" delay (or even eliminate that entirely). This could be added as another condition in the rule when creating the delay (if you want to keep it but just lengthen it) or elsewhere (if you don't want "off" at all). You could turn this on/off via voice control (if you have such a device) or a Dashboard tile (if that's not too much hassle). Perhaps you could make it automatically turn off under certain conditions too if you forget (time, no motion for a really long time, lots of motion elsewhere, etc.).
  2. Consider a more sensitive sensor closer to where you are, like an Iris v2 or a Dome DMMS-1 on the highest sensitivity, and maybe mount it on or near your bed/nightstand/etc. When close, it's likely to detect smaller movements than hand-waving. Add this sensor to your automation however you see fit (whether it's to turn and keep the lights on or just keep them on--you may want the latter if it's also visible from a hallway you might just walk by).
  1. Get really creative: consider the possibilities with a pressure mat and an open/close (contact, a.k.a. door/window) sensor with external contacts. Under my living room couch cushions, I have a pressure mat whose (dry) wires are hooked up to a Z-Wave contact sensor that has external contacts (the Ecolink 2.5 would work well here; the similar Monoprice 15270 would also work if you solder the internal contacts closed, and I think both require setting a parameter to enable the external ones). When pressure is applied to the mat, the Z-Wave contact sensor closes. You should be able to do something similar with a bed and a sensor under the mattress (may need the pet-resistant variety to eliminate the mattress weight itself as something that could close the loop). Then, when the sensor is closed, don't turn off the lights even if the motion sensors go inactive (or if the app you're using doesn't support contact sensors, use a custom driver or virtual device plus a rule to present it as one instead).

Hope some of this helps!

1 Like

Does "inactive" mean the same thing as "no motion"?

So, if I put inactive then lights off with 10 min delay, I perceive that to mean that if there is any motion during that 10 minute period it will restart the 10min clock. However if there is no motion for ten minutes then it should turn off.

is that correct?

Yes. Active = motion detected.
Inactive = no motion detected. (After the devices time out period. Some detect motion and stay active for 30 seconds before changing to inactive).

To have it cancel the turn off you need to turn on 'cancel' against the 10 minute delay and then it will do as you have described above.

You also need to have a "Cancel Delayed Actions" somewhere (often in the other half of an IF...ELSE depending on your triggers) for that to do anything. Perhaps that was mentioned before and I missed it. (This is a departure from the Rule 3.0 paradigm.)

To the original poster, there is a simple example of what is being discussed here with motion in the Rule Machine 4.0 docs I linked to above. I know it sounds boring, but they're helpful and I'd encourage you to read them. Again, that example would be a good starting point (assuming you do want to use RM for this).

Good point. I just grabbed the screenshot to show the 'cancel' button and forgot about the 'cancel actions'.
Oops. :blush:

Triggers motion changed

IF motion Active THEN
Turn ON light
IF(time between 7:15am AND 11:00pm) Turn ON light (option A if used delete line above)
Cancel Delayed actions
IF(time between 8:30am AND 6:00pm) turn OFF light delay 10 mins
IF(time between 6:00pm AND 11:00pm) turn OFF light delay 45 mins
IF(time between 11:00PM AND 7:15am) turn OFF light delay ? mins (option B?)

Notice no OFF for between 7:15 and 8:30

but i think motion lighting would do this. I use modes

for you bed you could have power monitoring on you phone charger?

thanks.. is this exactly what mine should look like?

Whats the options?

depends on you exact scenario your need to be more clear to be sure. The options are for do you want it to only turn ON between 7:15 and 11pm if you do then delete the 2nd line but keep the 3rd simple IF condition.

option B is if you want the light to still auto OFF after X time between 11pm and 7:15

I have attached 3 pictures - one for each rule/time block. Not sure if this was done the best way, but based on a prior suggestion I made them like this. (it looks like they are all running into each other - at least to me, so they all start with the "select trigger events" box and end with the "select actions to run" box)

  1. does this make any sense? Am I close?
  2. Where/how do I do the "cancel delayed actions"?

Any tips would be greatly appreciated. In the mean time I'm going to re-read the suggested documentation again.


This is where it should be one rule not 3. I'll create one for you in a bit but please confirm this.

1 . You only want it to run between 7:15 and 11pm so not ON OR OFF outside them hours.
2. Between 7:15 and 8:30 you don't want it to turn OFF

Yes and NO

For knowing what you want I believe so fir understanding RM on how to run through a script not quite but will get you there.

Did you look at motion lighting?

Yes 715-11p bc I don't want motion turning it on at night when moving in bed. And before I knew about cancel motion I was leaving it on from 715-830, but now Just add it to the second time period, 715-6 with a turn off after 15 min. And the evening shut off after 45 min. Both with cancel.

Thanks for your help. Can't wait to see how this is supposed to look.

personally this is what i would do using motion lighting. substitute home for morning mode for you( 7:15 to 8:30) evening for day (8:30 to 6:00pm) and night for evening (6:00pm to 11:00pm)

its easiest to use modes so create some and use mode manager to decide when the house should be in each mode. then you can do lots more with the modes including arming and disarming.


if your really want to use RM 4.0 this should work (notice the extra complex set up)

may still be a better way to do this :thinking:

Edit: no there would be a error with this if it was active when it changed to 11:00PM it wouldn't turn off

1 Like

What is private Boolean? And why is it more complicated in RM4?

it's a condition that is linked to the rule that allows you to use it and test against it. In this case i'm using it to stop ON constantly being sent each time the motion goes active when the light is already ON.

because you should do stuff like above and it's harder to work with due to having to plan and think about the rule more.
the UI for motion lighting is designed for this exact set up. The HE staff say its always best to KISS so why reinvent the wheel when it's there ready to be used and can do what you want with its eyes closed and more.

Don't get me wrong RM is awesome and i use it alot but i only use it if i have to, if there is a simple way to do it in another app i use that.

happy with below now though

but again i would use modes and do this

1 Like