Template documentation regarding unique_id feature is unclear or outdated

Just started using HA and I am confused by this section of the “Template” integration documentation which states:

The unique ID for this config block. This will be prefixed to all unique IDs of all entities in this block.

Further in the documentation is also this section:

unique_id string (optional)
An ID that uniquely identifies this entity. Will be combined with the unique ID of the configuration block if available. This allows changing the name, icon and entity_id from the web interface.

There is no example in the docs showing the usage of this “config-block” level unique_id.

Is someone able to provide a working example of their configuration.yaml that utilizes this option?

Most of my attempts to add this config-block-level unique_id causes HA to throw .yaml config errors. The following configuration.yaml is accepted by HA; but HA is not prefixing the unique_id:
(I’ll get to how I’m able to confirm the unique_ids later)

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

# Text-to-speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

logger:
  default: info
  logs:
    custom_components.hacs: debug
    aiogithubapi: debug

## customizations ##

#enable python scripts
python_script:

template: !include_dir_merge_list customizations/templates/

sensor: !include_dir_merge_list customizations/sensors_legacy/

customization/templates/valetudo.yaml:

# for custom valetudo controls
  - unique_id: "ignored_prefix_"
  - sensor:
    - name: "selected_segments"
      unique_id: valetudo_sel_seg
      state: "uninitialized"
  - sensor:
    - name: "remaining_segments"
      unique_id: valetudo_rem_seg
      state: "uninitialized"
  - binary_sensor:
    - name: "vacuum_is_lost"
      unique_id: valetudo_is_lost
      state: "off"

Per the documentation, my understanding is that sensor.selected_segments should have the full unique_id of: ignored_prefix_valetudo_sel_seg, however, no amount of reloading/deleting/re-adding .yaml files and restarting HA seems to create the proper unique_id.

Any help from the community is, as always, greatly appreciated.

I suggest you spend time learning yaml. The docs explain how to write yaml… if you understand yaml.

- unique_id: ignored_prefix_
  sensor:
    - name: "selected_segments"
      unique_id: valetudo_sel_seg
    - name: "remaining_segments"
      unique_id: valetudo_rem_seg
      state: "uninitialized"
  binary_sensor:
    - name: "vacuum_is_lost"
      unique_id: valetudo_is_lost
      state: "off"

The closest example in the docs that cover this is the 3rd one here

or this one

They are just missing unique_id, which would simply be

- trigger:
    ...
  sensor:
    ...
  binary_sensor:
    ...
  unique_id: ...
2 Likes

Is it possible to have a “config-block-level” unique_id for a group of state-based template sensors?