Using Codex to Clean Up Home Assistant Entities
Use Codex to compare Home Assistant entities with Proxmox, Docker, and repository references before removing stale Portainer and Glances entries.

Home Assistant keeps a record of every entity that an integration creates. Container rebuilds, retired services, and old device names can leave that record crowded long after the infrastructure changes.
I used Codex to audit my entity registry against the systems that own those entities. Home Assistant supplied registry and state data. Proxmox and Docker supplied the live infrastructure record. A repository search showed which names still appeared in dashboards or automations.
Start with proof
An unavailable entity can still matter. A host may be offline, an integration may have lost its connection, or a dashboard may still depend on the entity ID. I asked Codex to classify each candidate before making changes.
- Read the Home Assistant entity registry and current state.
- Compare container entities with current Proxmox guests and Docker containers.
- Search the Home Assistant repository for dashboard, automation, recorder, and logbook references.
- Remove candidates after each check agrees.
The first safe set contained 1,136 unavailable Portainer entities with hash-style container prefixes. None of those hashes matched a current Docker container ID. A second review found 650 stale Portainer and container entities that met the same test.
Deletion and migration need different checks
The Glances sensors needed a migration instead of deletion. One active Docker host still used an IP-based entity prefix while the other hosts used readable names. Codex checked all 77 active sensors for target-name conflicts before changing the prefix to sensor.docker17_*.
The bedroom kiosk needed a display-name change. Its existing entity IDs already appeared in automations, so I kept those IDs stable and changed the device label from Alarm Panel 1 to Bedroom Kiosk Tablet.
Keep useful history
Recorder and logbook had generated exclusion blocks for retired Portainer sensors. Codex rebuilt those blocks from the current registry and removed 408 stale lines. The aggregate Docker outage sensors, Repairs, and curated logbook events stayed in place because they answer a useful question: when did a Docker problem start, and how long did it last?
This retention choice also keeps raw container status chatter out of Home Assistant history. My Home Assistant and Tugtainer setup keeps update results and exception handling visible without treating each polling value as permanent history. The earlier MCP homelab article explains how Codex reaches the systems used for these checks.
Implementation references
The public repository shows the supporting configuration:
- Docker infrastructure monitoring and Portainer cleanup
- Normalized Glances-backed infrastructure sensors
- Recorder retention and exclusions and logbook display filters
Run a Home Assistant configuration check after repository changes. Read the renamed entities back from Home Assistant before removing their old names. Those two checks caught naming mistakes before they reached a restart.
Watch the cleanup
The video shows the Codex prompts, the classification decisions, and the validation results from the finished cleanup.

