How is "friendly_name" supposed to behave?

So I’ve been adding the “friendly_name” option into my configurations so I can try to pass a better name over to Home Assistant but it’s behaving in a very strange manner and I can’t seem to get things to act the way I want.

Ultimately, it looks like when you add the friendly name into the configuration I can see it’s being automatically prefixed to the entity name in Home Assistant and it is also added to the entity ID itself.

For example, when I have:

esphome:
  name: ${device_name}
  friendly_name: ${friendly_name}

and then I have a binary sensor as follows:

binary_sensor:
- platform: template
  name: ${friendly_name} Single Click
  id: ${ha_name}_single_click

Home Assistant names with an additional prefix so it looks like

${friendly_name} ${friendly_name} Single Click

and it has the entity ID prefixed as

binary_sensor.${friendly_name}_single_click

but if I change things to exclude the friendly name from the sensor:

binary_sensor:
- platform: template
  name: Single Click
  id: ${ha_name}_single_click

Then the friendly name isn’t double prefixed in the sensor’s name but it also means that the entity ID itself loses the friendly name. What this means is that things look like this:

{friendly_name} Single Click

and the sensor has no prefix.

binary_sensor.single_click

Ultimately I would like the friendly name to prefix the entity name ONCE and the entity ID. Is there something that I’m missing? How is “friendly name” supposed to behave? The docs are pretty general:

friendly_name (Optional, string): This name is sent to the frontends. It is used by Home Assistant as the integration name, device name, and is automatically prefixed to entities where necessary.

I’ve ruined all of my entities and names for the time being so it would be nice to get this fixed :slight_smile:

3 Likes

Post the YAML code.

OK, here is a reasonably simple example

#Sonoff S31 Lite

substitutions:
  device_name: bedroom-fan #change
  friendly_name: Bedroom Fan #change
  comment: Sonoff S31 Lite | IP 192.168.30.184
  icon: "mdi:fan"

esphome:
  name: ${device_name}
  friendly_name: ${friendly_name}
  comment: ${comment}

esp8266:
  board: esp01_1m

wifi:
  ssid: !secret wifi_NoT_ssid
  password: !secret wifi_NoT_password
  fast_connect: true
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ${device_name}
    password: !secret wifi_ap_password

captive_portal:

# Enable logging
logger:
  baud_rate: 0  # (UART logging interferes with cse7766)

# Enable Home Assistant API
api:
  encryption: 
    key: !secret esp_home_api_encryption

ota:

time:
  - platform: homeassistant
    id: homeassistant_time

uart:
  rx_pin: RX
  baud_rate: 4800

binary_sensor:
  - platform: gpio
    id: button
    internal: true
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    on_press:
      - switch.toggle: relay
  - platform: status
    name: Status

switch:
  - platform: gpio
    name: ${friendly_name}
    icon: ${icon}
    pin: GPIO12
    id: relay

  - platform: restart
    name: Reboot

  - platform: safe_mode
    name: Safe Mode

status_led:
  pin:
    number: 13
    mode: OUTPUT
    inverted: true

sensor:
  - platform: wifi_signal
    name: WiFi Signal
    update_interval: 60s 

In this instance my device name is “Bedroom Fan” (as expected) as my Reboot and Safe Mode switches are named “Bedroom Fan Reboot” and “Bedroom Fan Safe Mode” with entity ids that look like this:

switch.bedroom_fan_reboot
switch.bedroom_fan_safe_mode

BUT the actual fan relay is named “Bedroom Fan Bedroom Fan” and the entity id is:

switch.bedroom_fan_bedroom_fan

I tried removing the name from the switch platform but then the switch doesn’t seem to show up at all. I’ve tried totally deleting these devices from HA and then readding them and things are still messed up.

I think this might be a bug.

It looks like if you have a value in “name” then the system is just prefixing it with friendly name (which is fine). The problem is when you want to have your “name” be the friendly name then you’ll get the friendly name twice.

If you leave name blank in an attempt to just have the single friendly name as the name then the system won’t give it a name at all and the entity won’t show up.

Further to this, I think there might be a bug in the template binary sensors wherein the entity ID is not correctly prefixed when using a friendly name. It works on the entity name but the entity ID loses the prefix.

For your switch, you have named it {friendly_name}. But your device friendly_name gets prepended, like the docs say.

For reboot, you have named it reboot, and friendly_name is prepended.

Yes, but ultimately there are two issues.

  1. I don’t believe there is a way to name a component the friendly name. As the friendly name is always prepended if you try to name the component the friendly name you will get duplicates.

  2. As mentioned in my first post, when the friendly name is automatically prefixed the entity ID didn’t get prefixed. I think this might just be for template sensors but I haven’t fully confirmed that yet.

I think for 1. You need to choose your names better.eg in this case call it ‘on off’

I don’t want to add “on off”.

I want it to be called “Bedroom Switch” or whatever the device is. That fact that it is a binary switch make the “one off” implicit.

Regardless, I filed a github and have been told it’s a known issue without a known solution at this time.

Really the bigger issue is #2. If the system prefixes the name then it should also prefix the entity ID and it doesn’t. What this means is that I either have to have the double prefix in the name and single in the entity ID or I have to have the single in the name and no prefix in the entity ID.

Without the prefix in the ID you get horrible entity ID names.

1 Like

I agree, this with auto-prefix is a total mess… i would also like, say friendly name to be “bedroom Light” and not just “Light”. Now there are two options, if, say, “friendly_name” is “bedroom”:
1: friendly name of sensor is just “light” and id is “sensor.bedroom_light”
2: friendly name of sensor is “Bedroom light”, but then id is “sensor.bedroom_bedroom_light”.

Only temporary solution is NOT to defince friendly_name at all (in esphome section)…

1 Like

Agreed, I’ve rolled my configs back until this makes more sense. The biggest problem is the bug wherein there are times that the entity ID doesn’t get a prefix at all.

There are some “weird” decisions from NabuCasa stuff regarding esphome in general lately… that annoying and needless update warnings, this incomplete name adding… i wonder what’s happening…?
First thing that should be available is a flag like “add_name_suffix” or similar…=true/false - for user to decide if he/she wants name to be added at all. No need to force something.

1 Like

Agreed, it’s nice to have things seem like magic but when they don’t work it really sucks.

4 Likes

I am going to print and frame this to hang on the wall of my server room.

5 Likes

Ha ha ha. Glad to help.

To use the Friendly Name as the complete id (i.e. sensor.${friendly_name}) set :

name: none

(source: esphome docs)

1 Like

Yeah, that’s a new feature that wasn’t present when I asked originally.

Found this very useful discussion except the conclusion doesn’t seem to generally work, for example with a light set to name: none the name is still doubled. If I do a validate it shows as name with an empty string (not the word none, also not None I tried both cases) and the entity ID comes through (in my case) as entity_id.flood1_flood1 and same for the name “Flood1 Flood1”. Am I missing something?

1 Like

This has been an issue for me as well. name: None is expanded to name: '' as soon as the config is parsed and validated and I’m seeing device name duplication in the entity id (e.g. switch.bathroom_bathroom).

There’s also an open ESPHome issue: empty ('') component name being replaced with device_name · Issue #4848 · esphome/issues · GitHub

2 Likes

Ive been dealing with this same issue and opened a feature request here: Add option to remove the prefixing of "friendly_name" since this affects the voice assistant · Issue #2476 · esphome/feature-requests · GitHub.
In my case, I use the friendly name to organize my nodes on the EspHome dashboard, but most of my nodes have multiple entities that are not necessarily related to the node name.
I have a couple of examples on the github request above.
The name prefix should be an option and not be forced.