Need help clearing a sensor history

Hello, I have a water flow sensor, and due to a software issue by the developers, its been reporting incorrect (very high) cumulative usage amounts. its been fixed now but when i add it to my energy dashboard, i get a massive correction:

I tried deleting the device, but it is autodiscovered via MQTT, and deleting it didnt seem to clear out the historic data anyway - whats the best way to nuke the history for this one particular sensor (or the whole device, im easy going at this point)
I have a fair few data points that’re quite tedious to set to 0 on the adjustment page (like a month worth as its taken that long to fix)

If you change the entity_id it will start with new data.

Interesting. Would this mess up the autodiscovery HA/MQTT is doing?

This is what gets put onto a topic for autodiscover

homeassistant/sensor/**snip**/cumulative_usage/config {"name":"Cumulative Usage","unique_id":"**snip**_cumulative_usage","state_topic":"Aquaro/**snip**/cumulative_usage/state","device_class":"water","unit_of_measurement":"L","state_class":"total_increasing","device":{"name":"Aquaro Sensor **snip**","mdl":"FlowMonitor v1","mf":"AquaroTech","identifiers":["**snip**"]}}

Namely, i think its naming the entity id based on the values in here as it gets populated as

sensor.aquaro_sensor_snip_cumulative_usage

Ideally i just want to delete everything and start from scratch without renaming the entity

There is the entry_id that’s already there, mostly hidden, and the unique_id and the back end uses that stuff as I understand it.

As long as you are supplying a unique_id in the MQTT discovery, you should be able to go in the UI with the Grat and change the entity_id.

Worst thing that I think can happen is you remember what the entity_id is and change it back before restarting HA and it is the way you started.

I am like 90% sure of this, I don’t do it often, but this is how I understand it. I know if you change it back before restart that it will revert 100%. The other stuff is the I believe that is what happens.

And no, that first sentence is not a typo. There is an:
device_id that is a string of hex
entity_id that is a string of hex
entity_id that is lower_case_chase_text
entry_id
unique_id
name (At least one, maybe others I don’t know about)

Do you have a lot of stats you want to keep?

I get errant data on a few sensors (including my water use sensor) once in a while and I delete them from the statistics tables in the DB. Are you comfortable making a DB backup and trying that?

i cant change the autodiscovery settings, they are at firmware level

i tried editing the db, very cautiously but i didnt know what to do and the stats kept coming back

i have no stats for this particular sensor i want to keep

You should be able to use the Recorder Purge Entities action in Settings → Developer Tools → Actions. Search for ‘Purge Entities’. From there you specify the entity and the number of days to keep (0).

2 Likes

It is setting a unique_id based on that string you posted, so you can change the entity_id in the UI using the gear.
But what they said is not I think going to purge LTS data.

This seems to have done the job!!
I’ll see how it goes for the next hour rollover, but i purged everything older than 1 day (since i only updated the firmware yesterday!) and it seems to have done the job

(I had to update HA a few versions in order to see this option, just adding that in case someone comes looking for a solution and are running an older version)