Home Assistant – How to CLEAR the short and long term statistic of an entity

UPDATE 1: I was told of an easier way to do this using the UI. Credit to Ildar_Gabdullin on the Home Assistant Forums for providing me this answer. click here for the easier answer

Update 2: Another solution was mentioned that you can rename the entity. When you rename the entity it will update the database to make sure that entity keeps its stats. Then you can delete the entity which will orphan the stats for that entity but under its renaned entity name. Create a new entity with the original name and it should have a clean history!


I was creating a helper utility meter to capture my energy use from an outlet. Some crazy spikes in data happened and all of a sudden I had used 1300kWh of electricity in 4 hours. It messed up my Energy Dashboard cost values and a few differnet things. I thought I had corrected it using the Developer > Statistics and then clicking the ramp up icon at the right end of the row. This will allow you to modify any anomalies. This normally shuld work to remove 1 or 2 bad reads but I found that even after I made the adjustment the stats in the graph were still wrong. As you can see by the photo below I had managed to reset the utility meter to 0 but the graph was still showing old statistical data.

This was very frustrating and I could not find a way to actually reset the utility meter AND its history. No mater where I looked it just kept telling me how to edit the bad reading from the developer > statistic page but not all the data would show. I did a bit of digging and decided to put some of my IT skill to use. I loaded the SQLLite Official Add On from the System > Add-ons page. Once I installed that I opened the app and it will auto load the HomeAssistant database.

The first thing you need to do is find the metadata_id of your sensor. Go to the statistics_meta table and do a search for your sensor by running the following query:

SELECT * FROM "statistics_meta" WHERE statistic_id="sensor.your_sensor_id"

Make sure you replace replace your_sensor_id in the above query with the ID of your sensor. This should return 1 row. If no row is returned then go to your sensor and verify its entity ID again. If more then one row was returned double check you put the FULL Entity ID. Once you get your one row returned that matches your sensor look at the row data and make sure this is your sensor. It should be pretty easy to tell if you have selected the right sensor. Look at the first column that is the ID for the device and remember it. For me it was 86!

Now that you know the ID of your sensor you can run a query to delete all the statistic data for that sensor a query to get all the statistics stored for the sensor.

For me I decided to delete all the records for this sensor and start fresh so I ran the following query

DELETE FROM "statistics" WHERE metadata_id = '86';
DELETE FROM "statistics_short_term" WHERE metadata_id = '86';

This will delete all statistical data hort and long for your entity. Make sure if you need to reset your sensor to 0 also or set your utility meter in the dev tool to the value you want to start at

I hope this helps someone else as this information was hard to find and figure out!!