Keep statistics when changing entity name

Hello,

How can I change an entity name while presuming the long term and short term statistics?

I replaced one device where I used statistics for energy. A solution how to take over the old statistics I found. I deleted the old entity and renamed the new entity to the old name. By doing so, the new device takes over the old statistics by using the old entity’s name. This technically is working. But the “messed up” entity name is confusing me.

I am using MariaDB. Can I just change in the database the name of the statistics by editing the “entitiy_id” in the table “statistics_meta” by phpMyAdmin?

Idea:

  1. change entitiy_id in statistics_meta to new entity name
  2. change entity name to new entity name

You didnt need to delete the old one but left it in the dashboard for statistics. For the new entity to use the old statistics you changed the entity id? Then you can change the normal name to the new one or change the new one back and make a dummy template sensor which you can name after the old entity.
I wouldnt change the database, but you can try if you want just make a backup and restore when you mess up.

Renaming an entity_id also moves all statistics/history with it.

1 Like

Thank you. I did a backup, tested and it worked.

Changing “entity id” in the database to the new entity name let me use the old statistics with the new device by using new entity names.

Step 1:
After renaming the entity name of the new device to the entity name of the old device, the entity took over the old statistics.

Step 2
After changing the entity_id in the statistics database to the new entity name I also can use the old statistics in combination with the new entity names.