How to keep existing history data from an mqtt device and re-discover the device with a different name?

I use OpenDTU which talks to an Hoymiles inverter and provides the data via MQTT to home assistant.
Now I want this inverter in a different place and function.

Therefore I am looking for a way to rediscover the inverter with a different device name, but without deleting the history data of its old role.
My idea is to delete the device from the MQTT integration.
Then change the name of the inverter from InverterA to InverterB in OpenDTU.
Finally having HA to rediscover it.

The goal is to get a new device InverterB with a set of entities named eg sensor.inverterb_power, but still have access to data from sensor.invertera_power.

Potential problem may be that OpenDTU use the serial number of the inverter to build the mqtt topic tree, this s/n will of course not change.

Will that work or are there alternative ways??
Has anybody experience with such reconfiguration?

Thanks for any help.
Nob

This is not possible. The data is tied to the entity_id. Change that and you lose your history.

Thanks for responding, Tom.
With entity id you mean the name that is stored in table states_meta as “entity_id” or the metadata_id?

Maybe I should split my questions:
Will all related database content be deleted, if I remove the device from the mqtt integration?
I assumed, that this is not the case, but like to double check…

State data will remain in the database for the length of your purge_keep_days setting (10 days by default).

LTS will only be deleted if you go to Developer Tools → Statistics and use the FIX ISSUE button for the missing entity.

Okay, that would be fine for me. The important point is that the LTS data is still available.

Now the second question is, how can I re-add the same hardware with a new set of entity_id’s?
As I said earlier, the device connects via MQTT.

It will be in the database but things like the energy dashboard wont be able to use it if there is an issue.

And as I said earlier,

You would have to do some serious database manipulation directly.

Ok so this may be possible if you have updated to 2024.3.1. See:

However as this is the same device this may or may not work. Do a backup and give it a try. You can always restore the backup if it does not work.

Hi Tom,
Thank you for the link. I thought that other users must also be challenged by similar situations.
The described procedure seem to match my case.
It is worth a try.
Nob