Graph of temperatures inside and outside

A fancy Home Assistant automation that checks the weather and figures out when to turn on your heater

So in the continuing saga with my mom’s home-automated furnace, it got extra cold recently and I noticed it wasn’t getting up to temperature in time for her to wake up. I figured I could come up with a formula to compute the time needed to come to temperature and turn on the furnace at a dynamic time in the morning so it’d be just right.

Graph of temperatures inside and outside
Temperatures at my mom’s house over a few days

The Home Assistant GUI only shows the past 24 hours, but the Recorder component saves data for as long as you want. I have mine cutting it off after a week. you can query the data to get nice csv files for processing with sqlite commands like this:

The simplest solution here is to just do a first-order approximation and say that heatup duration is probably proportional to the temperature delta between inside and outside at the moment you need to make a decision. This is rough because you don’t know what the outside temperature will do during the heat-up period, but it should be good enough for most purposes.

The Python package, pandas makes it really easy to process these data. The code below processed the raw data and computed the least-squares fit of the relationship between the temperature delta and the heatup duration:

The results are in! It’s fairly noisy, but should get the job done.

Heatup duration plotted
Heatup duration vs. temperature delta

So now we have to get Home Assistant to turn on the heat that many minutes before the target “wake up time”. Templates triggers to the rescue. The template trigger for a 7:45am wakeup looks like this:

Whenever the indoor or outdoor temperature sensors change, this checks to see if the number of minutes between now and 7:45am is less than the required duration for full heatup and triggers if so. You’ll want to turn off the automation as part of its own action and turn it back on when the system shuts down for the night (in another automation).

If you want to try to get extra fancy you can do some thermodynamics calculations and use Newton’s law of cooling to try to figure out a more robust model. I fiddled with it a bit but didn’t get anything super interesting. Here is a plot of some intermediate cooling analysis. The coefficients on the top left are supposed to have a constant slope (they’re the relation between temperature gradient and heat flux dQ/dt. Most of them are approximately constant but it’s quite noisy. The linear model above suffices.

Noisy graphs
Analysis of some cooling periods with numerical differentiation.

One thought on “A fancy Home Assistant automation that checks the weather and figures out when to turn on your heater”

  1. This is amazing !

    Maybe this could be an addition to the generic_thermostat component, so that it could be able to use an external temperature sensor and improve its algorithm over time.

    I have a netatmo thermostat (which does check the weather) but the more I use HASS, the more I think I should have just use a remote switch and built it myself

Leave a Reply

Your email address will not be published. Required fields are marked *