Home Assistant release with the issue:
0.65.6
Last working Home Assistant release (if known):
0.65.6
Operating environment (Hass.io/Docker/Windows/etc.):
Raspberry pi with virtual env. followed install instruction.
Component/platform:
Xiaomi Gateway (Aqara) / Xiaomi Cover
Description of problem:
sometimes entity_registry.yaml makes same entity with "_2" tail and unique ids.
cover.curtain_158d0001fd5065:
name:
platform: xiaomi_aqara
unique_id: status_status_pos_curtain_level158d0001fd5065
cover.curtain_158d0001fd5065_2:
name:
platform: xiaomi_aqara
unique_id: pos_curtain_level_status_status158d0001fd5065
Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):
# Xiaomi Gateway
xiaomi_aqara:
discovery_retry: 5
gateways:
- mac: !secret aqara_mac
key: !secret aqara_key
Traceback (if applicable):
Additional information:
nothing related for this issue but I'm using with custom component for Smart Mi Fan from https://github.com/syssi/chuangmi_ir
follwing log is caused by offlined fan. Just i'm not sure this one affect or not.
2018-03-29 03:47:13 ERROR (Thread-7) [miio.device] Unable to discover a device at address 192.168.10.213
2018-03-29 03:47:13 ERROR (MainThread) [homeassistant.components.fan] Error while setting up platform smart_mi_fan
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 82, in async_setup
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File "/usr/lib/python3.5/asyncio/tasks.py", line 400, in wait_for
return fut.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
raise self._exception
File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/homeassistant/.homeassistant/custom_components/fan/smart_mi_fan.py", line 77, in setup_platform
SmartMiFan(hass, name, host, token),
File "/home/homeassistant/.homeassistant/custom_components/fan/smart_mi_fan.py", line 165, in __init__
self._state_attrs = self.fan_get_prop()
File "/home/homeassistant/.homeassistant/custom_components/fan/smart_mi_fan.py", line 404, in fan_get_prop
"natural_level", "child_lock", "buzzer", "led_b"])
File "/srv/homeassistant/lib/python3.5/site-packages/miio/device.py", line 210, in send
self.do_discover()
File "/srv/homeassistant/lib/python3.5/site-packages/miio/device.py", line 148, in do_discover
raise DeviceException("Unable to discover the device %s" % self.ip)
miio.device.DeviceException: Unable to discover the device 192.168.10.213
This is the expected behavior. Entity IDs are generated based on the friendly name of the entity. And if the friendly name of two entities are the same, _2 _3 and so on are appended to the name to have unique IDs as before.
What the entity registry does is it allows you to manually change the entity id by the user. For example you can now rename your _2 entity to cover.curtain_cover. The entity registry isn't there to improve automatic entity id generating, but to allow users to manually change them.
@OttoWinter Thanks for the infomation about "_2" tailing and usage for entity registry. But the problem is if I made some automation with this entity, it's not working sometimes because the device is matched with another _2 entity, not the original one. I think xiaomi aqara platform has a bit problem because the device already has entity and unique id, the platform makes another one. Other xiaomi zigbee devices are super fine, but not the cover.
For the clear infomation, I have one cover not 2 :)
cover.curtain_158d0001fd5065:
unique_id: status_status_pos_curtain_level158d0001fd5065
cover.curtain_158d0001fd5065_2:
unique_id: pos_curtain_level_status_status158d0001fd5065
cover has more than one prefix for generated unique_id.
sensor.temperature_158d0001ddb487:
name:
platform: xiaomi_aqara
unique_id: temperature158d0001ddb487
binary_sensor.switch_158d00016da2a7:
name:
platform: xiaomi_aqara
unique_id: status158d00016da2a7
binary_sensor.door_window_sensor_158d00016fdc87:
name:
platform: xiaomi_aqara
unique_id: status158d00016fdc87
binary_sensor.motion_sensor_158d00012300c1:
name:
platform: xiaomi_aqara
unique_id: status158d00012300c1
Other devices have just one prefix.
First up, I don't know anything about xiaomi, but there are probably reasons for splitting up the cover platform into two entities. Now, I think the behavior you're referring to with having "unstable" entity IDs is from before the entity registry times. Because now, you can override which entity ID home assistant uses for entities in the entity registry. For example, if you want to rename the entity ID of your _2 cover you can just put this in your entity_registry.yaml:
cover.curtain_number_one:
name:
platform: xiaomi_aqara
unique_id: status_status_pos_curtain_level158d0001fd5065
cover.curtain_number_two:
name:
platform: xiaomi_aqara
unique_id: pos_curtain_level_status_status158d0001fd5065
Now the entity IDs of the covers should be cover.curtain_number_one and cover.curtain_number_two (apart from https://github.com/home-assistant/home-assistant/issues/13316, but I doubt that's the case here). Once you put that in your registry, Home Assistant will no longer suffix the entity ids with numbers like _2. Again, I have no idea why xiaomi does this with 2 cover entities, but there are probably reasons for that.
@OttoWinter OK I see. I understand there is no way to merge these entities fundamentally or prevent split. The weird thing is if I don't reboot or restart HA, it's just fine not be split. But for the automation, I'll handle two entities. Thanks again with kind explanation about this problem. :)
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment :+1:
@balloobbot Same issues. version 0.74.0
cover.curtain_158d00020e43f1:
platform: xiaomi_aqara
unique_id: status_status_pos_curtain_level158d00020e43f1
cover.curtain_158d00020e43f1_2:
platform: xiaomi_aqara
unique_id: pos_curtain_level_status_status158d00020e43f1
These 2 curtains are same curtain.
But "unique_id" is different.
Above is "status_status_pos_curtain_level .... "
Below is " pos_curtain_level_status_status .... "
please help me.
LOL, it is a bug.
In cover.xaiomi_aqara, when we create XiaominDevice, we pass in a dict as _data_key
And in xiaomi_aqara, we use _data_key as part of device's _unique_id
Fun thing here is in python 3.5 and below, dict will not preserve the order, the output of dict format will be random. So after several HA restart, we end up have two entity id.
cc @syssi @Danielhiversen
If this is fixed, will:
homeassistant.exceptions.HomeAssistantError: Entity id already exists: binary_sensor.motion_sensor_xxxxxxxxxxxxxxxxxx. Platform xiaomi_aqara does not generate unique IDs
also be fixed?
@awarecan: Do you know if this bug is already fixed?
@Danielhiversen I know we are all busy, but if I buy you a beer, can you take a look here?
I do not have any xioami curtains, but can you try this
https://github.com/home-assistant/home-assistant/compare/dev...unique_id_xiaomi?quick_pull=1
What other sensor does your motion sensor has?
Can you post their entity id?
I will test with your code but for now this is my error:
Traceback (most recent call last):
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 346, in _async_add_entity
msg)
homeassistant.exceptions.HomeAssistantError: Entity id already exists: binary_sensor.motion_sensor_158d000121c89d. Platform xiaomi_aqara does not generate unique IDs
2018-10-17 10:37:18 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 346, in _async_add_entity
msg)
homeassistant.exceptions.HomeAssistantError: Entity id already exists: binary_sensor.door_window_sensor_158d0001a33834. Platform xiaomi_aqara does not generate unique IDs
^^ I have edited the file, but have the same error.
The sensor is a motion sensor and a illumination sensor in one (the aqara version of the xiaomi motion sensor)
@frekel Please do not piggy back, your issue is totally different and you should submit a new issue to track.
@awarecan So sorry! I confused 2 issues (I have both this and the _2 error!)
Please advice; do I need to remove the comments?
No, you don't need remove them. I am going to hide them.
I do not have any xioami curtains, but can you try this
https://github.com/home-assistant/home-assistant/compare/dev...unique_id_xiaomi?quick_pull=1What other sensor does your motion sensor has?
Can you post their entity id?
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "sensor.illumination_7811dcb8fc90",
"name": "Gateway Bright",
"platform": "xiaomi_aqara",
"unique_id": "illumination7811dcb8fc90"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.switch_158d0001f47471",
"name": "Switch Bathroom",
"platform": "xiaomi_aqara",
"unique_id": "status158d0001f47471"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.switch_158d000214e8b5",
"name": "Switch Bedroom",
"platform": "xiaomi_aqara",
"unique_id": "status158d000214e8b5"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.motion_sensor_158d0001d557b4",
"name": "Motion Bedroom",
"platform": "xiaomi_aqara",
"unique_id": "status158d0001d557b4"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.motion_sensor_158d0001d5562c",
"name": "Motion Living room",
"platform": "xiaomi_aqara",
"unique_id": "status158d0001d5562c"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.door_window_sensor_158d0002286d34",
"name": "Contact Right",
"platform": "xiaomi_aqara",
"unique_id": "status158d0002286d34"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.door_window_sensor_158d00022b9747",
"name": "Contact Left",
"platform": "xiaomi_aqara",
"unique_id": "status158d00022b9747"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.motion_sensor_158d0001d55679",
"name": "Motion Bathroom",
"platform": "xiaomi_aqara",
"unique_id": "status158d0001d55679"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.motion_sensor_158d0001d5578c",
"name": "Motion Kitchen",
"platform": "xiaomi_aqara",
"unique_id": "status158d0001d5578c"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.switch_158d0001e7361b",
"name": "Switch Door",
"platform": "xiaomi_aqara",
"unique_id": "status158d0001e7361b"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.door_window_sensor_158d0001fd5298",
"name": "Contact Door",
"platform": "xiaomi_aqara",
"unique_id": "status158d0001fd5298"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.motion_sensor_158d0001d55790",
"name": "Motion Door",
"platform": "xiaomi_aqara",
"unique_id": "status158d0001d55790"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "light.gateway_light_7811dcb8fc90",
"name": "Gateway Light",
"platform": "xiaomi_aqara",
"unique_id": "rgb7811dcb8fc90"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.cube_158d00027d06c0",
"name": "Cube Living room",
"platform": "xiaomi_aqara",
"unique_id": "status158d00027d06c0"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "binary_sensor.cube_158d00027d8fc4",
"name": "Cube Bedroom",
"platform": "xiaomi_aqara",
"unique_id": "status158d00027d8fc4"
},
{
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_id": "cover.curtain_158d00022c80b5",
"name": "Curtain",
"platform": "xiaomi_aqara",
"unique_id": "curtain158d00022c80b5"
}
I have a similar issue. Since a couple of weeks (possibly one of the last updates) one of my door-window sensors stopped working in HA.
The error is:
1471-2018-11-11 16:48:36 WARNING (MainThread) [homeassistant.setup] Setup of xiaomi_aqara is taking over 10 seconds.
1583-2018-11-11 16:48:37 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
1695-Traceback (most recent call last):
1730- File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 346, in _async_add_entity
1859- msg)
1868:homeassistant.exceptions.HomeAssistantError: Entity id already exists: binary_sensor.door_window_sensor_158d00014df7be. Platform xiaomi_aqara does not generate unique IDs
I have 62 devices, 3 gateways and it is always this sensor causing problems (but it works fine in the Xiaomi app & automations so I tend to exclude it is and hardware or battery issue).
Would it make sense to manually remove the entity from core.entity_registry and see if it gets added correctly?
This is not only an issue for covers anymore, but for all xiaomi_aquara devices. They suddenly got a _2 suffix breaking all automations:

em... this bug works for me...
em... this bug works for me...
i have solved this by upgrading my python verion to 3.7 in pi
@DavidLP May be you are affected of this recent change: https://github.com/home-assistant/home-assistant/pull/19192
@syssi I got hit by this too. Will your fix restore slugified ids?
Yes. The PR will fix/avoid the issue. I hope you haven't touched your .storage/core.entity_registry in the meantime.
This issue will not be fixed by #19770, but #19766, reopen it.
Most helpful comment
LOL, it is a bug.
In
cover.xaiomi_aqara, when we create XiaominDevice, we pass in adictas_data_keyhttps://github.com/home-assistant/home-assistant/blob/9fb8bc8991eda47488e2bfeac37c1d41378a9174/homeassistant/components/cover/xiaomi_aqara.py#L20-L23
And in
xiaomi_aqara, we use_data_keyas part of device's_unique_idhttps://github.com/home-assistant/home-assistant/blob/9fb8bc8991eda47488e2bfeac37c1d41378a9174/homeassistant/components/xiaomi_aqara.py#L227-L229
Fun thing here is in python 3.5 and below,
dictwill not preserve the order, the output of dict format will be random. So after several HA restart, we end up have two entity id.cc @syssi @Danielhiversen