Control the device_id property for maximum flexibility - is it possible?

I’ve recently switched to Zigbee2MQTT from ZHA. So far so good. However, I’m wondering whether I can make my setup more durable.

I noticed that when a device first joins, an entry like this shows up in my zigbee2mqtt configuration.yaml:

devices:
  '0x001788010915XXXX':
    friendly_name: '0x001788010915XXXX'

If after the device joins I change friendly_name to say Phillips Hue Bulb, I can see in HA that its name was updated to Phillips Hue Bulb; however, references to this device’s entities remian with the old ID:

light.0x001788010915XXXX

I can change these entities manually, but that is quite a labor. I then noticed something else. I unpaired the device, and made sure I have the following in my Z2M’s configuration.yaml:

devices:
  '0x001788010915XXXX':
    friendly_name: 'phillips_hue_bedroom_1'

Now when I re-paired the device, it was given a nice ID, and the same applies to its entities:

light.phillips_hue_bedroom_1
sensor.phillips_hue_bedroom_1_linkquality
etc...

Why do I want this?

Suppose tomorrow my database gets corrupted or [[insert apocalyptic scenario here]]. If everything, including entity IDs, is predefined in YAML files which are backed up - I can seemingly get everything up and running pretty quickly again, including automations (which rely on entity_id and sometimes device_id).

Is this kind of configuration possible?

If you use Z2M’s UI to rename it, and enable the option to rename the HA entity_id, you’ll get what you’re looking for.

If you have the hardware that is capable, have you considered running home assistant as a virtual machine. You can then backup the entire machine if an apocalyptic event occurs. I store a backup of my virtual machine on an off the network backup drive. Then it does not matter what they are named. You reinstall the VM and life is good.

Thanks. But having a backup (which is a good practice regardless) is not the same as having a declarative setup.

I will respectfully disagree with you in this case. Backing up the VM is like having a backup from a raid drive. It is as if you cloned a hard drive and can swap. All software and configuration remains intact.

Thanks Tinkerer. Do you know if something similar is achievable with other HA integrations? For example giving all Shellys IDs in YAML, etc…?

Entirely depends on the integration, and requires them to support YAML configuration. If they do, it’ll be explained in the docs for it.