DISCLAIMER: Use at your own risk! It has worked for me, it might not work for you, or even worse screw your system or eat your favorite pet.
Pull Requests, Bug Reports and Thank You are welcome and appreciated.
Devices can be renamed outside of Home Assistant. When this happens, the integration does not propagate that change to Home Assistant, i.e., the entity_id
is not changed. This makes sense to not break automations etc.
On the other hand, that causes names outside and inside of Home Assistant to diverge over time. See this feature request for concrete user stories.
Unfortunately, Home Assistant lacks a functionality to re-acquire the current names from the integrations.
Some forum ports that are related to the problem:
- Feature Request (please vote!): Reset / Re-acquire entity_id
- Question: Reset Hue entity ids?
- Question: Reset entity_id after name change
- Question: Rename entity_id for script any solutions?
- Question: Rename an Entity ID
- Remove all entities from file
core.entity_registry
whereplatform
matches. - Remove the same entities from file
core.restore_state
, if existing. - Remove the devices with matching
id
from filecore.device_registry
.
First of all, stop Home Assistant. To my experience, the integration/platform does not need to be removed.
Backup your configuration directory. The script does not do backups.
Run, e.g.
ha-prune.py --path homeassistant-config prune --platform hue
Use --dry-run
or -n
to not actually write anything to disk.
Restart Home Assistant. The entities should be automatically re-discovered under their new name (i.e. the names obtained from the integration).
The command:
ha-prune.py --path homeassistant-config save "out.json"
saves the friendly names, if set, for all entities. It produces a file like:
{
"switch.horus": "Horus",
"sensor.sentinel_1_air_temperature": "Flur",
"device_tracker.thermostat_wohnzimmer": "Thermostat Wohnzimmer",
"switch.janus_1": "Heizlüfter",
}
vice versa
ha-prune.py --path homeassistant-config restore out.json
restores the friendly names, if modified.
IDs like
device_id: c42cc5888a0c7349d8425023efdedac7
entity_id: 28b1c57400b2c8bc5930b8889505edcb
seem to be unstable when devices are re-discovered. Use entity_id
like light.kitchen
in your automations etc.