How do I remove an Entity?

I’m writing a Component for the Visonic Powermax Burglar Alarm (here) and I have a problem that I’m hoping someone can help me with. When the connection between the Alarm Panel and HA is broken (TCP over Ethernet for example) I can trap it with an exception handler and re-connect to the Alarm Panel but I get exceptions like this:

2019-01-06 19:38:44 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/src/app/homeassistant/helpers/entity_platform.py”, line 344, in _async_add_entity
raise HomeAssistantError(msg)
homeassistant.exceptions.HomeAssistantError: Entity id already exists: sensor.visonic_z03. Platform visonic does not generate unique IDs

I know that the entities still exist from the previous execution before the re-connection to the Alarm Panel, so I tried removing the state using “hass.states.async_remove”. This didn’t make any difference.

Is there a method within HA to remove an already existing entity by entity_id? Not just the state but the entity itself.
Or is there are method so I can simply remove all entities for my Platform? i.e. Unload a Platform?

The alternative is that I test to see a sensor already exists before I call “discovery.load_platform”

Please keep in mind that I’m just learning the HA Architecture and so may have mixed up entity, component, platform and any other key words :slight_smile:

Any help would be much appreciated

have you found it?

No sorry, I would still like to know though

for me
hass.add_job(entity_object.async_remove())
worked, but you have to have the object, …

@Filip_Van_Ham : Is there any way to run that from the Homeassistant GUI?