How to correct a long term statistics value

Hi
I have an utility meter which records the on time of a switch. The state gets reset every day (at midnight) Everything works as expected.
But for some reason, the recorded value has in one day a wrong state.
I can correct this in the sqlite db, however the sensor on my card then adds the difference I have corrected to the current day automatically. From where gets HA this value? I can not find any hint in the db nor in the core.restore_state file.
The state in the staistics table is correct, but the sum just jumps to a higher value.

image

Any idea where HA gets this value from?

Go to Developer Tools → Statistics. Find your utility meter sensor and click on the ramp icon to the right of it. Navigate to the time the error occurred and delete the value.

2 Likes

Thanks for the answer. I found there a value which is not correct. From where are these values? They are not from the DB. Is there any other location where HA stores that?

They are calculated from the values in DB.

This can somehow not be the case, because I have deleted the states for the entity used here and only kept the statistics data. But still I saw the values under “Developer Tools → Statistics” for this entity. And more strange, there the values are shown in 5 minutes steps whereas the states table records it on change or every minute and the statistics logs it every hour.

However I could solve my problem with setting the value in “Developer Tools → Statistics”. Thanks again.

The values use for the calculations are stored in the db statistics table, not the states table.

I assumed that, but the 5 minutes showing in the statistics edit dialog is not present in the statistics table.
The statistics table shows me only that between 10:00 and 11:00, the switch was on for 0.85 hour:

image

But in the “Edit” dialog, I see exactly when it started and for how long (in the mentioned 5 minute steps)

image

Is this calculated by HA? How does it know when the start was or if there was a gap within one hour?

It is not a problem related to the issue here, it just interests me…

Must be another table somewhere?

I do know that after a week the LTS 5-minute values are down-sampled to hourly max, min and average so only 24x3 values a day are kept forever.

Try going back over 7 days in the edit dialogue to see this.

:roll_eyes: :man_facepalming: the table is statistics_short_term… it keeps the statistics in 5mins step for (default) 10 days.
I should have known this as I already used it before…

1 Like

It must be hinged on the purge_keep_days setting. Mine is set for 7 days.

the table is statistics_short_term… it keeps the statistics in 5mins step for (default) 10 days.

Are you sure? I’ve been looking in that table for values that are shown in developer-tools/statistics , but can’t seem to find those…

Trying to find the location in the database so that I can do a search for specific (too) high values that I might’ve missed, but can’t find those 5-minute values anywhere (also checked in other tables).