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.

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

I am in the same situation. I want to replace the sensor that reports generated solar power since the current sensor kind of sucks and replace it with a shelly PM sensor without loosing data or deleting the current sensor.

any solution?

Did you suceed? How did you do it?

No, I didn’t bother trying. All my long term data is in InfluxDB.

So you didn’t replace your sensor for the energy dashboard?

No, I didn’t bother trying to keep the data.

Anybody else switched the sensor which is relevant for the energy dashboard?

***NOTE:*** The new entity ID can't have statistics associated with it already, or the data transfer will not work.

From the FAQ … doesn’t answer how I prevent a brand new statistic to be created within milliseconds after my new sensor is registered… any ideas for this? I’d love to keep my data!

***NOTE:*** The new entity ID can't have statistics associated with it already, or the data transfer will not work.

From the FAQ … doesn’t answer how I prevent a brand new statistic to be created within milliseconds after my new sensor is registered… any ideas for this? I’d love to keep my data!

Not sure if you went ahead and did this anyway @mfx, but it seems that note is nothing to worry about. I deleted the old energy monitoring device from HA, rebooted, renamed the entity IDs of my new energy monitoring device with the copy-paste of the old ones, and it seems to have carried the historic data across without any issues. This is despite the “new” entity IDs had been online for ~30 mins with new data already associated to them.

Screenshot below of the new device/sensor, with 0.014kWh worth of energy so far today, and the existing ~1,100kWh of tracked data from the past year or so. Same goes for the power (W) and current (A) sensors.

Also shows in my energy monitor dashboard without having to change anything there. Just as if it was the old device still running. Happy days!