How to cancel out of If (thermostat control based on windows)

I am trying to create a rule where if a few contact sensors are open for 5 mins, I can turn off my Thermostat. But, if the contacts are all closed, then the thermostat is back on.

The problem I am facing is, that if I open my window for less than 5 mins, and close it, then the rules naturally goes into the "ELSE" part, and there as the window is now closed, it executes setting the thermostat, and sends an annoying notification that the thermostat has been restored. What is an efficient way for me to skip the else condition completely, if the If condition duration was not satisfied? The other way to think about this requirement is that the
ELSE logic should be triggered, only if the IF logic was earlier trigerred.
I am almost sure that I am thinking this problem incorrectly.

Edit: This won't work! Oops :upside_down_face: I'll think again! :slight_smile:

Second attempt: :slight_smile:

The issue is the notification, so let's remove the notification from the If and Else statement as a first step. The logic works okay, so we now need to determine when you want a notification - which is when the thermostat changes between Mode: Eco and Mode: Heat

I don't have a thermostat to test this on but can you create another Conditional Statement that is triggered when the Thermostat Mode is changed and then have a conditional action to notify your phones what the new mode is?
:slight_smile:

If the change is detected when Mode is 'changed' to the same mode. You may need to create two rules with Predicate Conditions - One with Mode is Eco and then check if the mode is now Heat and another the other way around.

IF you look at %device% after a wait it will be "timeout" if the wait timed out, otherwise it will still be equal to the device that triggered the rule initially.

Also the first line of your IF doesn't have any wait conditions, does that work like a wait for event elapsed time? Seems like you want your wait conditions in there.

After further consideration perhaps a private Boolean would be the way to go. Set it to true in the if condition waiting for a close. With a delay to set it back false after 5 mins. Then your else can be an ELSE IF the private Boolean is False.

1 Like

Thanks....how does this look? Do you think the conditions seems correct and efficient? What am I missing? Any edge conditions where this might not work?

Your issue is if you open a window for less than 5 minutes you don't want anything to change, if I understood your first post.

The rule is triggered every time a window is opened or closed. This will cancel your wait and start the rule over.

So you need to set the private Boolean True, as soon as a window is open. Then set it back false after the 5 min wait is over since the window was never closed. So set it true before the wait and false after the wait inside the IF.

If you close the window before the 5 min is up it will then bypass the ELSE_IF, but you should then set the private Boolean back to False, so you need a final ELSE that only sets the Private Boolean back False. Your ELSE-IF needs to only run if the Boolean is False not True. Of coarse you can reverse when you set it True and False and then it would need to be True.

There are other ways you could do this but I was trying to keep it within the scope of what your already had.

This was my original thought but as your trigger is 'changed' then the rule will be run when your contact is closed after < 5min. Hence my suggestion to treat the issue of notification separate to the rest of the logic, or have you discounted my post?

Thank you @terminal3 and @UKmedia

@UKMedia , I wanted the notification when the smarts in my automation setup change the thermostat state. I think by your suggested logic, I will receive the notification, even if the thermostat is manually changed to eco/heat mode, or even by its inbuilt scheduler. Hence, my thought has been to embed the notification right where the actual logic triggers a tstat state change, as a confirmation of what great feat was accomplished my the home automation routine :slight_smile:

@terminal3 , I see your point. Let me try to readjust the logic and will share it back for review. You said there are other ways to get this done. Do you have any simpler/more efficient ways in mind to accomplish this?

Okay understood.. The complexity is caused by the triggering of the rule whenever any of the contacts change state. I'm not sure a private Boolean will work either with your current trigger. :frowning:

How about something like this?

Trigger:
contact-1, contact-2 any changed

Actions:
IF contact-1, contact-2 any open THEN
  Wait for Event —> Elapsed time: 0:05:00
  IF contact-1 contact-2 any open THEN
    Set Private Boolean True
    Thermostats: Thermostat —> Mode: Eco
    Notify phone: ‘turning off thermostat while window is open’
  End-If
ELSE
  IF Private Boolean is True THEN
    Thermostats: Thermostat —> Mode: Heat
    Notify phone: ‘Turning thermostat back on’
    Set Private Boolean False
  END-IF
END-IF

Thank you all the replies so far, which has helped me to continuously tweak my rule. Here is my latest version. It seems to be actually working fine since last 2 days. I will keep on monitoring it.
Sharing here, to seek any further review comments, and to hopefully help others who are looking for a similar(but common) need to turn on or off the thermostat, based on an open/closed set of contact sensors.

Features/considerations:

  • Turn off thermostat if ANY of the specified window is open
  • Turn on thermostat if ALL windows are closed
  • Turn off thermostat, only if any windows have been open for at least 5 minutes.
  • Turn on Thermostat only if all windows have been closed for at least 1 minute
  • If a window was opened, but closed back within 5 minutes, do not do any thermostat mode changes
  • If multiple windows are open, and you just closed few of them(but not all), then do not again change thermostat mode to OFF, as the thermostat must be already OFF mode.
  • If all windows were closed, and you opened a window for a short moment and closed it again, then do not set Thermostat mode to ON again, as the mode must already be in ON
  • Send notification to the App, when thermostat is turned on, or off

Download the Hubitat app