Still stuck on my HVAC Rule

I have a rule where if you open a window or door, I want the HVAC to turn off, but I want to record the previous setting and when everything closes it should turn back on. This generally works for me, however, sometimes I feel like if open and close a bunch of things during my 5 minute delay, I end up where even though everything is closed, my HVAC remains off. Am I properly using the delay(cancel) and Cancel Delayed events here? When a delayed event is cancelled, does it just skip that line and move on to the next? Meaning, looking at this rule, if I open something, close it within 30 seconds, then the cancel delayed actions happens, does it just cancel my delay and move on to still set the mode to off? I can't figure out why my HVAC stays off sometimes even though everything is closed!

Cancel delayed actions should be the first line, not the last line of each of these sections...I think. If true, cancel any delay in the false section. If false, cancel any delay in the true section.

Hmm any reason why the cancel has to be first? The examples @bravenel wrote on [Released] Rule 4.0 don't seem to be that way? It's what I based my rule on...

You have 5 minute delays as you first action in each section, so the cancel actions will really never do anything.

In Bruceā€™s examples, he does not have a delay action like you do.

Also, I'm not really sure this has to be as complicated as you make it out to be. What you want to do is trigger off the first window opening, right? Well, set a variable equal to the current state of the HVAC when the first window opens and then set it to NULL again when everything is closed. You can check that the variable is currently equal to NULL (or whatever you want) when first setting it. That way it won't get overwritten when you open the second window.

Something like this:

Trigger :  Any contact sensor changing

If ANY contact open AND variable = NULL   Then
         If HVAC if in heat mode 
                set Variable = HEAT
         Else if HVAC is in cool mode then
                set variable = COOL
         Else if HVAC is OFF then
                set variable to OFF
         end-if
Else if ALL contacts are closed then
        If variable = Heat
               set HVAC to heat
        Else if variable = COOL
                set HVAC to cool
        end if
        set variable = NULL
end-if

Do you have a heat pump? You have Emergency Heat mode. Just wondered if that was necessary cause I know my HVAC doesn't use it.

This looks promising, but the part I'm getting stuck on is the delay. I don't want it off the second something opens, people open a door or window all the time. I want to make sure they're open for 5 minutes before it fires. But of course if it closes in less then 5 minutes I don't want to actually do anything. As far as the emergency heat, yes I have a heat pump and in the northeast where it gets under 0 degrees sometimes so the emergency heat does get used.

Okay...this rule doesn't actually turn the HVAC off, it only turns it back on if it is off. But you can do something like this: (and on a side note, I wouldn't do this with doors. Doors being left open is a different issue. I would only do this with windows.)

Trigger :  Any contact sensor changing

If ANY contact open AND variable = NULL   Then
         Cancel Delayed actions
         If HVAC if in heat mode 
                set Variable = HEAT
         Else if HVAC is in cool mode then
                set variable = COOL
         Else if HVAC is OFF then
                set variable to OFF
         end-if
         Delay actions by 5 mins subject to cancel
         Turn HVAC to Off
Else if ALL contacts are closed then
        Cancel Delayed actions
        Delay Actions by 5 minutes
        If variable = Heat
               set HVAC to heat
        Else if variable = COOL
                set HVAC to cool
        end if
        set variable = NULL
end-if

This will delay either turning back on or turning off the HVAC by 5 minutes from a contact sensor opening or closing.

I use auto mode exclusively, but here's how I do this.

I wait for a door to be open for 2 minutes before turning the AC off, and I wait for them all to be closed 5 minutes before turning them on. This is to prevent an accidental compressor issue where it cycles in too short of a time frame. It also accounts for running outside for a sec and leaving a door open.

I could probably shorten up the 5 minutes, but it works for me.

This may not work....because you are using a delayed action which gets scheduled at the beginning before any other actions it is possible that the Cancel Delayed Actions will also cancel the one you just scheduled. So, I would advice adding an action of "Delay" in after the cancel delayed actions and then removing the delay from your set thermostat action.

Iā€™m not sure, itā€™s been working great.

Then you've been lucky. Someone else doing the exact same thing has been seeing his delayed actions not happening. If your hub isn't busy you might be getting by but the order of execution is to schedule any delayed actions first then run other actions. So, it's possible for your delayed action to get canceled immediately.