Xiaomi Gateway - switch.plug_##### random rename

Hi,

I have been using the gateway and the plugs for a while. All was good.
Then I moved one plug to the second gateway and now it seems to randomly change its name between switch.plug_158d00013e8964 and witch.plug_158d00013e8964_2

I removed all mention of the plug from the config and after a restart, both of them show up in the developer tool, one of them works, the other does nothing, but sometimes they swap. I checked the app, there is only one.

Any idea where to trouble shoot next would be appreciated as this is my bedside lamp and it is a PITA when I have to debug HASS to switch off the light and go to sleep :frowning:

My Xiaomi config is here (this still includes the plug): https://github.com/Data-Monkey/Home-Assistant-Config/blob/master/includes/packages/Xiaomi_Package.yaml

1 Like

I have exactly the same issue with a temperature/motion sensor. At first I thought it was something I did wrong because the values for the sensor were sometimes unknown.

Because I did not see the second one being registered with the _2 name at first, I deleted the sensor in the MiHome app and registered it again with the gateway.

Then I saw the one with the _2 and thought it was a replacement for the previous one, but then the same behavior also occurred for the _2 one.

Sometimes it gives unknown, sometimes it gives a value.

Thanks, at least I am not alone with this problem.

Maybe @Danielhiversen or @syssi could point us into the right direction on how to debug this?

1 Like

I have an idea what’s happening: Each gateway maintains a list of paired devices. This list is retrieved by home assistant and used to create a HA sensor/device per entry. The “moved” device is attached twice now because it wasn’t removed from the former gateway. I guess you have done a hard-reset of the sensor instead of using the Mi Home App and the “remove device from gateway” button. Next edge case: The discovery of the gateways is non deterministic. It depends which gateway response first. So sometimes the unavailable device will be registered first and vice versa.

It’s a bug. Could be please file an issue here and reference this thread: https://github.com/home-assistant/home-assistant

A workaround: Use the Mi Home App to clean-up your list of paired devices.

Thanks @syssi
Sounds very reasonable. Is there a way to verify your assumption?
I will raise the issue later today.
The device does not show up on the original gateway anymore in the Mi app. Any idea how I could clean it up?

You can enable the debug log:

logger:
  default: warn
  logs:
    homeassistant.components.xiaomi: debug
    homeassistant.components.sensor.xiaomi: debug
    homeassistant.components.binary_sensor.xiaomi: debug
    homeassistant.components.light.xiaomi: debug
    homeassistant.components.switch.xiaomi: debug

Right after the recovery the retrieval of the device list is logged. You should find two device lists in the log. One entry must be in both lists.

I will think about it. I remember the is an api method which is not used/implemented at the home asisstant component.

Hi @syssi,
I have created the issue: xiaomi_aqara issue when device is/was connected to multiple gateways ¡ Issue #9571 ¡ home-assistant/core ¡ GitHub

I have upgraded today and made the adjustments to the config and the debug settings.
But I can’t find the list you mentioned above.
here the first 10 minutes from my log, the device in question is switch.plug_158d00013e8964 and switch.plug_158d00013e8964_2

2017-09-25 20:36:31 DEBUG (SyncWorker_14) [homeassistant.components.xiaomi_aqara] Expecting 2 gateways
2017-09-25 20:36:31 INFO (SyncWorker_14) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 1)
2017-09-25 20:36:32 WARNING (MainThread) [homeassistant.helpers.entity] Update for media_player.living_room is already in progress
2017-09-25 20:36:36 DEBUG (SyncWorker_14) [homeassistant.components.xiaomi_aqara] Gateways discovered. Listening for broadcasts
2017-09-25 20:36:40 WARNING (MainThread) [homeassistant.setup] Setup of media_player is taking over 10 seconds.
2017-09-25 20:36:40 WARNING (MainThread) [homeassistant.setup] Setup of remote is taking over 10 seconds.
2017-09-25 20:36:40 WARNING (MainThread) [homeassistant.setup] Setup of device_tracker is taking over 10 seconds.
2017-09-25 20:36:41 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
2017-09-25 20:36:52 DEBUG (SyncWorker_14) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00014dd511: off>: {'no_motion': '1200'}
2017-09-25 20:37:04 DEBUG (SyncWorker_15) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00014dd669: off>: {'no_motion': '1200'}
2017-09-25 20:37:06 DEBUG (SyncWorker_19) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00012dc3de: off>: {'no_motion': '1200'}
2017-09-25 20:37:19 WARNING (SyncWorker_0) [netdisco.ssdp] Error fetching description at http://192.168.1.250:1990/WFADevice.xml
2017-09-25 20:37:23 INFO (SyncWorker_16) [homeassistant.components.xiaomi_aqara] Discovered: {'host': '192.168.2.134', 'port': 54321, 'hostname': 'lumi-gateway-v3_miio47622663.local.', 'properties': {'epoch': '1', 'mac': 'f0b429cfbc12'}, 'mac_address': 'f0b429cfbc12'}
2017-09-25 20:37:23 INFO (SyncWorker_15) [homeassistant.components.xiaomi_aqara] Discovered: {'host': '192.168.2.133', 'port': 54321, 'hostname': 'lumi-gateway-v3_miio52049271.local.', 'properties': {'epoch': '1', 'mac': '286c0785b6f3'}, 'mac_address': '286c0785b6f3'}
2017-09-25 20:38:08 DEBUG (SyncWorker_3) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d0001288e14: off>: {'voltage': 3600, 'status': 'off', 'inuse': '0', 'power_consumed': '174', 'load_power': '0.00'}
2017-09-25 20:40:12 DEBUG (SyncWorker_5) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d00013f9d2a: on>: {'voltage': 3600, 'status': 'on', 'inuse': '1', 'power_consumed': '1820', 'load_power': '12.58'}
2017-09-25 20:40:46 DEBUG (SyncWorker_2) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d00013e8964: on>: {'voltage': 3600, 'status': 'on', 'inuse': '1', 'power_consumed': '3362', 'load_power': '39.63'}
2017-09-25 20:42:31 DEBUG (SyncWorker_4) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Switch_158d000186dfe4: off>: {'voltage': 3062}
2017-09-25 20:43:39 DEBUG (SyncWorker_14) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Switch_158d0001870e25: off>: {'voltage': 3092}
2017-09-25 20:44:33 DEBUG (SyncWorker_13) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Illumination_f0b429cfbc12: 432.0>: {'rgb': 0, 'illumination': 741}
2017-09-25 20:44:33 DEBUG (SyncWorker_13) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Gateway Light_f0b429cfbc12: off>: {'rgb': 0, 'illumination': 741}
2017-09-25 20:45:34 DEBUG (SyncWorker_9) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Temperature_158d0001576d20: 23.85>: {'temperature': '2390'}
2017-09-25 20:45:34 DEBUG (SyncWorker_9) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Humidity_158d0001576d20: 33.94>: {'temperature': '2390'}
2017-09-25 20:45:34 DEBUG (SyncWorker_5) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Temperature_158d0001576d20: 23.9>: {'humidity': '4027'}
2017-09-25 20:45:34 DEBUG (SyncWorker_5) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Humidity_158d0001576d20: 33.94>: {'humidity': '4027'}
2017-09-25 20:45:34 DEBUG (SyncWorker_8) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Temperature_158d0001576d20: 23.9>: {'voltage': 3035, 'temperature': '2390', 'humidity': '4027'}
2017-09-25 20:45:34 DEBUG (SyncWorker_8) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Humidity_158d0001576d20: 40.27>: {'voltage': 3035, 'temperature': '2390', 'humidity': '4027'}
2017-09-25 20:46:01 DEBUG (SyncWorker_5) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d0001288e14: off>: {'voltage': 3600, 'status': 'off', 'inuse': '0', 'power_consumed': '174', 'load_power': '0.00'}
2017-09-25 20:46:50 DEBUG (SyncWorker_19) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00014dd511: off>: {'no_motion': '1800'}
2017-09-25 20:47:02 DEBUG (SyncWorker_5) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d00013e8964: on>: {'voltage': 3600, 'status': 'on', 'inuse': '1', 'power_consumed': '3362', 'load_power': '39.63'}
2017-09-25 20:47:02 DEBUG (SyncWorker_12) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00014dd669: off>: {'no_motion': '1800'}
2017-09-25 20:47:05 DEBUG (SyncWorker_6) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00012dc3de: off>: {'no_motion': '1800'}
2017-09-25 20:47:05 DEBUG (SyncWorker_1) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Temperature_158d00015763d7: 22.69>: {'temperature': '2212'}
2017-09-25 20:47:05 DEBUG (SyncWorker_1) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Humidity_158d00015763d7: 27.64>: {'temperature': '2212'}
2017-09-25 20:47:05 DEBUG (SyncWorker_17) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Temperature_158d00015763d7: 22.12>: {'humidity': '2831'}
2017-09-25 20:47:05 DEBUG (SyncWorker_17) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Humidity_158d00015763d7: 27.64>: {'humidity': '2831'}
2017-09-25 20:47:50 DEBUG (SyncWorker_9) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d00013f9d2a: on>: {'voltage': 3600, 'status': 'on', 'inuse': '1', 'power_consumed': '1820', 'load_power': '12.58'}

Let me know please if I can help any further

I have the same problem. Has anyone solved it?

Not a solution at all, but a workaround.
I put both plugs (real and ghost) in a group and I toggle the group.
Not very elegant ,but at least the plug works again.

That’s true, but I want to fix it

The only real solution for moment is to find a way to remove the duplicated device from one of the gateways.

There might be this manual solution.
So I got into this mess when I moved one device (a plug) from Gateway1 (G1) to Gateway2 (G2) without properly removing it from G1.
Today I did this:

Open the Mi Home App
– go to G2
– find the device
– remove the device cleanly

– go to G1
– add the device
– remove the device (now it is gone cleanly)

– go back to G2
– add the device again

so far I have restarted HASS about 15-20 times and it is still good.
Of course, it was some kind of race condition and it could still go wrong, but it feels like I got it this time

1 Like

Glad you found out… This is very useful! Thank you very much!

This issue solved it for me as well.

Thank you.

The manual workaround should no longer be required, @syssi implemented new functionality to add/remove devices.

https://github.com/home-assistant/home-assistant/pull/10150

I am constantly amazed how great this community is! Thanks a lot!

2 Likes

how does it work?

Luckily I didn’t have any need to try it yet.
But there is a new service call:

xiaomi_aqara.remove_device

from the link above:
The service “remove_device” removes a sub-device identified by the device address (f.e. 158d000xxxxxc2)

Ok I put
{ “entity_id”: “binary_sensor.motion_sensor_158d000112e1de_2” }

click on remove it, and then …?

I restarted and the sensor is still there (with _2)

I checked log, so I put this

{ “entity_id”: “binary_sensor.motion_sensor_158d000112e1de_2”, “device_id”:“y0s16gzdzpt3xxxx”, “gw_mac”:“f0b429aaxxxx” }

2018-02-27 09:55:21 ERROR (MainThread) [homeassistant.core] Invalid service data for xiaomi_aqara.remove_device: extra keys not allowed @ data[‘entity_id’]. Got ‘binary_sensor.motion_sensor_158d000112e1de_2’
length of value must be at most 14 for dictionary value @ data[‘device_id’]. Got ‘y0s16gzdzpt3mlrd’