[Custom Integration] Orphan Entity Cleaner – Find and delete orphaned entities safely

[Custom Integration] Orphan Entity Cleaner – Find and delete orphaned entities safely

Hi everyone! :waving_hand:

I’d like to introduce Orphan Entity Cleaner, a custom integration for Home Assistant that helps you detect, review, and safely delete orphaned entities in your system.

:thinking: What’s the problem?

When you remove an integration, unpair a device, or perform a major update, entities often remain in your registry. These “orphaned” entities:

  • Clutter your entity list
  • Degrade performance
  • Cause errors in logs and automations

:hammer_and_wrench: What does Orphan Cleaner do?

This integration provides a built-in sidebar panel where you can:

  • :magnifying_glass_tilted_left: Scan for orphaned entities (with extended detection logic)
  • :clipboard: Review the list with search and filter options
  • :white_check_mark: Select entities in bulk
  • :test_tube: Dry-run to test before deletion
  • :floppy_disk: Export results as JSON
  • :shield: Automatic backup before any deletion
  • :locked: Protection for entities with config_entry_id
  • :clipboard: Allowlist for critical entities (never delete)

:shield: Safety first!

I know that deleting entities can be risky, so I built in multiple safety layers:

  • Automatic backup creation before any destructive action
  • Protection for all entities with a config_entry_id
  • An allowlist that permanently protects critical entities like zone.home
  • Dry-run support to test what would happen
  • Admin-only access to prevent accidental actions by non-admin users

:package: Installation

Via HACS (recommended)

  1. Open HACS in Home Assistant.
  2. Click on “Integrations” → three dots (⋮) → “Custom repositories”.
  3. Add this URL: https://github.com/realsly2/Orphan-Entity-Cleaner
  4. Select “Integration” as the category.
  5. Click “Install” and restart Home Assistant.

Manual installation

Copy the custom_components/orphan_cleaner/ folder into your Home Assistant custom_components/ directory and restart.

:rocket: How to use

  1. Open Orphan Cleaner from the sidebar.
  2. Click “Start Scan”.
  3. Review the detected entities.
  4. Use search and filters to narrow down your selection.
  5. Select the entities you want to delete.
  6. Export or backup the results (optional but recommended).
  7. Run a dry-run to test.
  8. Click “Delete Selected”.

:bar_chart: Services & API

The integration provides several services for automation:

  • orphan_cleaner.scan (with optional strict_mode: true)
  • orphan_cleaner.delete_selected (requires entity_ids parameter)
  • orphan_cleaner.clear_results
  • orphan_cleaner.export_results
  • orphan_cleaner.backup_results
  • orphan_cleaner.get_allowlist

API endpoints

  • GET /api/orphan_cleaner/results – Retrieve scan results (with pagination)
  • DELETE /api/orphan_cleaner/results – Delete all results
  • GET /orphan-cleaner – The sidebar panel

:test_tube: Requirements

  • Home Assistant 2026.8.1 or newer
  • Python 3.10 or newer

:bug: Bug reports & Contributions

If you find any bugs or have improvement ideas, please open an issue on GitHub:
:backhand_index_pointing_right: https://github.com/realsly2/Orphan-Entity-Cleaner/issues

Contributions are welcome! Feel free to fork the repository and submit pull requests.

:memo: Future plans

I’m planning to add:

  • More filtering options in the panel
  • Enhanced reporting with statistics
  • Integration with Home Assistant’s backup system

:speech_balloon: Feedback

I’d love to hear your thoughts! Try it out and let me know what you think. Any feedback, feature requests, or suggestions are highly appreciated.


Check it out on GitHub:
:backhand_index_pointing_right: https://github.com/realsly2/Orphan-Entity-Cleaner

Happy cleaning! :broom::sparkles:

1 Like

It doesn’t allow installation via the UI, and there is no documentation for installing in YAML.

Hi @Marcos_Felipe,

thank you very much for your feedback! You’re absolutely right – the integration is currently not installable via the UI. This is because it’s a Custom Integration that is not part of the official Home Assistant Core.

Here are the two ways you can install it:

1. Via HACS (recommended)

The integration is designed for HACS. You can add it as follows:

  1. Open HACS in Home Assistant.
  2. Click on “Integrations” → three dots (⋮) → “Custom repositories”.
  3. Add this URL: https://github.com/realsly2/Orphan-Entity-Cleaner
  4. Select “Integration” as the category.
  5. Click “Install” and restart Home Assistant.

2. Manual installation (via YAML)

You asked about YAML installation – here is the step-by-step guide:

  1. Download the custom_components/orphan_cleaner/ folder from the GitHub repository.
  2. Copy it into your Home Assistant custom_components/ directory.
  3. Add the following line to your configuration.yaml (this is important!):

orphan_cleaner:
4. Restart Home Assistant.
After the restart, the integration should load automatically and you will find the Orphan Cleaner panel in your sidebar.

I will update the documentation in the README.md to make the YAML step clearer. Thanks for pointing this out!

Let me know if it works now or if you have any further questions.

Best regards,
realsly2

Looks like there’s some further configuration required :confused:

image

How is this (or is it) related to the already existing Orphan Entity Cleaner from Franz646? It looks very similar.

If it’s not related then how is this better?

:rocket: Update: Orphan Cleaner – New Features & Improvements

Hi everyone,

I’ve made some significant updates to the Orphan Entity Cleaner integration based on community feedback and to make it even more powerful and flexible. Here’s what’s new:


:new_button: What’s new?

1. Simplified Installation

  • The integration now loads correctly when you add orphan_cleaner: to your configuration.yaml.
  • No further configuration is required – it just works!

2. Multiple Detection Methods

The integration now uses four methods to detect orphaned entities:

  1. orphaned_timestamp – The official signal from Home Assistant (always used).
  2. Dead config entry – If an entity’s config_entry_id points to a config entry that no longer exists.
  3. Unavailable state – Entities that have been unavailable for a configurable period (default: 24 hours).
  4. Heuristic (optional) – Enabled via the aggressive_heuristic flag in the service call.

3. Enhanced Services

Service Description
orphan_cleaner.scan Start a new scan (optional: aggressive_heuristic: true)
orphan_cleaner.delete_orphans Delete selected entities (requires entity_ids, optional dry_run: true)
orphan_cleaner.clear_results Clear saved scan results
orphan_cleaner.export_results Export results as JSON
orphan_cleaner.backup_results Create a backup of results
orphan_cleaner.get_allowlist Return the current allowlist

4. Improved UI

  • The sidebar panel now has better search and filter options.
  • Bulk selection is more intuitive.

5. Updated Documentation

  • The README.md has been completely revised and now includes:
    • Full installation instructions (HACS + manual)
    • Detailed detection logic
    • Service and API documentation
    • Troubleshooting section

:wrench: How to update

If you installed via HACS:

  1. Open HACS in Home Assistant.
  2. Go to “Integrations” and find Orphan Cleaner.
  3. Click “Redownload” (or wait for the automatic update notification).
  4. Restart Home Assistant.

If you installed manually:

  1. Download the latest custom_components/orphan_cleaner/ folder from the GitHub repository.
  2. Replace your existing folder with the new one.
  3. Restart Home Assistant.

:memo: What’s next?

I’m planning to add:

  • More filtering options in the panel
  • Enhanced reporting with statistics
  • Integration with Home Assistant’s backup system
  • Optional configuration parameters in configuration.yaml (min_orphan_age_hours, aggressive_heuristic)

:speech_balloon: Feedback

I’d love to hear your thoughts! Try it out and let me know what you think. Any feedback, feature requests, or suggestions are highly appreciated.


Happy cleaning! :broom::sparkles:

Hi @chairstacker,

thank you for your comment! With the latest update, the integration still does not require any further configuration – simply adding orphan_cleaner: to your configuration.yaml is enough to load it.

What about min_orphan_age_hours and aggressive_heuristic?

These are planned as optional parameters in a future update. For now, you can use aggressive_heuristic directly in the service call:

service: orphan_cleaner.scan
data:
  aggressive_heuristic: true`

The integration works perfectly fine without any configuration – the defaults are sensible for most users.

Let me know if you have any further questions!

Best regards,
realsly

Hi @finity,

that’s a very valid question. With the latest updates, both integrations have evolved further. Let me clarify the current relationship and differences.

Relationship to francesco.beghi’s Integration

My integration was developed independently and has a different focus. Both are now more feature-rich, but they approach the problem differently.

Key differences (as of the latest update)

Feature My Orphan Cleaner francesco.beghi’s Integration
Sidebar Panel :white_check_mark: Full UI with search, filter, bulk selection :white_check_mark: Web panel with filter and log
Configuration Via configuration.yaml (mandatory to load) and UI Via UI (Settings → Devices & Services → Configure)
Detection Methods orphaned_timestamp, dead config entry, unavailable state, heuristic orphaned_timestamp, dead config entry, unavailable state, heuristic
Service: scan :white_check_mark: Fires event orphan_cleaner_orphans_found :white_check_mark: Fires event orphan_cleaner_orphans_found
Service: delete_orphans :white_check_mark: With entity_ids or all, plus dry_run :white_check_mark: With entity_ids or all, plus dry_run
Allowlist :white_check_mark: In services.py (customizable) :cross_mark: Not available
Backup :white_check_mark: Automatic JSON backup :cross_mark: Not mentioned
Dry-Run :white_check_mark: Via service or UI :white_check_mark: Via service
UI Installation :white_check_mark: Manual YAML or HACS :white_check_mark: Via UI (Add Integration)

In short

Both integrations solve the same problem, but with different trade-offs:

  • My integration focuses on flexibility and safety – you configure it via YAML (if needed), it has a customizable allowlist, and it creates automatic backups before deletion.
  • francesco.beghi’s integration focuses on UI-driven configuration – you can set everything via the Home Assistant UI, which is more accessible for less technical users.

I respect francesco.beghi’s work – it’s well done and clearly addresses the same need. I believe both integrations can coexist, and users can choose based on their preference for YAML vs. UI configuration, and the specific safety features they value.

Let me know if you have more questions!

Best regards,
realsly

1 Like

I do always like a yaml config over strictly UI for many (if not most) things.

I’ll give yours a try too.

:new_button: New Configuration Options in the UI

Hi everyone,

I’ve just released an update that adds two new configuration options to the Orphan Cleaner integration. You can now customize the detection behavior directly in the UI – no need to edit your configuration.yaml!


:memo: New Configuration Parameters

You can find these settings by going to:
Settings → Devices & Services → Orphan Cleaner → Configure

1. min_orphan_age_hours (default: 24)

  • What it does: Filters out entities that are too recent. Only entities that have been unavailable for longer than this period are considered orphaned.
  • Why it’s useful: Prevents false positives when an integration is temporarily offline or a device is restarting.
  • Valid range: 1 to 720 hours (1 hour to 30 days).

2. aggressive_heuristic (default: false)

  • What it does: When enabled, the integration also considers entities with no config_entry_id and a platform that is not in the exclusion list (e.g., template, input_boolean, group, zone, person, etc.) as orphans.
  • Why it’s useful: Helps detect entities that may have been left behind by custom integrations or manual setups.

:wrench: How to Update

If you installed via HACS:

  1. Open HACS in Home Assistant.
  2. Go to “Integrations” and find Orphan Cleaner.
  3. Click “Redownload” (or wait for the automatic update notification).
  4. Restart Home Assistant.

If you installed manually:

  1. Download the latest custom_components/orphan_cleaner/ folder from the GitHub repository.
  2. Replace your existing folder with the new one.
  3. Restart Home Assistant.

:bar_chart: How to Configure

  1. Go to Settings → Devices & Services.
  2. Find Orphan Cleaner in the list.
  3. Click “Configure”.
  4. Adjust the sliders and toggles as needed.
  5. Click “Submit”.

The new settings will take effect immediately – no restart required!


:test_tube: Testing the New Features

You can also override these settings per service call:


service: orphan_cleaner.scan
data:
  aggressive_heuristic: true 

This allows you to test the heuristic mode without enabling it permanently.

So, this is the 2nd time I tried to install this Custom Integration and it’s the 2nd time I’m getting an error with no hint on how to fix it - even after a HA restart that wasn’t supposed to be required:

image

Why is ever entity I WOULD delete not able to be selectable? The wyze cam isn’t in use anymore but I can’t delete two associated entries and it’s shown a pending_delete_by_ha through multiple restarts. It alsi seens to consider all my broadlink integration buttons and switches created through scripts as no config or device.

Orphan Entity Cleaner — v1.1.2 Changelog

Improvements

  • Tightened admin permission checks across the panel and backup/restore services
  • Backup files now use safer, more consistent filenames with atomic writes to prevent corruption
  • Backup timestamp parsing improved for more reliable restore selection
  • Entity links in the panel are now styled white for better readability

Maintenance

  • Various lint/type fixes (flake8, mypy) and test coverage updates for the new admin checks

As always, back up your Home Assistant config before updating. Feedback and issues welcome!

Appears to be broken, it is removed upon reboot of HA!!!