Is unique_id universal in YAML configuration? How can I force one if not?

In order to configure HA, I use a mix of configuration.yaml and the GUI (that writes its magic to .storage).

In the GUI some of the entities are not ediatble because “they do not have a unique ID”. Fair enough, I tried:

binary_sensor:
  - platform: ping
    host: 8.8.8.8
    name: ping_google
    count: 5
    scan_interval: 60
    unique_id: 8d45d1aa-b0d9-4087-81d4-49d08a4c459e

This raises an error when restarting HA, unique_id is apparently not supported there.

So how can I have a unique ID for such an entry if it is not accepted in configuration.yaml?

In contrast,

sensor:
  - platform: template
    sensors:
      ping_google:
        friendly_name: "google"
        unit_of_measurement: "ms"
        value_template: "{{ state_attr('binary_sensor.google', 'round_trip_time_avg') }}"
        unique_id: daf3ff7b-2741-41c3-b235-f2d27613e9f6

was accepted without problems and is now configurable in the GUI

It’s simple, if it’s not inplemented in the integration, you can’t do it. The dev of the integration needs to implement unique_id, you can’t force it.

1 Like

Thank you.

I had a look at the 32 instances of CONF_UNIQUE_ID across the components code. For many of them, it seems that they just from homeassistant.const import CONF_UNIQUE_ID (among others), and then declare it as optional in the extension of the platform schema. It looks like it is not used afterwards.

Is this the minimal implementation for unique_id?

I understand that it can be set to a specific value (a serial number for instance, like for the hue component), or reused afterwards - I am just wondering whether merely importing it and adding to the extension of the platform is enough to have HA recognize it (and make efficient use of it by unlocking the GUI edition, maintaining it in .storage etc.)

I don’t know, I’m not a dev :slight_smile: I assume there might be more in order that the integration doesn’t assign an already used unique_id. To be honest I don’t care so much, I don’t need to be able a binary_sensor or similar in the UI when I can do it in YAML.

1 Like

Yes, this is true but this dualism between the YAML and the UI is messy. I would prefer to keep the elements clearly separated: either here or there.

A nice milestone (before having a separation) would be to have a unique_id available in the YAML, and make the whole configuration in the UI. Today for instance I can add a input_boolean both in the YAML and in the UI. They both meet as “entities” but keeping track which is where is not optimal.

2 Likes