Energy dashboard stops updating, subsequent database corruption

I have this strange problem for more than a week now that my energy dashboard stopped updating. The log is full of errors apparently relating to the computation of long term statistics. The only fix seems to be, to start with a fresh database, which I would like to avoid for obvious reasons.

The HA error logs:

Error executing query: unsupported operand type(s) for +: 'NoneType' and 'float'
TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'

Has anyone else experienced this problem?

I tried to narrow down the bug, but the error message is not specific enough and I don’t know where to start the investigation.

I created an issue on the HA bug tracker as well.

I managed to fix this issue with a little bit of beginner SQL fu. The database was structurally fine, but had some rows left over from a previous schema migration. Clearing out some old rows fixed it fortunately.

I have the same issue. Please describe more in detail how you " fix this issue with a little bit of beginner SQL fu"
Thankyou

You can find my explanation in the linked issue on GitHub:

Hope it helps.