My HA crashed due to SSD failure on July 2nd, and my last full backup was on June 30th.
After I restored from the backup, I found that all my monthly Utility Meter entities were not reset to start from July 1st. Instead, they continued to accumulate from the June values.
Is there a way to fix this? or is there a configuration setting to prevent this from happening?
Yes I can write some script to set them using the utility_meter.calibrate action. Not important at the moment.
IMHO, the Utility Meter is too dumb. I have some other integrations with monthly entity values; they all reset themselves to 0 on July 2nd after I restored from the backup. (The value on July 1st was the same as that of June 30th which is expected).
When you restore a backup you restore the database too. So all sensors get the state they had when the backup was made. That is what restoring a backup does.
I meant that the algorithm for Utility Meter (UM) helpers may have a bug for this scenario.
e.g. On June 30 (the last backup), UM monthly energy had value 120 kWh. So on July 2, when I restored from backup, the UM monthly energy has value 120 kWh but it SHOULD check the last timestamp which was June 30 and reset to 0 since July 2 is a new month.
I have a Tapo energy monitoring plug which has a month energy reading. It reset itself to 0 on July 2 after I restored. This value is probably stored in the plug and wasn’t affected by HA’s “fauty” UM algorithm.
A utility meter should have a last_reset and a next_reset attribute. After the restore (perhaps during startup), did the next_reset attribute get changed to the next month? If so, it would make sense to modify that code so that when the next_reset attribute is changed, the utility meter is reset at the same time. Even if it is past the datetime when the reset is supposed to occur.
If the next_reset attribute didn’t get changed and still reflects a datetime in the past, then that seems like a bug.
I agree that there is an issue there. Not just monthly and it would affect any timefame. (such as restoring a backup from last week will affect the weekly UM).
I have opened an issue with dev and hopefully someone will take a look at it.