Help: Turn on hall lights if entry door opens after garage door opens

Trying to do something fairly simple and my brain is stuck.
Here's what I am trying to automate.
Predicate: Between sunset and sunrise.
Trigger: When a garage door opens
Rule: Wait up to 3 mins for entry door (between garage and house) to open and, when it does, turn on entry hall light.

Struggling with how to structure the if/then and wait events in the rule to properly do this. Looking for recommendations.

There are probably better ways, but here's what comes to mind for me.

Create a virtual switch.
Create first rule with predicates and triggers as you noted. For actions, just turn on the virtual switch, then wait for 3 minutes, then turn the virtual switch off.
Create a second rule with the trigger being the entry door sensor being open. The action could be "IF virtual switch is ON, turn on light. " or the second rule could use the virtual switch being ON as a predicate.

Seems like there should be a way to do this in one rule, but it's not something I've really tried to do before.

EDIT: it's also likely that you could skip the virtual switch and instead use Rule 1 to set a Private Boolean in Rule 2 (or boolean type hub-variable). Also not something I'm super familiar with, but should work.

1 Like

Here's what I'd do. First create a local variable (or use a hub variable if you really want to) of type String. I'll call it deviceValue in my example, but you can call it anything.

Predicate Rule: Time between sunrise and sunset

Trigger event: Garage door opened

Actions to run:

Wait for event: entry door opens --> timeout 0:03:00
Set variable deviceValue to %device%
IF (deviceValue != "timeout") THEN
  On: Hall Light
END-IF

Instead of that variable and the condition--the second and third lines--you could also just do IF (Entry Door open), which should be the state at that point if the door was opened, but staff have recommended the approach above since it actually says what the Rule did (the built-in %device% variable gets set to timeout if a "Wait" timeout happens, so it's one way you can check why something happened; you just can't check it directly so need to store it in a "real" variable first).

Or you could just get a motion sensor at that door and make it easier. :smiley:

5 Likes

#ThisIsTheWay

The timeout feature is something I wasn't aware of. Much more practical than using two rules. But what "resets" the variable after a timeout has occurred?

The trigger event, which (the event device) is normally what %device% refers to.

1 Like

Another way to do what you want is to look at the status of the door after the wait is over.

Wait for event: entry door opens --> timeout 0:03:00
IF (entry door opened) On: Hall Light
2 Likes

Thanks for all the suggestions. I had difficulty following the specifics of bertabcd1234 and dylan.c with respect to using virtual switches and local variables so I tried pseudonym's approach and it seems to be working perfectly! Thanks again :slight_smile:

image

I did discuss the device attribute conditional too and the reasons you might want the other approach, but either should really work (and it's all you could do before this was introduced). :slight_smile:

The only thing you might want to do is make the delay cancelable and add a "Cancel Delayed Actions" somewhere before your "On," possibly right before (depending on what behavior you want). That way, re-opening the door will effectively reset that countdown.

1 Like

Thanks again and good idea I will add the Cancel Delayed Actions command (before On)!

Hi, what is the translation for the "end if" statement and how do I select that for a similar rule I am building?

I'm not sure what you mean with "translation," but the meaning of END-IF is just to close out the IF THEN, i.e., the block of conditional actions. For example, compare these two Rule actions:

Action 1
IF (Condition X) THEN
  Action 2
END-IF
Action 3

and

Action 1
IF (Condition X) THEN
  Action 2
  Action 3
END-IF

Action 1 will run in both Rules (because it's outside of any conditional), and in both Rules, Action 2 will also run if Condition X is true at the time of execution. However, Action 3 always run in the first Rule (because it's outside the conditional), whereas Action 3 will only run in the second Rule if the condition is true (because it's contained inside the block of conditional actions).

If it's the last "action" in a Rule, some people leave out the END-IF. Even though it's not technically valid, RM will figure it out--like forgetting to put a period at the end of a sentence. But it's sloppy, IMHO, and it definitely matters in the first Rule above (otherwise it will execute like the second Rule).

If you're in the middle of making a block of conditional actions, you should see convenient buttons for adding an ELSE or END-IF to your Rule actions. But you can always just choose them from the menus, too: the "Conditional Actions" menu (under "Select action type to add") has those plus more, and it's also how you have to start making a conditional action in the first place.

Thank you for your response. You explained what I meant to ask. Iā€™m still a little lost on how to get the end if. Where the red arrow is pointing, is that the right path? The rule is working but I want to learn how to make clean rules as you mentioned.

Thank you

No, it looks like you're still in the process of creating your "IF (rule) THEN" expression. You need to complete that, perhaps by choosing "New Condition" and then your door status or whatever you're really looking to test. In other words, you haven't even added your IF THEN yet, so you're not quite at the spot where it would even make sense to add an END-IF ... yet.

Okay, so here is where I am at. Iā€™m ready to add End-If. How do I go about doing that? Do I click add another action>conditional actions>?
(Sorry I am not finding it as easy as Iā€™m sure it is.)

As bertabcd1234 explained, you must create an If-Then conditional rule before you can subsequently select an else-if or end-if statement. The rules you've shared here don't yet have a n If-Then conditional rule in them.

To do this, you FIRST need to select a new condition under the "select action type to add" menu that you've shown with the red arrow in your most recent post. Then, as you shared in your prior post, choose the "IF rule THEN" option and define the rule element in the next menu with "-> New Condition"

After you've created this if then condition in your rule, you can subsequently select else-if and end-if statements.

Gotcha! So I should have started the rule with: If the mailbox opens, then turn on the lights, etc, etc, etc, end-if"

Thank you for your patience.