Help with a conditional rule

:smiley: For RM4, it's under "Delay or Repeat Actions, Wait", bottom of the list.

1 Like

Yup I see it now. Thank you.

My wife says I have trouble looking to the back of the fridge as well.

1 Like

I have a question - can't you move the cancel before the IF? Is that reasonable?

Yes you can as @JNS said.
But would it make any difference ?

I have just realised that this rule is turning light off even when light was already on.
And this is not what I want.

I've made this modification :

Will it work ?

Yeah I goofed not reading through the whole thing - a seemingly chronic problem of mine lately! {slows down, takes deep breath}. I need to revisit some of my rules as some of my programming experience is getting in the way of my RM creation I think. Thanks for the discussion!!

Use the built in motion lighting app

No because you only cancel the delay if it's OFF.

This is why it's a much easier in the motion lighting app and B if you do want to use RM then use 'changed' and a IF ELSE statement.

Hi guys,

Rule is working great for what it was meant to do, but I realized that I have an issue to solve now.
When I get home it's already dark and light is turned on by this rule as soon as motion is detected, so far so good. But in 3 minutes light is turned off and it enter in a loop as whenever I try to turn light on manually, this rule automation detects motion again and turns it on before I reach wall switch, then turns it off in 3 minutes again and again.
Well, what I need is a rule smart enough to know that I'm in the living room and keep light on until there is no motion activity for a while.
Sorry if I am asking too much, but I'm not a programmer and I'm excited to learn to program these rules.

There are a couple of problems with your rule. You stated earlier that you wanted to play and learn Rule Machine so the rule I provided isn't complete.

If you look at the logic of your rule the IF will only be executed if Lux is < 10 AND the light if OFF so the light will not be turned back on until it turns off. You need to remove the condition for the light being OFF. I would also move the 'Canceled delayed actions' outside of the IF THEN statement. If you also want to control the light outside of this 'motion rule' you will need to track a private boolean or variable whenever you don't want this rule to run.

Thanks JNS,

The more I play, the more I realized that I know nothing.
Do you recommend any guide/documentation for me to learn RM rules ?

I would start with reading the following. If you're new to this type of thing my recommendation would be to review other rules, ask questions and just play with it. All of the sudden a light bulb will go on and it will all make sense.

This was written before RM 4 came out but the basics are the same.

This document covers the changes in RM4

Here is another thread discussing using RM for motion lighting.

This link will take you to a list of example rules.


Do you think this rule would work ?

This will not work. Before I go any further. Will this light only be activated by motion or do you want to be able to override the rule with a switch?

Yeah, I want to override the rule by manually turning it on or off.

What will you be using to turn the light on and off? Is this a smart bulb, smart switch or dumb switch?

This is a smart (zigbee) switch.

Does the switch report a physical press?

Edit: that won't really matter for this. The first thing you need to do is have a way to track whether the light was turned on by the switch or by motion. You can do this a couple ways.

  1. Create a virtual switch
  2. Use a private or global boolean

I have no idea what that switch is and what capabilities it has.

Edit: is that setup as a button device?

I have to head out in 10 minutes for the evening.

Let's start with a stripped down rule.

First create a virtual switch and create a rule that toggles the virtual switch when you physically turn the light on and off. This will be used in the motion rule to determine how the light was originally turned on.

Download the Hubitat app