Energy monitoring in 2021.12

The first morning after I installed 2021.12, I got this weird blip in my energy usage. I assure you my solar panels did not consume ~11 kwh from midnight to 1am :slight_smile: The underlying sensors did not exhibit any similar weirdness. It’s the first time anything like this has happened, so I assume it is something to do with 2021.12.

Any idea how I can fix this data blip so my month and year values are not messed up?


I’ve moved to 2021.12.1 and I am seeing the same behaviour this morning. Something’s got to be wrong. Do I have to manually edit the database to fix this?

For the record, my energy dashboard typically looks like this, as it did on the day before I upgraded to 2021.12:

I’ve looked into what is going on in the database with regards to the states of the sensors (which all look good) and the statistics table (which also looks good). However, it’s very suspicious that the negative usage I’m seeing at midnight is the same as the total accumulated number from the previous day. The best thing I can figure is one of the following:

  1. Since the statistics.start field aligns directly with an hour, I think this could be a case of a DB query using a greater than or equal to instead of a greater than so that it is matching the last entry of the previous day when it shouldn’t, OR
  2. Something has regressed with 2021.12 that caused it to incorrectly interpret when my daylight savings time started, and it still thinks I’m GMT-3 which is causing the query to be off by 1 hour.

My timezone is currently Atlantic Standard time (not Daylight Time, which ended back in November) and is GMT-4.

I know I’m just posting to myself here, but I’ve done some more digging in the statistics table and I have some findings. Maybe this can help whoever can attempt to fix this bug.

It looks like at the start of each day, the sum column is being reset to what it was at the start of the previous day instead of continuing to grow as a sum normally would, so that when the difference is calculated from the previous sum, the result is negative, even though the sensor never reports a negative value.

I think the only way to fix the historical data would be to go and re-calculate all of the sum values by actually adding up all of the changes in states from whatever date 2021.12 was installed.

Here’s the SQL query I used to show this range of data. I specifically only wanted to see the range of times where it would transition from one day to the next.

    `statistics`, `statistics_meta`
    `statistics_meta`.`id` = `statistics`.`metadata_id`
    AND `statistics_meta`.`statistic_id` = 'sensor.sense_daily_from_grid'
        (`statistics`.`start` >= '2021-12-11 02:00:00.000000' AND `statistics`.`start` < '2021-12-11 05:00:00.000000')
        (`statistics`.`start` >= '2021-12-12 02:00:00.000000' AND `statistics`.`start` < '2021-12-12 05:00:00.000000')
        (`statistics`.`start` >= '2021-12-13 02:00:00.000000' AND `statistics`.`start` < '2021-12-13 05:00:00.000000')
        (`statistics`.`start` >= '2021-12-14 02:00:00.000000' AND `statistics`.`start` < '2021-12-14 05:00:00.000000')
        (`statistics`.`start` >= '2021-12-15 02:00:00.000000' AND `statistics`.`start` < '2021-12-15 05:00:00.000000')
    `statistics_meta`.`statistic_id` ASC,
    `statistics`.`start` DESC;

I’ve also noticed that the last_reset fields for some sensors are not being consistently set in the statistics table. In particular, the entities that are giving me trouble have this field set to null. This really seems like a bug, because even my attempts to correct the values with a script can’t detect when the state is reset (vs. actually being 0).

Is anyone actually reading this? Anyone having similar problems with entities in the statistics db table?

1 Like

I appear to be having the same issues, started 12th december (probably when I updated.)

1 Like