2 Wait Events - Elapsed Time and Contact Sensor

I have a virtual switch that is turned on when my back doorbell button is pressed. Then I have a rule that is triggered by that virtual switch being turned on to turn my carport light on. In this rule I want one of two events to turn the light off. Currently I have it to wait for an elapsed time of 5 minutes and turn the carport light off. I would also like for there to be an "OR" event of a contact sensor closing (door closed) after a door has been opened to turned the light off. Concept is if doorbell is pushed the carport light comes on. If the back door is opened and then closed the light goes off, but if no one is home to open and close the door then after 5 minutes the light goes off. I have tried to figure out how to put both these conditions in but I can't figure it out. I am open to any help and suggestions.

Below is a screenshot of my current rule with only the wait event of elapsed time.

The rule you posted and your description of what you're trying to do are pretty far apart, so I'm going with what you said you want to do.

If this is only supposed to run at night, remove the if/then/else and put the time conditions in as a required expression.

That leaves the actions for this rule as:

On Carport light
Wait for event: Back Door closes, timeout 5 minutes
Off Carport light
Off Back Door bell switch

The rule will wait for the door to close, but if that doesn't happen after 5 minutes, the wait times out and the other actions run.

Then I didn't do a good job explaining because this rule does exactly what I want when I want for both the light and turning off the virtual switch that is activated regardless the time of day when it is pushed (the door bell doesn't give me sunset to sunrise only times and I want that to change naturally not be a fixed time). So I use the if statements inside the rule to clarify what to do inside the day because the rule needs to run every time the doorbell is pushed.

The only thing different is I want to add the door opening and closing as a trigger to turn off as well but I can't figure out how to do that. Rule Machine won't seem to let me do a time period or a contact sensor. I can do either or do two physical items such as sensor and switch but not time and sensor.

I see that the rule I outlined would leave the virtual switch on during the day. Why don't you just set the virtual switch to auto-off after 10 seconds and remove the off command for the virtual switch from the rule?

I think when you say 'trigger to turn off' you mean the wait for event action? What I described is exactly how you do either a device or an elapsed time. Use the timeout option in the wait action.
The rule will continue after either the door closes, or 5 minutes passes without the door closing.

I didn't know you could do an auto off on the switch. I will have to look into that or if you can give a quick explanation.

When I get home tonight I will try setting it up. My problem was when I put the door in the rule I couldn't find an option for time. It was like that option disappeared. I must be overlooking it

In the device preferences:

image

The drop-down lets you set it for up to 10 seconds.

Your actions should look something like this, but in my example I'm using a 30 second timeout for testing:

This shows the logs where I opened the door before the timeout. You can see it logs the wait is over when the door closes:

This is what it looks like if the timeout occurs. You can see it logs the wait is over ~30 seconds after it starts:

Thank you so much. I will update tonight and feedback the results.

Also, thanks for teaching me about the auto off on the virtual switch. Learn more every day.

Sorry one other thing. Where do I find the "time out" action? That is what I can't find.

The timeout is an option when creating the 'wait for event' action:

Select "hrs;min:sec" from the drop-down, then you can enter the time:

Thank you very much. I had noticed that but did not understand what it was for. I truly appreciate the help.

The other thing to know based on the picture that @Alan_F provided, is that you could add another Wait Event and it gets treated as an "OR". With your elapsed time wait, you could also add a Wait for Event of the contact being closed. This would give you two different Waits without the timeout. Here is an example of overnight lighting in my house:


You'll see that there are two different Wait for Events that would allow the rule to progress with both being covered via a timeout.

The example provided of the contact closing with a timeout is probably a little bit cleaner, but it is possible to do what you wanted in the initial post.

Something like this is what originally had in mind with "wait for 5 minutes and no other actions light turns off" or "the contact sensor closes the light turns off even if that is before the 5 minutes is up".

Problem I was running into is I can't figure out a way to use the wait time or the contact sensor. I can do the "or" for two different physical wait events but I can't mix a "time" wait and a "physical" event wait if that makes sense.

The timeout may have to be the route to go. If you know how to get a wait for a physical event to happen or wait for a time event to be on the same wait event line in a rule please let me know.

Timeout and elapsed time are the same thing. If you click into your current Wait for Event, it will look like this:

When editing an elapsed time event, it's coded as timeout. Basically, just put in the contact sensor as closing with a timeout and it means the exact same thing as what you want.

Thank you. I will update tonight.