Filter quantity of states (for a specific sensor) that get saved to the history

Hello! I have a couple sensors that push updates every second. I like having the immediate value on my dashboard, and for that specific use case, the performance is good.

The problem arises when I tried to make complex graphs for those sensors. I use apexcharts-card, and my issue is that the graphs take a long time to load (or never load at all) when I set a graph span longer than three or four days. It makes sense, since the frontend needs to pull and compute a big history. I’ve already talked with the codeowner of this card, and they said that there isn’t much they can do; so I need to solve or work-around the problem on the history side of things.

So my question is: is there any way to filter the quantity of states that get saved to the history, maybe through configuration of the recorder integration, while still keeping the latest value as the entity state? Something like “save the current state every 10 seconds”, or “save one out of 10 states”, rather than “save every state”.

One of my sensors is a template sensor and the other uses the core MQTT integration. So far, I’ve used template sensor triggers to decrease the update frequency of the template sensor to 10 seconds, and the performance does improve - I know I could “wrap” my MQTT sensor in a template sensor to apply that workaround, but first I’d like to see if there’s an alternative solution available.

Thanks in advance!

HA is not super flexible regarding history.

I’d suggest to use influxdb for this sensor, and use Using HA or HACS graphs w/ InfluxDB data in HA? - #6 by koying to graph it.

1 Like

This is an issue Home Assistant developers are aware of and the groundwork for improvements are being made: New sensor properties for long-term statistics | Home Assistant Developer Docs

1 Like

Thanks for the info., that’s a step in the right direction.

That being said, I’m personally not convinced HA will get to the level of performance and flexibility of a true Time-series db, nor should it aim to, really.

This is still Python, after all :slight_smile:

1 Like

That’s great! Thank you, I’ll stay tuned for future updates.

I’ll look into that! Thank you.