Reduce recorder days,, keep long term statistics

So I got standard 10days of recorder history, and quite a bit of long term history. Have used history-explorer-card to show longterm/short-term in same graph, same as now available in base-HA-history.
All of a sudden my DB start growing shitloads!, and I’d like to both reduce the troublesome sensors and in general the days of state-history

At the release-video for 2023-12 it seemed like it was possible to reduce recorder-days and the long-term statistics for those days was created ?

  • I’ve previously asked people to reduce recorder-days and configure their sensors for long term history, but they state it will loose history ? (one guy had even created a test install to verify it))

Anyone that can elaborate? - what happens to a sensor which is configured for long term statistics when I reduce from 10 to 7 days of recorder history?

  • the saying from the last discussion was that there would be a gap in long term history,
  • but from the release-video it seemed like it would be self-healing (the purge would create long term statistics if sensors was configured for it

Would really not like to get days of gaps in statitstics, so hoping someone have a qualified answer for me :wink:

LTS are never purged.

All that would happen is that you would lose 3 days of state and event data.

1 Like

strange it was so calmly suggested to reduce days in the release-video, when people have such long recordings it is for a special case, - and encouraging to reduce with data loss ?
I guess for me it is triviality, and I should reduce it, long term seems more than sufficient, just trying to understand and perhaps others should be warned somehow ??

Warned about what?

sorry, not native English-speaking so apologies for beeing unprecise
So the guy having 365 days recorder settings stated by changing to 10 days he did not get long therm statistics for the interval between 365 days and 10 days, but after a day the 10th day was made into the 11th day with long term statistics,

So just “worried” about what happens,

  • but I have just updated my config to reduce to 9 days for myself, guess it is dummy-testing :wink:

My guess is when it was such a consensus in the release - and you dont see it as an issue - he might have misconfigured his sensors to not create long term statistics?
(which make it odd he get the 11th day of long term stats?) - but in hindsight that is some time ago (springtime or something?? ) so I might have missed som new great functionality :wink:

found a new rabbithole :wink: looking at this option:

If I use it ad-hoc (setting keep-days to 2) to purge a really noisy zibee device which have managed to create 802465 rows for 12 entities, so more than 9mill rows (more than the rest of my devices!! )
, will the service create long-term statistics when purging, so for theese particular I will get long term statistics from day 3-10 while other entities have states in that period ?

LTS are only created every 5 minutes if the sensor has a state_class.

Also you can not set a purge interval per entity. It is one global setting.

1 Like

Long-term statistics are created every five minutes, right from the start, and summarised into hourly statistics on the hour. So if you have 10 days of recorder history, for those 10 days the data is stored in both the state history and the long-term statistics. The LTS are not created from data “rolling off” the state history, and have nothing to do with the purge process. There is no process that deletes LTS.

The only way you could have gaps in LTS would (probably) be non-numeric values or changing/deleting state_class such that they are not created.

Have a look under Dev Tools > Statistics to see if they are being created for your entity.

2 Likes

Super, finally I got it into my 5-year-old-brain :slight_smile:

So to summarize if I now got this in the right order:

  • a sensor/entity can be defined with state_class or otherwise rules that enables LTS (see more info in dev-doc on the subject)
  • when state_class or other rules for LTS is added to sensor/entity, on hourly basis the LTS is created - and it is never purged.
  • never mind that history/history-explorer-card select states first then the LTS, the LTS is always there “behind the scenes” :slight_smile:
  • The issue with “the other guy” must have been his configuration of the sensor (which he must not have done before actually purging states)
  • the recorder ‘purge_keep_days’ is limiting states from growing, and have nothing to do with LTS, as the sensor/entity definition trigger that - and from moment of configuration LTS is starting to build

Thanks to Michal for dumbing it down to my level :),
sorry Tom, I now see that you presented the right answer from the beguinning - I was just not knowledgable enough to get it :wink:
Really apriciate you trying twice !

Hi, I’m trying to achieve the following with the history-explorer-card for the same entity in the same graph:

  • For visualizing data during the last 10 days (recorder history period): show 5 minute long-term statistics (as that 5 minute LTS detail is available during recorder history period).
  • For visualizing data older than 10 days (before the recorder history period): show hourly long term statistics as these are available forever.

Did you configure that the same way? How did you do it?
Now when I use this statistics period: 5minute setting. It doesn’t show any data anymore for older than 10 days.

It’s been a while since setup, have you seen this?

Here are sample of card and sensor

The history explorer card is no longer maintained and should not be recommended as it could stop working at any time.

1 Like

Thanks for the heads up,
for sure bad advice to recommend archived custom solutions - :zipper_mouth_face:

Do you happen to know any good/equivalent alternative?
Know the normal history graph now can show lts, but not the graph and booleans in same timeline?

Running 2024.2.5 - not seeing any warning/repairs on using archived HACS component, is that as expected?

Apexcharts supports LTS and booleans.