Turn on Space Heater if temp falls below threshold

Hi, I want to make sure that I’m building this rule correctly. This is what I’m trying to accomplish:

If any of three temperature sensors drop below 68° overnight, then turn on smart switch for 10 minutes and then turn off.

This is what I have built:
Required expression:
Time is between 7:30pm and 7:30am

Trigger:
Temp sensor 1, temp sensor 2, temp sensor 3, any reports < 68°

No Conditions needed

Actions:
On: Space Heater Switch
Delay 0:10:00
Off: Space Heater Switch

This seems to work well, but what I’m wondering is what would happen if the switch was triggered on, and during the 10 minute delay, the temperature reported less than 68° again. Would the switch be triggered on again for an additional 10 minutes even if it’s already on? Basically, would this make the total On time longer than 10 minutes?
Ideally I’d like for it to not evaluate the triggers again until the actions fully complete and then it can evaluate them again. Is there a way to get it to work this way? Thank you!

You can set a Private Boolean to prevent that.

Make it the Required Expression. Private Boolean = True

Then in actions make your first action set the Private Boolean to False (this will prevent it from triggering again until True) After that then you can use conditions to set the time and set Space Heater Switch On, Wait 10 Mins Space Heater Switch Off. Finally set the Private Boolean back to True so it can run again.

Here's a quick screenshot I threw together so you can see how it would look.

Jimmy

3 Likes

Disregard my inaccurate original post here (now minimized), I was coffee-starved when I made it.

Summary

You may have noticed Jimmy used the "Wait for event --> Elapsed Time: X" option instead of Delays in his excellent example up there...

Both options do the same basic thing, but IIRC, that main advantage of the Wait option (vs Delay) is that the Wait wouldn't be interrupted by another trigger event, whereas a Delay would get interrupted. So, it's additional insurance in this case.

I now use the Wait option (instead of Delay) pretty much exclusively in my rules as a general practice.

1 Like

I may be misunderstanding what you meant to say, but I think you have that backwards. 'Wait for' is canceled by a new trigger of the rule. 'Delay' keeps running when the rule is re-triggered.

I just tested this using a rule with a 'wait for elapsed time 10 seconds' that then logged a message. When I repeatedly triggered the rule (less than 10 seconds between triggers), the message was only logged 10 seconds after the last time I triggered it.

I then changed it to 'delay 10 seconds' and triggered the rule 4 times in less than 10 seconds. I got 4 messages logged as each 10 second delay completed.

TLDR for the rest of this post: If you want the space heater to turn on for 10 minutes after the first trigger and only turn back on for a new trigger after the 10 minutes has passed, use the Private Boolean to ensure it only runs once. If you want the space heater to stay on for 10 minutes past any subsequent triggers that happen during the first activation, use 'wait for elapsed time'.

Details, with the OP's original rule:

Scenario 1, rule is triggered at 00:00 and again 00:06 using 'delay' but not Private Boolean:

  • Rule is triggered at midnight, Space heater is turned on
  • At 00:06, rule is re-triggered. A second instance of the rule runs and the space heater is turned on (but it is already on)
  • At 00:10, the first delay is over, the space heater is turned off
  • At 00:16, the space heater is turned off again (but it is already off)

So far, no problem other than being a bit messy, but consider:

Scenario 2: Rule triggers at 00:00, 00:06 and 00:12 using 'delay' without Private Boolean:

  • Rule is triggered at midnight, Space heater is turned on
    -At 00:06, rule is re-triggered. A second instance of the rule runs and the space heater is turned on (but it is already on)
  • At 00:10, the first delay is over, the space heater is turned off
  • At 00:12, the rule triggers again. The space heater is turned on
  • At 00:16, the space heater is turned off again after only 4 minutes
  • At 00:22 the space heater turns off (but it is already off)

So the heater was on from 00:00 to 00:10 and 00:12 to 00:16.

Using the Private Boolean prevents this kind of back-and-forth between multiple instances of the rule turning the switch on and off. It will always run for 10 minutes after the first trigger, and each subsequent re-trigger will result in 10 minutes of heat. In scenario 1 with the Private Boolean the heater will be on from 00:00 to 00:10. In scenario 2 it will be on from 00:00 to 00:10 and 00:12 to 00:22.

However if you want it to keep the space heater on for 10 minutes after the most recent report of <68°, then you would want to use a 'wait for elapsed time' which is canceled by the next trigger.

Scenario 1 with 'wait for elapsed time':

  • Rule is triggered at midnight, Space heater is turned on
  • At 00:06, rule is re-triggered. A second instance of the rule runs and the space heater is turned on (but it is already on). The first 10 minute 'wait for' is canceled. A new one is started.
  • At 00:10, nothing happens
  • At 00:16, the space heater is turned off.

The space heater runs from 00:00 to 00:16

Or in scenario 2 with 'wait for elapsed time':

  • Rule is triggered at midnight, Space heater is turned on
  • At 00:06, rule is re-triggered. A second instance of the rule runs and the space heater is turned on (but it is already on). The first 10 minute 'wait for' is canceled. A new one is started.
  • At 00:10, nothing happens
  • At 00:12, the rule triggers again. The space heater is turned on (but it is already on). The second 'wait' is canceled. new one is started.
  • At 00:16, nothing happens
  • At 00:22 the space heater turns off

The space heater runs from 00:00 to 00:22

As with many things in Hubitat, there is more than one way to get the same result. You could get the same effect as 'wait for elapsed time' using cancelable delays.

There two action sets should be functionally the same:

Actions:
Cancel delayed actions
Turn on space heater
Turn off space heater (delayed 10 minutes, cancelable)

or:

Actions:
Turn on space heater
Wait for elapsed time: 10 minutes
Turn off space heater

1 Like

Ah fek, you're right -- as I was typing that this morning, I had a feeling that wasn't right. Clearly not enough coffee yet.

Thank you for correction - I'll amend my post to mitigate add'l confusion.

Thank you for the detailed response! This is a perfect explanation!

Thank you for the suggestion, I'll try it with a Boolean

1 Like

I forgot to mention that if you go with the Boolean you may want to add a Reset on Reboot. From what I've read before if the Boolean is set to FALSE and waiting to get set back to True, If there happens to be a reboot of the Hubitat in that small 10 minute window it will stay at FALSE. However if you create a Rule to reset it on Reboot that will correct that issue.

Here is a screenshot of how one of mine is setup.