Predict / forecast Values (linear / polynomial regression)

I am searching for a solution to predict values or a time when a specific Value is reached (e.g. falling temperature, When does the temperature falls below a specific limit). My research brought me to the “Trend” Integration, but this seems to be only linear and it is only possible to have a switch, if the gradient is rising or falling, but no predicion.

I found out that lovelace-plotly-graph-card uses some nice graphs and prediction by regression. Maybe this feature can also be implemented in the “Trend” integration or a new one. My idea would be a sensor or a device, which uses linear, polynomial (configurabel degree), … regression of some history sensor data to describe it as a function. With this function description it is possible to predict values.

My usecase: I have a wood fired heating system and it is important to know the buffer temperature and when i should fill the oven again. Especially i need to know if there is enough temperature in the buffer left the next morning or not.
With this feature i can predict the temperature at a specific time ( in case there is no dramatic change in the consumtion of energy) or i can predict the time when a specific temperature is reached ( with inverse function)

It seems possible with the numpy python module in only a few steps (Python Machine Learning Polynomial Regression)
I am quite new to python and Home assistant ( writing integration) so maybe it is easy for some experienced persons to integrate such a feature. Maybe there is a solution already existing, which i do not know.

Hey, I know this has been a while, but did you ever get something like this done? I’d like to do the same for a grill thermometer

I am in a similar position but with an oil tank. I have a ESP32 on ESPHome with a vl53l0x distance sensor, a filter to convert distance to top of oil to the number of litres remaining. Having a regression for where this is zero will give me a number of days until empty. The readings from the vl53l0x vary enough that I would need a regression over a week or so to get a line. The brute force would be a switch for when it gets below n litres, I can export the data and calculate it outside HA, but would be nice to have.

I’m looking for something like this for a variety of use cases as well.

For example, warnings when batteries will be drained based on how long until they’re actually drained. I don’t care if a battery is under 30% if it drains at a rate of 10% a year. I care that it’s going to be drained “soon”.

1 Like

Btw, I was able to find a way to do this well enough for my use case using the derivative helper. This gives me the rate of change for another sensor over a given time window and I can then use that to estimate when that underlying sensor will reach a certain value.

For example, I used it to give me a rough estimate as to when my phone battery will run out. The derivative sensor uses my phone’s battery sensor as the input sensor and looks at a time window of 1 hour. It also has a time unit of 1 hour so it will give me the rate of change per hour.

Then I use a template sensor to give me an estimate of when the battery will run out:

        {%  set seconds_to_0 = 
            (states("sensor.phone_battery_level")|float
            / states("sensor.phone_battery_level_derivative")|float|abs)
            * 60 * 60
        %}
        {{
          as_local(as_datetime(
            as_timestamp(now()) + seconds_to_0
          ))
        }

It’s taking the current battery value and the rate it’s changing, then estimating the actual date/time it’ll be at 0.

Been wishing for this too. For now the most robust solution is maybe to export data to a dedicated analysis platform like Grafana.