Skip to content

ESPHome unique_id doubles when using dallas "hub" and index, homeassistant ignores doubled items #4771

Description

@KHit6

The problem

My setup tries to have multiple Dallas DS18B20 one-wire temperature sensors connected to an ESP32 module. Each sensor connects to one terminal GPIO and the DS18B20's build in addresses aren't used. Instead each sensor is defined with index=0 inside the yaml configuration file. With this setup I like to exchange sensors only knowing which pin the sensor must be connected to.
Initially when no sensor is connected I expect to see all my sensors in Homeassistant with an unknown value. But only the first sensor is shown, other sensors are ignored. And Homeassistant complained about this.

My ESP-module communicates with Homeassistant with help of the ESPHome-Api .

I investigated more with help of the connect.py example of aioesphomeapi. It shows more than one entity with an unique_id='dallas-0000000000000000'. My guess is that a doubled unique_id prevent Homeassistant from using that entity.

If I use "address=..." instead of using "index=0" in the yaml configuration everything goes like expected. But when using "address=..." I cannot exchange sensors easily.

The source code in dallas_component.cpp creates the unique_id from the DS18B20's address or 0, if no address is known. As the DS18B20's address is without any usage within Homeassistant I think it is allowed to generate a unique_id the same way as ESPHome does it for all other sensors.

So I modified inside the template file dallas_component.cpp the line
std::string DallasTemperatureSensor::unique_id() { return "dallas-" + str_lower_case(format_hex(this->address_)); }
to
std::string DallasTemperatureSensor::unique_id() { return ""; }

With this small change everything performed like expected.

Please let me know if I can provide more help.

Which version of ESPHome has the issue?

ESPHome 2023.7.0

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

Home Assistant 2023.8.1

What platform are you using?

ESP32

Board

nodemcu

Component causing the issue

dallas

Example YAML snippet

esphome:
  name: temperator
  friendly_name: "Temperator"
  platform: ESP32
  board: nodemcu-32s

# Enable logging
logger:

packages:
  ota: !include common/ota.yaml
  wifi: !include common/wifi.yaml

captive_portal:

switch:
  - platform: gpio
    pin: GPIO2
    inverted: False
    id: ledblue
    name: "Blue LED"

binary_sensor:
  - platform: gpio
    id: buttonboot
    name: "Button"
    pin:
      number: GPIO0
      inverted: True
      mode: INPUT_PULLUP
    on_press:
      then:
        - switch.toggle: ledblue
        - delay: 3s
        - switch.turn_off: ledblue

dallas:
  - pin: GPIO13
    id: sensor_1    
  - pin: GPIO14
    id: sensor_2
  
sensor:
  - platform: dallas
    dallas_id: sensor_1
    index: 0
    name: TEMP1
  - platform: dallas
    dallas_id: sensor_2
    index: 0
    name: TEMP2

api:

Anything in the logs that might be useful for us?

--------------------------------------------------------------------
Output of modified connect.py from aioesphomeapi:

api_version: APIVersion(major=1, minor=9)

device_info: DeviceInfo(uses_password=False, name='temperator', friendly_name='', mac_address='*****', compilation_time='Aug  6 2023, 13:19:26', model='nodemcu-32s', manufacturer='Espressif', has_deep_sleep=False, esphome_version='2023.7.0', project_name='', project_version='', voice_assistant_version=0, legacy_bluetooth_proxy_version=0, bluetooth_proxy_feature_flags=0)

entity: BinarySensorInfo(object_id='taster', key=1433402148, name='Taster', unique_id='temperatorbinary_sensortaster', disabled_by_default=False, icon='', entity_category=<EntityCategory.NONE: 0>, device_class='', is_status_binary_sensor=False)

entity: SensorInfo(object_id='temp-1', key=3380183005, name='TEMP-1', unique_id='dallas-0000000000000000', disabled_by_default=False, icon='', entity_category=<EntityCategory.NONE: 0>, device_class='temperature', unit_of_measurement='°C', accuracy_decimals=1, force_update=False, state_class=<SensorStateClass.MEASUREMENT: 1>, last_reset_type=<LastResetType.NONE: 0>)

entity: SensorInfo(object_id='temp-2', key=3380183006, name='TEMP-2', unique_id='dallas-0000000000000000', disabled_by_default=False, icon='', entity_category=<EntityCategory.NONE: 0>, device_class='temperature', unit_of_measurement='°C', accuracy_decimals=1, force_update=False, state_class=<SensorStateClass.MEASUREMENT: 1>, last_reset_type=<LastResetType.NONE: 0>)

entity: SwitchInfo(object_id='blaue_led', key=1866352556, name='Blaue LED', unique_id='temperatorswitchblaue_led', disabled_by_default=False, icon='', entity_category=<EntityCategory.NONE: 0>, assumed_state=False, device_class='')

--------------------------------------------------------------------

The same output with the suggested solution:

api_version: APIVersion(major=1, minor=9)

device_info: DeviceInfo(uses_password=False, name='temperator', friendly_name='Temperator', mac_address='*****', compilation_time='Aug  6 2023, 17:37:31', model='nodemcu-32s', manufacturer='Espressif', has_deep_sleep=False, esphome_version='2023.7.0', project_name='', project_version='', voice_assistant_version=0, legacy_bluetooth_proxy_version=0, bluetooth_proxy_feature_flags=0)

entity: BinarySensorInfo(object_id='button', key=977454165, name='Button', unique_id='temperatorbinary_sensorbutton', disabled_by_default=False, icon='', entity_category=<EntityCategory.NONE: 0>, device_class='', is_status_binary_sensor=False)

entity: SensorInfo(object_id='temp1', key=307962872, name='TEMP1', unique_id='temperatorsensortemp1', disabled_by_default=False, icon='', entity_category=<EntityCategory.NONE: 0>, device_class='temperature', unit_of_measurement='°C', accuracy_decimals=1, force_update=False, state_class=<SensorStateClass.MEASUREMENT: 1>, last_reset_type=<LastResetType.NONE: 0>)

entity: SensorInfo(object_id='temp2', key=307962875, name='TEMP2', unique_id='temperatorsensortemp2', disabled_by_default=False, icon='', entity_category=<EntityCategory.NONE: 0>, device_class='temperature', unit_of_measurement='°C', accuracy_decimals=1, force_update=False, state_class=<SensorStateClass.MEASUREMENT: 1>, last_reset_type=<LastResetType.NONE: 0>)

entity: SwitchInfo(object_id='blue_led', key=817087403, name='Blue LED', unique_id='temperatorswitchblue_led', disabled_by_default=False, icon='', entity_category=<EntityCategory.NONE: 0>, assumed_state=False, device_class='')

Additional information

With the solution applied, both sensors show up:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions