Id substitution

I am working on a ESPHome project, and using substitutions to name the entities in HA to match the project. I plan on having 3 of the same modules, so mapping entity_id to a board is important.

This is what I have at the top:

substitutions:
  project: Gallery Door Controller
  id: gallery-door-controller
  id_name: gallery_door_controller

Then for the entity, this is the example:

switch:
  #Include restart button
  - !include common/switches/restart.yaml
  - platform: gpio
    name: 'Relay 1'
    id: '${id_name}_relay1'
    pin: GPIO16
    inverted: true
  - platform: gpio
    name: 'Relay 2'
    id: '${id_name}_relay2'
    pin: GPIO17
    inverted: true

In HA, I see this:
image

So the switch is not named.

Caveat, I created the project without the ${id_name} first. Installed, made sure functions and basics work, then added the substitution.

Should I expect the new version to update the entity IDs? Or do I need to delete the existing device and add it again?

Delete Home Assistant device (not ESPHome) and add it again. Then entity_id will be chaged.
In general this is safe way when id/name changed.

I deleted the device from the ESPHome integration.
Confirmed the device is no longer in the Devices list under settings.

Reset device, got detected again in ESPHome, Configured it, got added back to ESPHome integration.

Still no change to the entity_id’s.

It’s the name that gets used as entity_id in HA - converted to lower case and spaces replaced with underscore. The IDs are used only within ESPHome and are not translated to Home Assistant’s Entity ID.

  - platform: gpio
    name: '${id_name} Relay 2'
    id: 'relay2'
    pin: GPIO17
    inverted: true

Would give you the following in HA:

switch.gallery_door_controller_relay_2

It would probably be better to use friendly_name option though.

1 Like

That was not what was suggested: you can leave the device in esphome but you need to remove it from the integrations page in HA and have HA detect it as a new device. Because you didn’t delete it in HA, the old names are kept.

Trying to clarify.
When you say integration, you mean here? Delete it from where it says ESPHome?
image

EDIT: it is one of the 14 devices, so when I went in, I deleted it from there.

That did it.

Update a friendly_name, and it updated the entities like I want once I removed and added the project from the ESPHome integration. Thanks.

1 Like