#Updated HAOS, all stats were reset to 0

1 messages · Page 1 of 1 (latest)

narrow wasp
#

All devices were reset to 0, resulting in insane - consumptions in the energy dashboard for consumers and - production for producers (solar panels). Opening any devices, shows correct growth, where nothing changed, why is HA broken? My Z2M installations are outside HAOS VM, so they were running during the HA update.

narrow wasp
#

Looks like RIP. Wrote a query to update statistics_short_term:

UPDATE statistics_short_term s
    JOIN (
        SELECT
            sst.id AS id,
            sst.metadata_id AS metadata_id,
            msbr.highest_sum AS highest_sum
        FROM
            statistics_short_term sst
            JOIN (
                SELECT
                    metadata_id,
                    MAX(sum) AS highest_sum
                FROM
                    statistics_short_term
                WHERE
                    id < {{ID_AFTER_UPDATE}}
                  AND sum IS NOT NULL
                GROUP BY
                    metadata_id
            ) msbr
                 ON sst.metadata_id = msbr.metadata_id
        WHERE
            sst.sum < msbr.highest_sum
          AND sst.id > {{ID_BEFORE_UPDATE}}
    ) AS rows_to_update
    ON s.id = rows_to_update.id
SET s.sum = s.sum + rows_to_update.highest_sum;

Had to just find some ID before and after the update to find the highest value, and then, all the entries where value is < than highest value.

Very dumb. But now in progress of writing similar for statistics table.