How to clear the long term stats of a sensor

yeah that’s what we figured out, rename it to something random which will take the history along with it under that new entity ID then just delete it and leave the records orphaned they’ll get cleaned up over time.

1 Like

Sorry, see no logic here.
After these actions you will have in DB two sets of data of what you call “orphaned entity”, of course both will be deleted in purge interval. What is a purpose of this?

because sometimes you’re playing around and have a lot of stupid data in your database. then when you finally get it all working you want that old data all cleared up…

Your answer was to “why would I want to delete old history” question - but not to “why would I want to have 2 sets of data to be deleted” ))

I have no idea how we even got here haha. I just wanted to post how to delete statistical data for a utility meter. Better answers were given not sure what others are talking about still. The use I need is solved

This is for who don’t know want edit database.

Editing database it’s not hard after all.

metadata_id

SELECT * FROM "statistics_meta" WHERE statistic_id = 'sensor.eb3a_adc_addon_r'

387 sensor.eb3a_adc_addon_r

check for bad values

SELECT * FROM "statistics" WHERE metadata_id = 387 AND min < 100

remove it

DELETE FROM "statistics" WHERE metadata_id = 387 AND min < 100

state_class: total_increasing. can be fixed from UI in dev tools.

state_class: measurement. only editing DB.

Delete things it’s the last resort to fix wrong values.

In the begin I just delete all DB. :rofl:

2 Likes

yours is great for a few bad reading, if you want to go full scorched earth. I am in the process of writing a SQL Query to fix these bad records… just subtract the bad value reading from the state in all 3 tables state, statistics, statistics_short_term

1 Like

In this thread it is claimed that the current behaviour is a bug:
after changing “entity_id” for an entity with “unique_id” a history for this entity should be retained.
Currently it is not retained according to my test.

Why can’t the devs just add a button in the developer statistics to remove data ?

2 Likes

100% agree!

Also Agree, this is so annoying. When you start out with HA you have a learning curve and make mistakes, or it just takes time to get all sensors and integrations going, so when you are finished the data won’t add up because the measurement is not started at the same time.
Current solution for this, make another 30+ helpers, or rename-delete-add back 30+ entities. :confounded: Come on! I thought I was finished! Just want to reset all long time data and look at the data filling in again over the next days. :disguised_face:

Yes, there should at least be a button per entity to do this in devtools and it would really be very nice if there would be the option to delete all long time data in one click (maybe 2, are you sure?)

1 Like

You can perform recorder: purge_entity action in dev tools.