Feedback requested for my first (simple) rule for a garage heater

I've had a C-8 for about a week. The main reason I bought it was to turn off/on a new garage heater when garage doors are open/closed but I'm also moving existing WiFi devices from Alexa. It's been fun setting everything up and I'm finally to the point that I want to create a rule for the heater. This is what I came up with. If someone with more experience than me could give me some feedback, I'd appreciate it. Is it "safe" to activate the heater actions?

Trigger:
     Any contact open

Actions:
     Turn off heater
     Wait for both contacts closed
     Turn on heater

The syntax will be different in the RM UI, but this is what I would do. Simple and clean. Your rule also has the problem with the private boolean. The only way it would ever execute is if you manually (or through another automation) toggle the private boolean.

But I have two garage doors. My thought was wait for a close event and if there not both close wait for another close event.

I don't think I can wait for a close event if both doors happen to be open at the same time.

Thanks for the help!

I see the Required Expression now. How does that differ from the IF?

Oh I see what you were saying. Is this going to poll the devices based on the while parameters? Isn't it more efficient to wait on the close events and then check the conditions?

That clarifies it. I'll change it. That's exactly the kind of thing I was looking for. Thanks.

Clarifying this point, no. It evaluates the expression at the time the action is reached. If true, it continues. If false, it (temporarily) subscribes to whatever events could change the evaluation, re-evaluates them when one fires, and does one of these two things again as needed. There is no "polling," either of the reported device state (all any app like Rule Machine knows about) or the actual device itself (very rare and rarely necessary, some classic Z-Wave devices aside).

...in case this knowledge helps ease concerns you may have in the future.

(In general, Hubitat is normally described as an event-driven system, the above being one illustration of this point.)

1 Like

To beat a dead horse, here's a solution to do everything you want without worrying about a private boolean

Trigger:
	Double,Single any contact open ###Either contact opening will trigger the rule

Required Expression:
	Heater is on ###Make sure the heater is on to even warrant running the rule

Actions:
	Turn off heater ###Self explanatory; this will prevent the rule from running a second time
	Log: "Turning off garage heater" ###Self explanatory
	Wait for expression (double AND single closed) ###Wait for both contact sensors to be closed
	Log: "Turning on garage heater"###Self explanatory
	Turn on heater###Self explanatory

To answer this:

This depends on ordering of the rule actions. A required expression be evaluated every time an event the expression is based on occurs (@bertabcd1234 can correct me if I'm wrong here). So if your required expression is based on a contact sensor, then it will be evaluated every time the contact sensor state changes (open/close). Pretty simple there but is highlighted more if it's based on say a temp sensor where you're looking for a specific temperature (e.g., temp = 45). While evaluated as false, the rule actions are prevented from running completely.

So, if your actions are:

IF(Contact = Open)
	A bunch of stuff
END-IF

Then it's the equivalent of having a required expression of Contact = Open.

But, say your rule is

Log something
Turn off a switch
IF(Contact = Open)
	Stuff
END-IF

Then you'd still want the log to happen and switch to turn off when the rule is triggered, so making it a required expression wouldn't make sense.

2 Likes

That makes sense, it eliminates the need to use the Private Boolean.

I think this makes sense and is logically simpler. I didn't see the Wait action before reading your example. I'll give it a whirl.

Thanks for taking the time to explain!

2 Likes

You can use Wait for Event if both door are open.
Wait for event: Double, Single all contacts closed
The Wait will only be satisfied when both contacts are closed.

My preference is to use Wait for Events when both the Trigger and Wait are the same device(s). If not, I'll use Wait for Expression.

No it's not. The END REP separates the intended repeated events from everything that happens afterwards. Without the END REP, it will repeat the Log action everything else every 10 seconds, including the set private boolean true

I don't know why I'm having trouble distinguishing between Events and States/Conditions...

If the doors are in these states:
Double is open
Single is closed

And this occurs:
Double closes

Would 'Wait for event: Double, Single all contacts closed' be satisfied since there wasn't an event for Single close? Or, is the 'Wait for event' any event that causes 'Double, Single all contacts closed' to be evaluated/satisfied?

I think they were saying it would work but there's a better way to get the same behavior with a Wait so the WHILE 'loop' isn't necessary.

A simple example would be a door. A door has two states, it's either closed or opened. An event would be when you open the door and change the state from closed to opened. An event is instantaneous while a state can remain indefinitely.

In your example, when the Double closes (Single door already closed) the 'Wait for event: Double, Single all contacts closed" will be satisfied because the Wait will see that both the Double and Single contacts are now closed.

2 Likes

Events represent state transitions, or state changes. Conditions are boolean expressions evaluated on states.

Correct, but there's a subtlety here that is worth noting and relates to the previous comment. There needs to be an event from one of the contact sensors for the Wait to evaluate that both contacts are closed. Closing one of the contacts triggers an event. However if both of the contacts were closed when rule comes upon the Wait, nothing will happen until one of them is opened and then closed again.

If what you wanted was immediate evaluation of the state of the contacts, you would use Wait for Expression. That would only wait if the expression is false when the action is come upon.

Right, but there is only one Event, for Double. My question was meant to be -The 'Wait for event' doesn't need both Events to be sent to be satisfied?

The way I read the rule, it seemed like it's waiting for both Events to be sent.

This is what I was looking for...

In this case, the rule will wake when either event happens and then evaluate the state of both devices (it being somewhat like "Wait for expression" in this case, aside from the fact that the truth value at the moment the action is reached doesn't matter--as mentioned above, it needs some event to continue).

Events are generated one at a time on the hub; "both" won't/can't truly happen at the same time (not that it matters for this answer, but it's something that some people ask about and is related to the issue at hand).

3 Likes

It's not waiting for both. I suggest you make two virtual contact sensor and a test rule and see for yourself how the various Waits respond.

Sorry, I wasn't challenging you info. I was just trying to figure it out. I plan on experimenting when I get some time in the next week or so.

Thanks again for the help everyone!

3 Likes

True, if there were some sort of delay getting to the Wait. In the OP example there isn't.