Using substitutions in name:

I have several similar devices to deploy and substitutions are clearly going to make things simpler as there are 50 'names in each. However, I can’t determine from the docs just how substitutions can be used in name:.

If I have the following, for example:

  - platform: total_daily_energy
    name: "Garage Total Daily Energy"
    power_id: garage_total_power
    accuracy_decimals: 0

and use substitutions:

substitutions:
  area_id: garage
  area_name: Garage

would I then use it as:

  - platform: total_daily_energy
    name: "${area_name} Total Daily Energy"
    power_id: ${area_id}_total_power
    accuracy_decimals: 0

or is some form of concatenation required? (I have no expectation that the example below is correct!)

  - platform: total_daily_energy
    name: "${area_name}" + "Total Daily Energy"
    power_id: ${area_id} + _total_power
    accuracy_decimals: 0

or similar.

Hope that makes sense.

@ashscott

Here is an example from my YAML:

substitutions:
  devicename: esp17

button:
  - platform: restart
    name: '${devicename} Restart'
    internal: false

display:
  platform: lilygo_t5_47
  id: '${devicename}_display'
  update_interval: never

The substitution is exact - it just gets swapped out when the YAML gets compiled.

Thank you.

So, in this case, button shows up in HA as ‘esp17 Restart’?

Have I got that correct?

Are the single quotes key or does it also work with doubles?

It does show up with an Entity ID of button.esp17_restart with a name of “esp17 Restart”

I run everything in esphome and Home Assistant through a YAML validator - it tends to like single quotes. But I think double quotes are okay (it validates).

Or you can switch to:

- platform: total_daily_energy
  name: '${area_name} Total Daily Energy'
  power_id: '${area_id}_total_power'
  accuracy_decimals: 0