spook icon indicating copy to clipboard operation
spook copied to clipboard

Delete all orphaned entities not working

Open Jezza34000 opened this issue 1 year ago • 4 comments

What version of Spook are you using?

v3.1.0

What version of Home Assistant are you using?

2024.8.3

The problem

Hi, Action > "Home Assistant Core Integration: List all orphaned database entities 👻" Give me 185 entites :

` count: 185 entities:

  • button.withee_reinitialiser_le_filtre
  • sensor.withee_surface_du_nettoyage_courant
  • sensor.tasmota_last_restart_time
  • time.withee_fin_npd
  • switch.withee_child_lock
  • sensor.omg_esp32_ble_sys_ip
  • sensor.withee_temps_de_sechage_de_la_serpilliere_restant
  • cover.esprts_test_cover
  • binary_sensor.withee_penurie_d_eau
  • switch.withee_ne_pas_deranger

`

When i use : "Home Assistant Core Integration: Delete all orphaned entities 👻" action is OK I restart many time, but entities are still here

Anything in the logs? Paste it here!

No response

Jezza34000 avatar Aug 26 '24 17:08 Jezza34000

I am experiencing the same thing. I just installed spooky for the first time for this reason specifically. Sad to see it isn't working.

joshrp5 avatar Aug 27 '24 18:08 joshrp5

Agreed, it has no effect here.

travisp avatar Sep 14 '24 21:09 travisp

yes, same for me. Trying to delete 770 orphaned entities but nothing happens.

freakyjoe8 avatar Sep 26 '24 08:09 freakyjoe8

I came here with the same issue: The action homeassistant.delete_all_orphaned_entities does not delete the entities listed from action homeassistant.list_orphaned_database_entities.

However the script example here: https://spook.boo/entities (find it under: "Script to remove entities from database") works perfectly for me.

CaptInsano avatar Sep 26 '24 21:09 CaptInsano

I came here with the same issue:

The action homeassistant.delete_all_orphaned_entities does not delete the entities listed from action homeassistant.list_orphaned_database_entities.

However the script example here: https://spook.boo/entities (find it under: "Script to remove entities from database") works perfectly for me.

I tried the script. I first had to reduce the number of entities it was trying to use because the template size was too large. At 1000 entities at a time I received no error but nothing happened. At 100 entities it worked... until I'd gone through about 700 entities and then it too stopped working.

That makes me think that whatever is making it fail silently (maybe a problem removing a particular entity) is also causing the delete orphaned entities action to fail silently.

Edit: I take that back as I was eventually able to remove all the orphaned entities. But it took many multiple passes over the same entities.

travisp avatar Oct 08 '24 23:10 travisp

I'm having the same exact issues as above; tried running the script but it doesn't seem to be doing anything.

Home Assistant Versions

  • Core
  • 2024.11.1
  • Supervisor
  • 2024.11.2
  • Operating System
  • 13.2
  • Frontend
  • 20241106.2

dalto12593 avatar Nov 10 '24 08:11 dalto12593

the script contains action: recorder.purge_entities which is a very time consuming action. Allow it to run for several minutes, in big data bases even hours.

nicknol avatar Dec 06 '24 06:12 nicknol

Can someone confirm if the action works, but perhaps takes some time? Wondering if I need to manually make a script or not...

Thanks :)

Swiftnesses avatar Jan 23 '25 19:01 Swiftnesses

I believe the action is in fact broken. I didn't have that many orphaned entities, only 165, but the delete all orphaned entities action still did nothing. But getting the list and then calling recorder.purge_entities on that list myself worked fine.

globalnamespace avatar Feb 03 '25 16:02 globalnamespace

Sorry, this seems to be working fine

This action does: Home Assistant Core Integration: List all orphaned database entities 👻

It does not clean up orphaned entities, it cleans up history.

../Frenck

frenck avatar Mar 06 '25 21:03 frenck

I think there may be a misunderstanding, the original issue is about the action "Home Assistant Core Integration: Delete all orphaned entities 👻" not the list action.

travisp avatar Mar 06 '25 21:03 travisp

Agreed: homeassistant.delete_all_orphaned_entities doesn't delete any entities. Would be surprised if that's expected behavior.

ejpenney avatar Mar 07 '25 01:03 ejpenney

@frenck Could you clarify the intended behavior of "Home Assistant Core Integration: Delete all orphaned entities 👻"? I'm wondering if the original issue was misread because the poster started by mentioning the "List all" action. However, that was only because they were using that to show that the "Delete all" was not working.

The documentation says that the "Delete all action does the following":

Mass clean up your Home Assistant by deleting all orphaned entities in one go.

Orphaned entities are entities that are no longer claimed by an integration. This can happen when an integration is removed or when an integration is no longer working. Home Assistant considers an entity only orphaned if it has been unclaimed since the last restart of Home Assistant.

The poster was using the "List all orphaned" action to show that "Delete all orphaned" was not deleting the orphaned entities

travisp avatar Mar 07 '25 13:03 travisp

This issue is mixing up the state machine/registries and database. Those are different things.

If you don't understand the difference between these two methods, you probably shouldn't use them.

../Frenck

frenck avatar Mar 07 '25 13:03 frenck

Then I suppose this is a documentation issue. I know for my part, I follow these steps:

  1. Run the action homeassistant.list_orphaned_database_entities and note entities in the list
  2. Try running homeassistant.delete_all_orphaned_entities
  3. Run homeassistant.list_orphaned_database_entities again and compare the results

And in step 3 I get the same entities I got in step 1. Restarting Home Assistant doesn't help. I run the script to remove entities here and then run step 1 and the entities are gone.

I'm assuming based on your abrupt message above this means homeassistant.list_orphaned_database_entities operates on the database and homeassistant.delete_all_orphaned_entities only operates on the state machine/registries. The documentation does not state that these actions are so limited and probably should clarify this distinction if you'd like your users to know about these limitations.

ejpenney avatar Mar 09 '25 00:03 ejpenney

@ejpenney

Thank you for this. Same exact issue here. I was trying to clean up orphaned entities and getting the same results as you.

I'd agree this is a documentation issue if "delete all orphaned entities" doesn't actually do that.

For anyone else struggling with this, once you've used the "list_orphaned_database_entries" to ensure you do indeed want to delete everything it returns, create a script with the following YAML and run it.

alias: Delete orphaned database entities
sequence:
  - action: homeassistant.list_orphaned_database_entities
    response_variable: orphaned
  - action: recorder.purge_entities
    target:
      entity_id: |
        {{ orphaned.entities }}
    data:
      keep_days: 0
mode: single

from: https://spook.boo/entities/#list-all-orphaned-database-entities - under "Script to remove entities from database"

amargolis avatar Aug 19 '25 17:08 amargolis

@ejpenney For anyone else struggling with this, once you've used the "list_orphaned_database_entries" to ensure you do indeed want to delete everything it returns, create a script with the following YAML and run it.

Thank you, this script ends with this error on my side:

template: Template output exceeded maximum size of 262144 characters

So, question is, how to limit the output of the first action?

schuettecarsten avatar Nov 25 '25 20:11 schuettecarsten