Ability to clear (long term) statistics for excluded entitites

Background

  • The long term statistics (i.e. the statistics table) is never purged. Nor is there a way to do it manually without doing SQL statements directly in the database.
  • Default is to have all entities recorded, and for entities having the right types of values they thus by default end up in this ever growing table.
  • After a year or so, people will (rightfully) start to optimize their ever growing database by excluding entities from the recorder.

Problem
The problem is then, that there is no way to remove the statistics. In some cases, it is possible, like if the entity has been removed. Then we have a “Fix” button. But in the case of the entity being excluded, on purpose, then there is no way.

I have hundreds of these, taking up around 500mb of database (I actually measured just the statistics table using SQL):

When clicking “FIX ISSUE”, there is no option to delete the statistics. It is for some cases, like entity is missing, but not if the entity is excluded.
Screenshot 2022-08-11 at 12.56.00

Proposal / feature request

  • Make it possible to exclude sensors from statistics (yet still not exclude them from the recorder - sometimes it is good to have a week’s history of something but not keep it forever).
  • In the case of an entity being excluded from the recorder, and prior statistics exist, show the “fix” button to remove the old statistics retroactively.
  • Introduce a statistics.purge_entities functionality similar to recorder.purge_entities. Perhaps also with a “days to keep”-setting, which recorder.purge_entities really should have, too.