Replacing Grid Consumption Sensor without Losing Data

Hi,

As I was reporting on this topic (Replace Grid Consumption Source without losing data?) I got a PV installation working and have a new Smart Meter incorporated into HA, which I would like to replace my previous grid consumption sensor.

The issue is that I have 6-years (yes, six-whole-years!) worth of hourly electricity consumption data that I spent a lot of time importing into HA, so I could compare evolution of consumption as needed. It happens, as I tried, that if you remove a sensor for the grid consumption, all data associated with that sensor is not longer shown.

My proposal is, for those of us that at certain point in time (will) need to replace a sensor (while also leaving the previous one working, as it is my case), that removing the sensor does not imply that all past data is lost.

Would it be possible to have an option with "Do you want to keep previous records on the Energy Dashboard and stop recording updates from the sensor that you are deleting from now on?"

Thanks

Don’t remove it from the energy dashboard.

Delete the old sensor from the Devices & Services entities list.

Rename the new sensor entity id to match the old one.

Your data set should continue to be used.

Thanks, @tom_l but that’s the thing, I want to keep using that sensor (without having it on the energy dashboard) and the associated integration.

That could help, but does not solve the issue. Thanks anyway.

Hello guys,
I would have a similar question if I may hack into this thread.

I have configured an ESP32 device through ESPHome to test the water counting. Call it test-1
As it worked fine, I flashed and cabled the new one with the same config. Call it Water-1
But as you expect, the old data is associated on the entities of test-1 and Water-1 entities have a “_2” attached to the names:

sensor.maison_total_hot_water
sensor.maison_total_hot_water_2

Generally, what would be the best practice when you have to replace hardware, but keep entities names ?

Thanks for your welcomed support.

Tim

Hi guys, the some trouble. Did find solution anybody??

Hey,

No, not by the moment.

I’m having exact the same issue! But no solution on this…

Delete the old sensor from the Devices & Services entities list.
Rename the new sensor entity id to match the old one.
Your data set should continue to be used.

I’ve done this as I wanted to use a new integration to provide data for a specific sensor but not lose all the historical data, I wanted it to resume where it left off. Everything about the new sensor is the same as the old one except the old one was a MQTT sensor and the new one is a template sensor

When I did the steps you mentioned above (removing old sensor, renaming new sensor to the old sensor’s ID) it did not retain any historical data. I have to restore from backup but still have not found a way.

Old sensor that was removed:

- state_topic: "victron/N/b827eb470f9d/system/0/Ac/Consumption/L1/Power"
  name: "AC Loads"
  unique_id: ac_loads
  device_class: power
  value_template: >
    {{ (value_json.value|int(0)) + (states('sensor.studio_power_total_power')|int(0)) }}
  unit_of_measurement: "W"
  icon: mdi:power-socket-uk

New Sensor that replaced it and was renamed to the same sensor ID:

- name: "AC Loads"
  unique_id: ac_loads
  unit_of_measurement: "W"
  state_class: measurement
  icon: mdi:power-socket-uk
  device_class: power
  state: >-
    {{ (states('sensor.studio_power_total_power')|int(0)) + (states('sensor.main_house_power_total_power')|int(0)) }}
1 Like

FYI Q1 here should allow you to move historical data from one entity to another: Energy FAQ

I have seen people report that deleting (instead of renaming) doesn’t work now either. :man_shrugging:

I’ll find out myself next week when I replace my energy monitoring device.

Either way it’s not a solution to VaRe TaS’s problem:

The solution there is to just delete the sensor from the energy dashboard set up.

I would also like too see this feature. Deleting a sensor from the energy dashboard should have an option to retain historical data.

I know there are options to replace the sensor with a new one, but in my case I just want to delete it and not replace it. I know I can delete the sensor and leave it on the energy dashboard but it will give an error when editing the dashboard.

Furthermore it would be nice if the deleted sensor wouldn’t show up on the energy dashboard on dates after deleting the sensor but just for dates in the past. So it would actually be gone from the dashboard from the moment you delete it but show up on historical dates.

I think this feature as described by @VaReTaS would make sense.