Recently I’ve migrated my P1 DMSR sensor firmware from an ESPeasy firmware that was being read via the DSMR integration to ESPHome DMSR. This however changed the entity ID’s and unfortunately the energy info is now being recorded into different entities.
old => new
sensor.energy_consumption_tarif_1 => sensor.energy_consumed_tariff_1
sensor.energy_consumption_tarif_2 => sensor.energy_consumed_tariff_2
sensor.energy_production_tarif_1 => sensor.energy_produced_tariff_1
sensor.energy_production_tarif_2 => sensor.energy_produced_tariff_2
The goal is to migrate energy history tracked on these 4 previous entities to the 4 new entities and then remove the old integration.
My plan is to:
0. Make a backup of home-assistant_v2.db
- Execute SQL queries via the SQLite Web addon:
UPDATE statistics
SET metadata_id = (SELECT id
FROM statistics_meta
WHERE statistic_id = 'sensor.energy_consumption_tarif_1')
WHERE metadata_id = (SELECT id
FROM statistics_meta
WHERE statistic_id = 'sensor.energy_consumed_tariff_1')
- Do the same for short_term statistics:
UPDATE statistics_short_term
SET metadata_id = (SELECT id
FROM statistics_meta
WHERE statistic_id = 'sensor.energy_consumption_tarif_1')
WHERE metadata_id = (SELECT id
FROM statistics_meta
WHERE statistic_id = 'sensor.energy_consumed_tariff_1')
(doing the same for all 4 entities)
- Remove the old integration (assuming the entities and history are deleted along with it)
Does this plan make sense?
I’m guessing this does not get rid of the big hump of data seen below that was recorded when the new entities were added? (which basically also contains last year as well). I will probably have to come up with queries that delete this data.
Starting over is also an option, but one I’m trying to avoid.
1 post - 1 participant