I tried to reproduce the sequence the suggested sequence and and failed at first, but then succeeded. Here is a report what happened. I hope it can be useful for someone. I didn’t find exact detailed description in the forum.
I have an ESPHome device with a sensor. I need to replace this device and retain history and statistics of the sensor.
Steps
- Entity to retain
sensor.esphome_originalcontains history and statistics for the past - Turn off the old device
- Connect the sensor to the new device
- Flash the new device
- New sensor gets name
sensor.esphome_new - (here were steps from wrong way, see below)
- Make a backup for Home assistant
- Make a copy of
/config/.storage/core.entity_registry - Open
/config/.storage/core.entity_registryin Studio Code Server - Find
"entity_id":"sensor.esphome_original" - Replace it to
"entity_id":"sensor.esphome_old_dummy"← this is considered a dangerous operation, be careful to not accidentally corrupt something else. This is also a critical step in the whole sequence. - Restart HA
- Now history and statistics is not available for
esphome_old_dummy - Rename
esphome_newtoesphome_original - History and statistics is available for
esphome_originalbefore turning off the old device - Any history collected for
esphome_newfor the time before renaming is lost - Outcome -
esphome_originalis on the new device up and running with history and statistics retained - Side comment -
esphome_old_dummyis still available on the old device, but without any history and statistics and probably will start collecting them if start using the old device again
Steps succeeded thanks to the comment: How to replace entity in Energy Dashboard by new one without losing history - #15 by Nerdix
Wrong way
- Settings → Device & services → Entities
- Status of old entry is “Unavailable” - exclamation mark in red circle
- Enter selection mode → select
- Three dots menu → Delete selected
- Dialog → Confirm
- Delete selected entities?
- You can only delete 0 of the 1 entities. The others require the integration to stop providing them, and sometimes a Home Assistant restart is needed. Are you sure you want to delete the deletable entities? Remove them from your dashboard and automations if they include these entities.
- Item stays
- Rename - error “Entity with this ID is already registered”
Additional information
Home assistant versions:
- Core 2025.2.4
- Supervisor 2025.02.1
- Operating System 14.2
- Frontend 20250214.0
Good luck!