I was wondering if it is possible to replace an entity that is used by the Energy Dashboard without losing history.
Currently I’m using a web polling integration for my solar panels. I updated the firmware of my inverter, so now I kan use a local polling integration.
Now I have two entities in HA with the same value, but with a diffent name/id. I would like to replace the old entity by the new one. But would like to keep the history on the dashboard.
Yes, just add the new entity. Change the entity_id of the old entity to a holder name, change the entity_id of the new entity to what the old entity’s entity_id used to be.
EDIT:
The new process is:
Delete old entity
Rename new entity to old entity_id
New entity will inherit old entities history
Do not under any circumstances rename the old entity before you delete it, this will cause the history to follow the renamed name.
Have you found an option to get this done?
I have to replace the entities tracking my photovoltaik system. I already have half a year of history and really don’t want to lose that.
Sadly I really have to do this, though, as my old entites no longer work as of today.
The old entities were created with templates. Is it possible to alter these templates, so that they just show the values of the new entites and this way continue the history?
If yes, then how would I do that?
Can not find the topic, but ended up altering the short and long term statistics in the database. Now it works but you should make a backup before you begin.
Altering the templates may be an option too, just try after making a bachup first
I guess this is confirmed (multiple times) to work that way reliably, isn’t it?
I thought with step 1 all the history is gone already… at least data from states table will be removed immediately, will it?
Statistics of course remain in the database (mine collected a garbage of 53 entities already… ).
Is it safe to rename the entity in step 4 (so once it already catched the history of the old one)?
Cross-post with a similar process (just with many more words):
Cannot migrate history for entity_id `sensor.network_in_end0` to `sensor.network_in_eth0` because the new entity_id is already in use
Cannot migrate history for entity_id `sensor.network_out_end0` to `sensor.network_out_eth0` because the new entity_id is already in use
Cannot migrate history for entity_id `sensor.network_throughput_in_end0` to `sensor.network_throughput_in_eth0` because the new entity_id is already in use
Cannot migrate history for entity_id `sensor.network_throughput_out_end0` to `sensor.network_throughput_out_eth0` because the new entity_id is already in use
(I deleted the *eth0* entities and renamed the new *end0* entities to *eth0*)
I guess basically this message is saying “the history of your NEW (*end0*) entities is now overwritten by the history of the old (*eth0*) entities” - which is fine, so it’s “safe” to ignore those HA log errors. Right?
And what about this big important question?
Corner case in addition to that:
To be 100 % safe, shouldn’t step 4 be “delete statistics of entity which got overwritten in step now at /developer-tools/statistics”? Otherwise, what would happen if one would change the entity_id back to the entity_id it had prior to the renaming…? That’s very important to know actually.
Answered in parts by my own:
Renaming is fine, history will follow.
Corner case (using the entity_id which has been used before): history will stay, but the states shown now are wrong. One definitely looses the states table data , which is a) not an issue anyway after reaching the recorder keep_days setting or when using HA Core >= 2023.12 as it now simply shows the statistics for the time there are no state values (see 2023.12: Welcome home! - Home Assistant):
That all sounds quite good, but does it still work if the meter readings are different?
I got a new water meter that starts at 0 again. That was already a problem without a new entity. Now I’m getting a new electricity meter (with a new entity). What happens if the last reading was 13282 kWh and the new meter starts at 0 again?
I hope so, I’m a little bit nervous. Before I get my new electricity meter, I have to switch from a Tasmota „Volkszähler“ to a Tibber Pulse. Then I will get my new meter in a few weeks.
So I have to switch entities first and hope Homeassistant will do the rest when the meter is replaced.
Thanks for sharing!
This way worked me for the current version of HA:
OS Version: Home Assistant OS 11.4
Home Assistant Core: 2024.1.5
The new process is:
1. Delete old entity (Settings > Device&services > Entities) It was in "Restored" status. Select the checkbox at the begining of the row!
2. Rename new entity to old entity_id -> click to the entity_id > settings > rename entity_id > update
3. New entity will inherit old entities history (no reboot needed, it is on the fly...)
IMPORTANT: Do not under any circumstances rename the old entity before you delete it, this will cause the history to follow the renamed name. (If you already renamed it, because you followed the earlier process, you have to rename it back, than reboot, than follow the new process above. It worked me this way too.)