A professional Home Assistant custom integration for automated management of obsolete entities with ESPHome-style user controls.
✅ Automated Obsolete Detection - Automatically scans for entities without backing devices or integrations
✅ Safe Cleanup - Backup entities before cleanup with full restore capability
✅ User-Friendly Controls - ESPHome-style template switches and buttons for direct interaction
✅ Device Grouping - All entities grouped under a single "Entity Janitor" device with custom icon
✅ Professional Terminology - Uses "obsolete" instead of "orphan" throughout the interface
✅ Configurable Filtering - Exclude specific domains and entities from cleanup
✅ Dry Run Mode - Preview what would be cleaned without making changes
✅ Template Controls - Interactive switches and buttons for monitoring and control
✅ Service Integration - Comprehensive services for automation and scripting
✅ Age-Based Filtering - Only clean entities older than specified days
✅ Detailed Logging - Complete audit trail of all cleanup operations
- Open HACS in Home Assistant
- Go to "Integrations"
- Click the 3-dot menu → "Custom repositories"
- Add repository URL:
https://github.com/Jacid23/entity-janitor - Category: Integration
- Click "Add"
- Find "Entity Janitor" in HACS and click "Download"
- Restart Home Assistant
- Add the integration: Settings → Devices & Services → Add Integration → "Entity Janitor"
- Download the latest release from GitHub releases
- Extract the downloaded ZIP file
- Copy the integration files to your
custom_componentsdirectory:- If files are in
custom_components/entity_janitor/, copy that folder - If files are in the root, create a new folder called
entity_janitorin yourcustom_componentsdirectory and copy all files there
- If files are in
- Copy
www/entity_janitor/icon.svgto yourwww/entity_janitor/directory for the device icon - Your final structure should be:
custom_components/entity_janitor/manifest.json - Restart Home Assistant
- Add the integration via Settings → Devices & Services → Add Integration
Configure Entity Janitor through the Home Assistant UI:
- Go to Settings → Devices & Services → Add Integration
- Search for "Entity Janitor"
- Configure your preferences:
- Auto Scan: Enable automatic periodic scanning
- Scan Interval: How often to scan (15-1440 minutes)
- Auto Clean: Enable automatic cleanup (requires backup)
- Backup Before Clean: Create backups before cleanup (recommended)
- Minimum Age: Only clean entities older than X days
- Dry Run: Preview mode without actual cleanup
All Entity Janitor entities are grouped under a single device with a custom icon. The device includes:
sensor.entity_janitor_obsolete_count: Number of obsolete entities foundsensor.entity_janitor_total_entities: Total entities in registrysensor.entity_janitor_last_scan: Last scan timestamp
switch.entity_janitor_backup_before_clean: Enable/disable automatic backupsswitch.entity_janitor_dry_run_mode: Enable/disable dry run modeswitch.entity_janitor_notifications: Enable/disable notificationsswitch.entity_janitor_detailed_logging: Enable/disable detailed logging
button.entity_janitor_quick_scan: Trigger manual scan for obsolete entitiesbutton.entity_janitor_full_cleanup: Perform full cleanup of obsolete entitiesbutton.entity_janitor_export_report: Export scan results to filebutton.entity_janitor_reset_statistics: Reset scan statistics
button.entity_janitor_scan_obsolete: Trigger manual scanbutton.entity_janitor_clean_obsolete_dry_run: Preview cleanupbutton.entity_janitor_backup_obsolete: Create backup
Scan for obsolete entities.
Clean obsolete entities.
service: entity_janitor.clean_obsolete
data:
entity_ids: [] # Optional: specific entities to clean
dry_run: true # Optional: preview mode
backup_before_clean: true # Optional: create backupBackup obsolete entities.
service: entity_janitor.backup_entities
data:
entity_ids: [] # Optional: specific entities to backupThe integration identifies obsolete entities by checking:
- Missing Devices: Entities linked to non-existent devices
- Missing Config Entries: Entities with invalid configuration entries
- Unloaded Integrations: Entities from disabled/removed integrations
- Stale Entities: Entities without active state
- Dry Run Mode: Preview changes before applying
- Automatic Backups: JSON backups before cleanup
- Age Filtering: Only remove entities older than specified days
- Domain Exclusions: Skip critical entity types
- Entity Exclusions: Protect specific entities
- Template Controls: User-friendly switches and buttons for safe operation
The Entity Janitor device features a custom icon that combines:
- Broom: Represents cleaning/janitor functionality
- Database elements: Represents entity management
- Sparkles: Represents the optimization process
- Professional colors: Blue theme for a clean, professional look
Backups are saved as JSON files in your Home Assistant configuration directory:
entity_janitor_backup_YYYYMMDD_HHMMSS.json
Each backup contains:
- Timestamp
- Entity details (ID, domain, platform, etc.)
- Cleanup reason
- Total count
The integration fires events for automation:
entity_janitor_obsolete_found: When obsolete entities are detectedentity_janitor_cleanup_complete: When cleanup finishesentity_janitor_scan_complete: When scan completes
The template switches and buttons work like ESPHome entities:
- Toggle directly in Home Assistant UI
- Use in automations for conditional logic
- Monitor state for dashboard displays
- Press to trigger actions immediately
- Use in scripts for batch operations
- Monitor last pressed for automation triggers
Example automation:
automation:
- alias: "Weekly Entity Cleanup"
trigger:
- platform: time
at: "02:00:00"
condition:
- condition: time
weekday:
- sun
action:
- service: button.press
target:
entity_id: button.entity_janitor_quick_scan
- delay: "00:01:00"
- service: button.press
target:
entity_id: button.entity_janitor_full_cleanup- Import Errors: Ensure Home Assistant is version 2023.1 or newer
- Permission Errors: Check file system permissions for backup directory
- Memory Issues: Large entity registries may need patience during scans
- Device Icon Missing: Ensure
www/entity_janitor/icon.svgis copied correctly - Template Controls Not Working: Verify integration is properly configured
Enable debug logging:
logger:
logs:
custom_components.entity_janitor: debugIf issues persist:
- Remove integration from Settings → Devices & Services
- Restart Home Assistant
- Re-add the integration
- Professional Terminology: Changed "orphan" to "obsolete" throughout
- ESPHome-Style Controls: Added template switches and buttons
- Device Grouping: All entities grouped under single device
- Custom Icon: Added professional device icon
- Improved Safety: Enhanced backup and dry-run capabilities
- Better UX: User-friendly controls and terminology
This integration is designed to be safe and conservative. Always test in a development environment first.
- Clone the repository
- Install development dependencies
- Run tests before submitting PRs
- Follow the coding standards
Please include:
- Home Assistant version
- Entity Janitor version
- Relevant logs
- Steps to reproduce
This custom integration is provided as-is under the MIT License for educational and utility purposes.
- GitHub Issues: Report bugs and feature requests
- GitHub Discussions: Ask questions and share experiences
- Home Assistant Community: Get help from the community