History-graph smoothing

I have a floor heating system, which among others is represented in HA as a climate entity for each room.
This displays very nicely in the history-graph.

Additionally to measuring the air temperature, each room sensor can measure the floor temperature by using an infrared sensor. This value is however quite noisy, and therefore messes up the graph when displaying climate control and floor sensor together.
Here’s an example of a floor sensor:

I have been trying to smooth this sensor.
First I tried to use the statistics platform. Unfortunately it was quite awful, and even had gaps in the resulting sensor.
Next I found the filter platform. At least there are no gaps in the data, and it helps a bit, but it still does not look good I think and the more you want to smooth the more it timeshifts the result.
Here the blue line is filtered, compared to original:
(time_simple_moving_average using a window of 30 minutes)

Question is, wouldn’t it be possible to have an option for the graph to do the smoothing at display time?
Of course not on by default, but some optional argument that could indicate a level of smoothness.
I realize the graph would not go through the exact measured values, but in a case like this the truth is probably the average of nearby measurements anyway.

Benefits of smoothing at display time:

  • You can see the result of your configuration right away. With filter and statistics you have to configure these derived sensors, then await new data is collected. Check the result, adjust and wait again…
  • The smoothing could be done better, because it can use “future” values in the calculation. For example it could calculate an average based on values some amount of time before and after the point it is calculating the average for.
    Filter and statistics must insert values into the DB as current values, meaning it cannot take future values into consideration, only historic. Resulting in some level of time shifting.

It takes some CPU resources of course. On the other hand you’ll save some writes to storage.

The custom:mini-graph-card can do smoothing at display time:
It does it ok I think, but I would still prefer the history graph. Especially because the intent is to have it in the same graph as the climate control.

There are different alternatives that have many options, such as

however this seems to stop being developed, and

With the plotly card, (if you understand the yaml format) you can apply filters, do extrapolations, combine multiple sensors make histograms, and fully customise everything. And if you can do a bit of javascript, you can do almost anything with it :slight_smile:

Also try the low pass (exponential) filter. It often works better in cases like this.

If your device has a state class of measurement you can use the statistics graph card instead of the graph card. It shows either the 5 min, 1 hr or 1 day mean.

e.g. standard graph vs 1hr mean, min & max statistics chart.