The problem
I have my recorder keep data for 400 days, created filters to only keep the entities of interest.
But ouf of those entities, for some I only need more recent data, like the past week, or past month.
In order to accomplish this, I've created a script that is ran weekly and it purges recorder data as per my needs.
This way I have a 8 months of data in a 1.6GB states table.
What I see recently is that the statistics_short_term is getting bigger than expected, it's reached now 1.2GB.
Checking some data there I see I have old data (half a year, for example, or more) for entities which I'm constantly purging. The states table only has 7 days of data for the same entity.
What version of Home Assistant Core has the issue?
core-2023.7.1
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
recorder
Link to integration documentation on our website
https://www.home-assistant.io/integrations/recorder/
Diagnostics information
I've picked a test entity to exemplify: sensor.average_illustairs_lux
Ran the below service and I've deleted everything except the past 1 day.
Then checked the states table:
SELECT COUNT(s.state_id), FROM_UNIXTIME(MIN(s.last_updated_ts)) FROM states s JOIN states_meta sm ON sm.metadata_id = s.metadata_id WHERE sm.entity_id = 'sensor.average_illustairs_lux'
The result is as expected:

Then checked statistics_short_term:
SELECT COUNT(sst.id), FROM_UNIXTIME(MIN(sst.created_ts)) FROM statistics_short_term sst JOIN statistics_meta sm ON sm.id = sst.metadata_id WHERE sm.statistic_id = 'sensor.average_illustairs_lux'
Here I have much older data:

Example YAML snippet
service: recorder.purge_entities
data:
keep_days: 1
target:
entity_id:
- sensor.average_illustairs_lux
Anything in the logs that might be useful for us?
No response
Additional information
No response
The problem
I have my recorder keep data for 400 days, created filters to only keep the entities of interest.
But ouf of those entities, for some I only need more recent data, like the past week, or past month.
In order to accomplish this, I've created a script that is ran weekly and it purges recorder data as per my needs.
This way I have a 8 months of data in a 1.6GB
statestable.What I see recently is that the
statistics_short_termis getting bigger than expected, it's reached now 1.2GB.Checking some data there I see I have old data (half a year, for example, or more) for entities which I'm constantly purging. The
statestable only has 7 days of data for the same entity.What version of Home Assistant Core has the issue?
core-2023.7.1
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
recorder
Link to integration documentation on our website
https://www.home-assistant.io/integrations/recorder/
Diagnostics information
I've picked a test entity to exemplify:
sensor.average_illustairs_luxRan the below service and I've deleted everything except the past 1 day.
Then checked the
statestable:The result is as expected:

Then checked
statistics_short_term:Here I have much older data:

Example YAML snippet
Anything in the logs that might be useful for us?
No response
Additional information
No response