Dynamic Energy Cost

How to keep history when replacing a device has been discussed before and there are suggested sullitions for this. I have not tried them myself, but i would create a new backup before testing this. Take a look at this thread: Replace entities and keep history (BREAKING CHANGE starting HA Core 2023.4) - #4 by e-raser