# Rule Help

I am trying to understand the logic in RM4 so I am doing so by trying to recreate some of my existing rules for learning purposes.

I have a rule that turns off the exhaust fan in the bathroom 5 mins after the bathroom light is turned off.

Two questions...

Should I have the rule set to only turn off the fan if its on or does that not matter?
How do I setup the rule so that if the light is turned back on while the fan delayed off is counting down it cancels the delayed off?

Basically, you want to change the trigger to be Bathroom Light changed. Then, in your actions:

``````IF (Bathroom Light on) THEN
Cancel Delayed Actions
Bathroom Fan On
ELSE
Bathroom Fan Off  --> delayed: 0:05:00 (cancelable)
END-IF
``````

In my experience, that "Cancel" right off the bat logs an error message.

Perfect. That worked.

1 Like

I've been doing some testing and I am not seeing any errors yet.

I use it in every one of my motion rules and it's never thrown an error.

Would this also work. I ask because I am still trying to get these in a logical order that I can understand.

IF light On
THEN
Turn On Fan
ENDIF

IF light Off
THEN
Turn Off Fan , Delay 5 min. (cancel)
ELSE
Cancel Delay
ENDIF

That would work. Same idea, different way of coding it.

Yea! Thanks. Maybe just maybe I am getting a grasp on this!!

1 Like

It's confusing. That's why I am going through my existing rules to make sure I understand how they all would work with RM 4

1 Like

@cory I totally understand and I am sure that there are a lot of others that will agree. But the reason I put in my post was to see if the way I see it actually happening is correct. To me putting the cancel before the actual delay was throwing me. So putting things in the logical order seemed to help.

Do you always want the bathroom fan on if the light is on? If so, then I would use this rule. Otherwise I would remove turning the bathroom fan on in the first part of the action.

I would also add the fan itself turning off as a trigger and then part of the first condition to cancel the delayed actions. If you turn it off manually, there's no sense in trying to turn it off again later.

That is incorrect. If you are getting that, then please post your rule that is giving you that error. You should always cancel your delayed actions before doing anything else because if something else errors, your delayed actions won't be canceled.

This is overly complicated....Plus, why do you have two if statements for opposite conditions? that's what Else or Else If is for. By definition the light cannot be on and off at the same time, correct? So, I would move them to one if/else statement and make things easier.

This will also attempt to cancel a delay that doesn't exist when the light is on.

This makes no difference to the rule. If this matters to you, I would do this:

``````If:  Bathroom light off
Turn off fan after 5 min delay (cancelable)
Else
Cancel Delayed actions
Turn on bathroom fan
End-If
``````

But again, that surmises that someone would want the fan on whenever the light was on, which i know i don't. So, that part can be removed.

Question....should the first IF be Bathroom Light On?

No, she wants the fan to go off 5 mins after the light is turned off. What i had was right.

The bathroom light can only exist in two possible states, on and off. But if you prefer, you can make the else into an Else if like this:

``````If:  Bathroom light off
Turn off fan after 5 min delay (cancelable)
Else If Bathroom light on.
Cancel Delayed actions
Turn on bathroom fan
End-If
``````

What you don't need is an End-If and another If.

Thanks, now I understand this one. I am getting much closer to getting this as long as I keep the cancel after the delay.

OK, I see what you are saying. Adding the ELSEIF makes sense.