Rename/migrate long term statistics


So i’ve been searching around and following several topics about migrating/renaming of long term statistics entities for more then a year now. I’ve been fiddling around with some SQL queries in the phpmyadmin add-on aswell, but still without succes unfortunately. There are just so many things that can go wrong when doing this manually.

So my situation:

database = mariadb
I have multiple entities in my energy dashboard that need to be replaced ( PV, gas, electricity ) by new entities, since the devices that are related to the old entities will be removed from my house and thus stop creating data.

The new entities are allready up and running for a while.

I need the old long term statistics to be merged with my new entities to prevent losing all my historical data.

Anybody that can help me out in the right direction? I think there must be more people out there having the same problem :slight_smile:

I was really hoping the developers of HA would create some native solution for migration/renaming of long term statistics between entities the past year.


LTS are associated with entity_ids.

Make a note of the entity_ids then delete your old entities, the data will remain in the DB.

Rename your new entity ids to match the old ones exactly. The data will continue to be collected and shown as as continuing on from the past data recorded by the old entities.