Deleting orphaned entities

Hi

I have four orphaned entities. Under Devices&Services-Entities they are displayed as Unmanageable and belonging to Sensor/Binary-Sensor integrations. (Zigbee door sensors leftovers)
They cannot be selected and deleted. I found few posts in this forum describing such problem. None of the suggested solution/work-around could help me.
In other words, I didn’t find any way to delete them with UI.
It is not only cosmetic problem because they appear as ghost entried in a card using following:
include:
- name: attributes.device_class
value: battery

The question again is: how to remove them?

Another, maybe more important questions are: why do I have them? They don’t have unique ID. If it is bad,
why am I allowed to create such entities? What can I do to prevent this?

Thanks for your time.
Chris

Did you try to empty browser cache, hard-reload HA? In 90% of those cases, it’s just the browser, which is just having them in cache and display them, even if not really existing anymore.

I have 2 integrations that create a lot of orphaned entities, although I cannot prove that they have any impact on functionality/performance… I just want then ‘out’. I created the below script which I then call periodically from an automation.
There is an action to delete all orphaned entities but I had issues in the past (no longer tested as below is fine for me)

script:                   
    delete_orphaned_entities_geo_location:
        alias: Delete geo-location orphaned database entities
        sequence:
          - action: homeassistant.list_orphaned_database_entities
            response_variable: orphaned
          - condition: template
            value_template: "{{ orphaned.count | int > 0 }}"  
          - action: notify.mobile_app_iphoneXYZ
            data:
                message: "Count orphaned entities: {{ orphaned.count }}"
                title: Count orphaned entities
          - action: recorder.purge_entities
            data:
              entity_globs: geo_location.*            
          - action: recorder.purge_entities
            target:
              entity_id: |
                {{ orphaned.entities }}
            data:
              keep_days: 0
        mode: single

Thank you both for the reply.

They are gone!
The server was rebooted this morning. Then I checked and they were there, in Devices&Services-Entities
and also in my “Battery status card”, before I wrote my initial posting.

I went away, three hours later I am back, read your answers, access my server with another browser: they
are not there. Back to my “old” browser - they are away!
It must have something to do with browser’s cache.
Learned something!

Thank you very much.
Chris

A reboot does not delete orphaned entries, at least, it does not with me. Mind you…there are so-called orphaned entries and old/outdated entries…so maybe that it is the diff ?

A word of caution: Use the script with extreme caution, making a full backup beforehand in case it goes rogue. Make sure you modify it for your specific requirements - do not use the entities listed without knowing what you are doing. Here be dragons.

+1 yes…you are right, forgot to mention this, thanks !