Combine 2 SIMPLE rules into one?

Just starting to venture into the RM...

I have a light I want to turn on/off based on a door sensor being open/closed. So, How do I make it one rule?

I currently have this setup...
Rule 1 - If the door opens, set dimmer to 100

Rule 2 - If the door closes, set dimmer to 0

How do I combine these?

I set it up as one rule using simple lighting app, but the delay was terrible.

(I've been reading a bunch of posts... how the hell do I make the if..then statements?)

One way:

TRIGGER
Storage Door Sensor changed

ACTIONS
IF Storage Door Sensor closed THEN
Dim: Storage Closet Light: 0
ELSE
Dim: Storage Closet Light: 100
ENDIF

Apologies up front... I'm coming over from wink, so bear with me please!

How do you get to the if... then statements?

To add an IF...THEN, under "Select Action Type to add", choose "Conditional Actions"; then, under "Select Which Action", choose "IF (conditions) THEN".

This may not suit your needs but I have this rule that turns the light off after 20 minutes should we forget to close the door properly.
Just for information really.

image

thanks @jwjr and @bobbles.

I finally got it. I think I was confused by the number of clicks needed.

1 Like

Perfect, except you could replace the ELSE-IF with a simple ELSE - once you get to that point in the Rule, the "closed" is a given.

Also, it'll help if you get in the habit of putting an END-IF at the end to close your IF statement. (It's on the Conditionals menu.) Your Rule will work fine without it, but more the complex rules you'll get around to eventually (especially nested IFs) need the END-IF to avoid confusion.

3 Likes

@jwjr . Like this? Also, what's the significance of closing the if statement?

1 Like

And it's good practice.
You may wish to follow your IF THEN with another IF THEN.
In this case you definitely need to finish the first IF THEN with an END IF.

2 Likes

Say you wanted to run another action after the if, it will behave very differently with and without the end if. Take a look at this:

IF (Storage Door Sensor open) THEN
   Dim: Storage Closet Light: 100
ELSE
   Dim: Storage Closet Light: 0
END-IF
Dim: Hall Light: 50

Compaired to:

IF (Storage Door Sensor open) THEN
   Dim: Storage Closet Light: 100
ELSE
   Dim: Storage Closet Light: 0
   Dim: Hall Light: 50

The first one will always dim the hall light when the door sensor changes state. The second one will only dim the hall light when the door sensor is closed.

This may not be a great example - not sure why you would set the hall light the same in both cases but it is just an example of the logic. :wink:

Your rule just falls out the bottom and ends. RM is forgiving enough that it doesn't need the implicit end-if. It doesn't hurt to get in the habit of adding the end-if so that you are used to it if you start building more complex rules.