Merging values whenever you change a device

I replaced my DSMR reader twice this year. But now I have 4 orphaned entities that I have to keep.
Also in the energy dashboard I need to add all of the previous entities.
I tried to merge them in a copy of my database but didn’t work.

This is also the case when you switch a metered power plug or something like that. The whole history is ruined/reset for the connected device in the energy dashboard…

duplicate of