MQTT Binary Sensor Entity Names

I have an irrigation controller that integrates with MQTT (it does not use MQTT discovery).

I would like to name my entities ‘binary_sensor.irrigation.’ - but HA seems to simply derive the entity name from the ‘name:’ field in the config resulting in “binary_sensor.veggie_garden”. The “name” field in the config seems to map to the “friendly_name” field in the UI. I’ve tried using “unique_id” but that does not seem to influence the entity name.

How do I set the entity name and friendly name?

Current config:

- platform: mqtt
  state_topic: "irrigation/mcsSprinklers/state/VeggieGarden"
  name: "Veggie Garden"
  icon: hass:flower
  unique_id: "irrigation.veggie_garden"

Results in this:

You set the entity_id using the name in the mqtt config. Then use Customize to add a friendly name. Keep in mind that friendly_names can be duplicated but entity_ids (and thus names in a domain) must be unique. So if you have two names (not friendly_names) that are the same then _2 will be appended to the entity_id.

I did something similar with some of my template sensors when I changed them to use the new format as I did not want to have to bother changing the entity ids in all my automations and scripts and I wanted the same name displayed in Lovelace (where I could have changed it too btw), e.g.

template_sensors.yaml

- name: "zone_1_time_remaining" # Customized as, friendly_name: Time Remaining
  icon: "mdi:timelapse"
  unit_of_measurement: "min"
  state: >
    {% if is_state('switch.zone_1', 'on') %}
      {{ [ (states('input_number.zone_1_run_time')|int(0) - (as_timestamp(now()) - as_timestamp(states.switch.zone_1.last_changed))/60)|round(0) ,0 ]|max }}
    {% else %}
      0
    {% endif %}

- name: "zone_2_time_remaining" # Customized as, friendly_name: Time Remaining
  icon: "mdi:timelapse"
  unit_of_measurement: "min"
  state: >
    {% if is_state('switch.zone_2', 'on') %}
      {{ [ (states('input_number.zone_2_run_time')|int(0) - (as_timestamp(now()) - as_timestamp(states.switch.zone_2.last_changed))/60)|round(0) ,0 ]|max }}
    {% else %}
      0
    {% endif %}

- name: "zone_3_time_remaining" # Customized as, friendly_name: Time Remaining
  icon: "mdi:timelapse"
  unit_of_measurement: "min"
  state: >
    {% if is_state('switch.zone_3', 'on') %}
      {{ [ (states('input_number.zone_3_run_time')|int(0) - (as_timestamp(now()) - as_timestamp(states.switch.zone_3.last_changed))/60 )|round(0) ,0 ]|max }}
    {% else %}
      0
    {% endif %}

customize.yaml

sensor.zone_1_time_remaining:
  friendly_name: 'Time Remaining'
sensor.zone_2_time_remaining:
  friendly_name: 'Time Remaining'
sensor.zone_3_time_remaining:
  friendly_name: 'Time Remaining'
1 Like

I ended up finding the “entity_namespace” field. This prefixed all of my entities with the entity namespace before adding the name:

- platform: mqtt
  state_topic: "irrigation/mcsSprinklers/state/VeggieGarden"
  entity_namespace: "irrigation"
  name: "Veggie Garden"
  icon: hass:flower

resulted in binary_sensor.irrigation_veggie_garden

That’s the entity id. You originally asked about names :thinking:

You’re right Tom, I’m new to HA and got my terminology confused.

I would like to name my entities ‘binary_sensor.irrigation.’

Your assistance pointed me in the right direction and I also dicovered the difference between entity-id and unique_id.

Using the namespace allows me to use regex / wildcards in lovelace which makes life much easier.

Thank you @tom_l, I came here looking for a solution to this issue of not being able to give a friendly name to mqtt entities and your trick using customize.yaml works!!

@beerygaz can you please mark @tom_l answer as the solution of your question so people can quickly see it when they visit this post?