How to fork an energy integration and keep history

Hello,

Sorry if this is a very basic question. Im still new to HASS development.

I use a custom integration for energy monitoring (it polls data from a third party site).

Because of some migration happening by the seller some users will be moved to a new platform and others wont this.

As a result, I want to fork the integration to a new one but I want users to keep their existing energy data.

I plan to keep the same entities so it would be just the integration domain that would change (e.g. sensor.integrationA_power would become sensor.integrationB_power)

What is the best way to achieve this? I dont think keeping the same integration domain makes sense since it is a new integration. Is there a way to keep the history with the new entities?

Greetings.

The only supported way will be to rename sensor.integrationB_power to sensor.integrationA_power (and the latter to something else, ofc)

this means my integration needs to keep using the old integration domain, right? (to keep the entity prefix)
isnt reusing the domain from a diferent integration a bad practice? do I have no other choice?

No. The domain is sensor, here. Whatever comes after it, e.g. integrationA_power is called an object id, and is not linked to an integration.

Actually, the bad practice is to have the integration name in an object_id. The object_id traditionally represent the purpose of an entity, e.g. sensor.power_living_plug, but integrations are free to generate whatever object id they want.

1 Like

I see. probably the integration I want to fork does that and I assumed it was a common practice.

I’ve been testing and the behavior Im seeing is that home assistant is creating new entities using a _2 suffix.

It seems that home assistant will not just ‘transfer’ entities from one integration from another if the platform name is different.

Is this the case?
It would seem I would need to keep the old name in my fork to keep using the same entities. Did I understand correctly?

I think I understand now. the entities provided by the old integration need to be deleted first.
so in order to migrate to a new integration, users would need to

  • remove the old integration
  • delete the existing entities
  • add the new integration.

Otherwise new integrations with _2 would be added. It does seem that if the energy entities are deleted and recreated with the same ids, history is preserved.