Setting Names in Templates and MQTT

Hey guys,

it might be a stupid question but i am having issues setting “names” and “friendly names” in HA.

I am about to get my template and MQTT sensors out of my main configuration.yaml by using mqtt.yaml and template.yaml. I wanted to “pretty up” the sensors while i was at it… The main goal was to get a sensor name like sensor.livingroom_us_adjust_temp with a corresponding fiendly_name of Eingestellte Temperatur Wohnzimmer. For this i tried it this way:

#### Auslesen Temperatur Wohnzimmer ######################################
  - name: Eingestellte Temperatur Wohnzimmer
    unique_id: livingroom_us_adjust_temp
    unit_of_measurement: °C
    device_class: temperature
    state: "{{ state_attr('climate.livingroom_us_radiator', 'current_heating_setpoint')}}"

The result of this is:

Is it just not possible to do it as i want or am i going at it the wrong way?
The Main reason for this would be, that i wanted clean “unique” names but still use the german words for friendly use.

Thank you in advance for any suggestions.

regards,
Markus

It’s possible but is a PITA.

The entity id will be created from the slugified name. So

name: Eingestellte Temperatur Wohnzimmer

Will produce:

sensor.eingestellte_temperatur_wohnzimmer

To do what you want you have to set the name to the entity_id you want:

  - name:  livingroom_us_adjust_temp

Which will produce sensor.sensor.livingroom_us_adjust_temp with an unwanted name of “livingroom_us_adjust_temp”.

Then using customise set the friendly name you want:

configuration.yaml

homeassistant:
  customize: !include customize.yaml

customize.yaml

sensor.livingroom_us_adjust_temp:
  friendly_name: Eingestellte Temperatur Wohnzimmer

Where I did this (due to entity_id backwards compatibility when moving to the new template format) I included a comment in the sensor to remind future me, e.g.

template_sensors.yaml

- name: "bathroom_pre_heat_time_remaining" # Customized as, friendly_name: Time Remaining
  unique_id: 66839a51-c4b0-4382-9b06-9edde634d967
  icon: "mdi:timelapse"
  unit_of_measurement: "min"
  state: >
    {% if is_state('switch.all_bathroom_heaters', 'on') %}
      {{ [ (states('input_number.bathroom_pre_heat_run_time')|int(0) - (as_timestamp(now()) - as_timestamp(states.switch.all_bathroom_heaters.last_changed))/60)|round(0, default = none) ,0 ]|max }}
    {% else %}
      0
    {% endif %}

- name: "ensuite_pre_heat_time_remaining" # Customized as, friendly_name: Time Remaining
  unique_id: c57d903e-2967-42ca-be44-4ffeae5ed3e6
  icon: "mdi:timelapse"
  unit_of_measurement: "min"
  state: >
    {% if is_state('switch.all_ensuite_heaters', 'on') %}
      {{ [ (states('input_number.ensuite_pre_heat_run_time')|int(0) - (as_timestamp(now()) - as_timestamp(states.switch.all_ensuite_heaters.last_changed))/60)|round(0, default = none) ,0 ]|max }}
    {% else %}
      0
    {% endif %}

That did the trick!
Thank you so much for the detailed description!

1 Like