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 .
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.
With this small change everything performed like expected.
Please let me know if I can provide more help.
--------------------------------------------------------------------
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='')
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
Anything in the logs that might be useful for us?
Additional information
With the solution applied, both sensors show up:
