Automation trigger when below temp

TLDR: I want to keep my garage at around 40°f in the winter. Since automation triggers only fire when the “threshold” is crossed (aka 40° changes to 39°), the trigger would sometimes be missed since it also had a condition to NOT run during Energy Peak Pricing times. When the trigger was missed, I would have to manually turn on the heater, otherwise the “Turn On Heater” automation would never fire again. I solved this problem by changing the trigger to every 15 minutes and I moved the “logic” to the condition section of the automation. The conditions now are: Garage below 40 and heater is off and time is after 7pm and before 3pm. The “Turn Off Heater” automation follows similar logic now too.

I was just wondering if there was a better way to achieve this. Concerned I may have overcomplicated it. Based on other topics I have read, there doesn’t appear to be a better way? Note: I realize I could get similar results using a timer plug and a thermostat plug, but that’s no fun :sweat_smile:

Long Version:
I have a detached garage and keep my tools and such in it, including my battery operated tools. We get some pretty cold winters, so to keep my batteries from degrading too badly, and to protect the rest of my tools from condensation and such, I want to keep my garage around 40°f.

Initially I setup an automation to turn on an electric heater (Oil filled, very safe) and a fan when the garage dropped below 40 and another to turn off the heater and fan when it got above 43. This worked fine until I decided I did not want to run the heater during my electrical providers “peak pricing” time (3pm-7pm). I modified the On automation so it would not trigger from 3pm-7pm. I then added a new trigger to my Off automation so it would trigger at 3pm daily in addition to when the garage was above 43.

The problem I started running into now was that if the garage dropped below 40 between 3 and 7, the On automation would “miss” its trigger since automation triggers like that only fire when the threshold is crossed, aka when temp goes from 40 to 39. This meant that until I manually turned on the heater and fan, the automation loop was broken.

I have since solved this issue by using a Time trigger instead of a Temperature trigger. Both the On and Off automations now trigger every 15 minutes. All the “logic” is in the Condition section now. The On automation has the following conditions: Garage is below 40 AND (the Heater OR Fan is off) AND The time is after 7pm and before 3pm. The Off automation follows a similar logic.

I am just wondering if I overcomplicated this. Is there a better way to achieve this?

At some point during this process it did occur to me I could have gone “low tech” and got a timer plug and a thermostat plug. Have the timer plugged into the wall, and the thermostat plugged into the timer, and run everything off that lol. That seemed less fun to me than getting Home Assistant to work though, and since i already had everything else, the Home Assistant solution was free :laughing:

Hi, sorry, I only looked at TLDR, and browsed for your time slots :wink:

I would create a template binary sensor for Cheap Energy, maybe it can be used elsewhere as well.

Then:
trigger1: below 40
trigger2: trigger cheap energy from off to on
condition1: below 40
condition2: cheap energy
action: heat it up

1 Like

Use the Generic Thermostat integration with a Schedule and an automation to control one by the other. It’s the most commonly recommended solution for your type of application. Plus you get a climate entity that can be displayed in the UI.

If you don’t need to control by time but by energy price, create the suggested Template Sensor and use that to control the climate entity’s operation (the Generic Thermostat integration produces a climate entity).

1 Like

No worries lol. I wrote the TLDR for a reason :grin:

That’s an interesting idea… I have created a couple of custom sensors for other things, mostly doing math like house energy consumption - solar generation, but it never occurred to me to create a custom sensor for the purpose of triggering an automation. In hindsight, its a kind of obvious idea lol.

Let me think that over. If nothing else I am sure I will use this in the future :grin:

I would also suggest the generic thermostat since it removes a few cases where an automation would fail.
There is no need really for a binary sensor since that is just a template trigger in the automation that controls the garage thermostat

1 Like

Thanks for bringing this to my attention! I had always assumed that this was intended to be used with smart thermostats that did not integrate well with HA. Did not realize you could “cobble together” a thermostat from various sensors and entities.

I will definitely check this out.

1 Like

I implemented this solution and believe it will work. I wont know for sure until Monday since peak pricing does not occur on weekends. I cannot see any reason this will not work come Monday though :grin:

Edit: Confirmed that this solution is working as intended. I created an automation that triggers based on the state change of the Schedule I created. When the schedule says its peak time, the automation triggers and turns off the garage thermostat. Then there is another automation that triggers when the schedule changes to not peak time and turns the garage thermostat back on.

1 Like

You can make a template trigger that will trigger only when the temp is below 40 degrees AND power is off peak (and add a “for X seconds” clause to debounce fluctuations, set to the reaction time of your thermometer).

Doing it any other way usually risks falling in the same trap that you are falling right now: Your trigger fires but the other condition is not met and therefore you have to fire the automation every 15 minutes or so, which doesn’t activate the device you want to activate immediately when both conditions have been met, AND has the second disadvantage that the logbook will NOT show that the automation was activated because a specific condition was met.

1 Like