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.)
If it’s a yaml automation, changing the name will cause it to lose the history. If you add an id to the automation, changing the name via the UI will carry the history w/ the name change.
This is true for all yaml entities. No unique_id, no carry over.
I created all my automations using the UI right from the beginning.
Checking automations.yaml, I can find the automation by alias, and it has an id.
That’s exactly not the way it happened for me.
So why doesn’t it work? Is an id in an automations.yaml not the same as an unique_id (as e. g. used for template entities)? Something’s different here…
Would you (others, feel free too) be so kind to give this a test try on your system? As renaming the automation back to the old/original one, nothing is lost.
I’m sure you’re on the latest HA release. Because that’s the first thing devs come up with when filing a new issue.
And as mentioned: no deletion of this entity as first step (because automations behave different, scripts likely too). Maybe that’s the thing?