Getting "Entity id already exists" error after connecting sensors to new Xiaomi gateway

Hi,

I have moved two sensors from being connected to one Xiaomi gateway to another Xiaomi gateway. Now I’m getting the error “Entity id already exists” in the log file. Sometimes the sensors are showing as “unavailable” sometimes they are giving values, but I haven’t been able to see a clear pattern. The sensors are a temperature/humidity/pressure sensor (158d0003d45086) and a motion sensor (158d0004470bb2), as can be seen in the log file below.
Both gateways are connected to the network and sensors, which have not been moved between gateways, are working fine. In the Xiaomi app the two sensors are shown correctly as children to the new gateway and they are connected and giving values as expected.

I assume that there is an old unique ID stuck somewhere in a configuration file and maybe being linked to the original gateway, but I’m simply unable to find it. I have checked in .storage\core.entity_registry but each sensor is only listed once.

Any help would be appreciated.

Thanks,
Dan

home-assistant.log:

2020-01-12 17:17:50 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 399, in _async_add_entity
    raise HomeAssistantError(msg)
homeassistant.exceptions.HomeAssistantError: Entity id already exists: binary_sensor.motion_sensor_158d0004470bb2. Platform xiaomi_aqara does not generate unique IDs
2020-01-12 17:17:51 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 399, in _async_add_entity
    raise HomeAssistantError(msg)
homeassistant.exceptions.HomeAssistantError: Entity id already exists: sensor.pressure_158d0003d45086. Platform xiaomi_aqara does not generate unique IDs
2020-01-12 17:17:51 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 399, in _async_add_entity
    raise HomeAssistantError(msg)
homeassistant.exceptions.HomeAssistantError: Entity id already exists: sensor.humidity_158d0003d45086. Platform xiaomi_aqara does not generate unique IDs
2020-01-12 17:17:51 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 399, in _async_add_entity
    raise HomeAssistantError(msg)
homeassistant.exceptions.HomeAssistantError: Entity id already exists: sensor.temperature_158d0003d45086. Platform xiaomi_aqara does not generate unique IDs
2020-01-12 17:17:54 WARNING (MainThread) [homeassistant.core] Unable to remove unknown listener <function async_track_point_in_utc_time.<locals>.point_in_time_listener at 0xb22dee88>
2020-01-12 17:17:56 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/storage.py", line 178, in _async_callback_delayed_write
    await self._async_handle_write_data()
  File "/usr/src/homeassistant/homeassistant/helpers/storage.py", line 190, in _async_handle_write_data
    if "data_func" in data:
TypeError: argument of type 'NoneType' is not iterable

After looking around even further, I stumbled across this in the Xiaomi Gateway integration documentation:
Xiaomi Gateway (Aqara) - Service xiaomi_aqara.remove_device

I tried the following:

  1. Deleted the sensors in the Xiaomi app.
  2. Ran the xiaomi_aqara.remove_device service (Developer Tools - Services) for both sensors on both gateways. It seems like the example for the gw_mac is not correct. At least I used the format xx:xx:xx:xx:xx:xx and not xxxxxxxxxxxx (see screen dump below).
  3. Reconnected the sensors to the desired gateway using the Xiaomi app.
  4. Restarted Home Assistant (Configuration - Server Controls - Restart).

It seems to have solved this issue. At least the error messages have disappeared in the log file and everything is online. Now I just need to monitor if they also stop becoming “unavailable” from time to time.

I apologise for the unecessary thread, but at least now there is a thread linking the error message to the Xiaomi remove_device service.

/Dan

1 Like

In my situation, only step 2 is necessary.
I didn’t touch the Xiaomi app and only remove device from old gateway according step 2. Then the specific device working properly.