Xiaomi Gateway Becomes Unavailable after some time

Hi,

Sorry if this is just another ‘Xiaomi Gateway Problem’ thread… I’ve tried searching this forum for every solution for my problem, tried to implement them, but still my problem persists. I hope someone can help me here.

The problem:
I have three xiaomi gateway, two are Xiaomi Gateway v3 and one is Aqara AC Partner. I have persistent problem with one of the Xiaomi Gateway v3, let’s call this Gateway A. Since several days ago, Gateway A consistently looses connection with HA but not with Xiaomi Home app. The most I can get with Gaeway A is three hours, after that it became unavailable and bringing all the child devices (sensors) offline also in HA. I check in Xiaomi Home app, and the gateway A with all its children are working fine. If I restart HA, the gateway A and all its children appear normal again. But just for some time, gateway A will be unavailable again. Here is the screnshot :

image

What I have done :

  1. Make sure wifi channel is not overlapping with Zigbee. Three of the gateway uses channel 11,15, and 25. I move my wifi to channel 7 to avoid overlapping, but the problem persists.
  2. I move the Gateway A closer to the router, but I don’t think signal quality is the issue. The problem persists.
  3. I disabled-enabled, create new token key from Xiaomi Home app. The problem persists.
  4. I tried setting ‘ping’ sensor in HA to regularly ping the Gateway A every 10 seconds. The ping sensor works OK even during the ‘unavailable’ time, which means no network connectivity problem between router and gateway A.
  5. I tried logging in xiaomy_gateway error from HA. Currently I only have the discovery logging of the gateway, as I haven’t yet encountered ‘unavailable’ again after I enable the logger 5 minutes ago. I’ll post the updated log when the Gateway A become unavailable. Here is the logging for Gateway A :
2019-06-14 09:56:58 INFO (SyncWorker_17) [xiaomi_gateway] Xiaomi Gateway 7811dcb37d98 configured at IP 192.168.0.108:9898
2019-06-14 09:56:58 DEBUG (SyncWorker_17) [xiaomi_gateway] _send_cmd >> b'{"cmd":"read","sid":"7811dcb37d98"}'
2019-06-14 09:56:59 DEBUG (SyncWorker_17) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_ack', 'model': 'gateway', 'sid': '7811dcb37d98', 'short_id': 0, 'data': '{"rgb":0,"illumination":1292,"proto_version":"1.1.2"}'}
2019-06-14 09:56:59 INFO (SyncWorker_17) [xiaomi_gateway] Discovering Xiaomi Devices
2019-06-14 09:56:59 DEBUG (SyncWorker_17) [xiaomi_gateway] _send_cmd >> b'{"cmd" : "get_id_list"}'
2019-06-14 09:56:59 DEBUG (SyncWorker_17) [xiaomi_gateway] _send_cmd resp << {'cmd': 'get_id_list_ack', 'sid': '7811dcb37d98', 'token': 'fpAJ7LWN5FJdQBrz', 'data': '["158d00027cdb02"]'}
2019-06-14 09:56:59 INFO (SyncWorker_17) [xiaomi_gateway] Found 2 devices
2019-06-14 09:56:59 DEBUG (SyncWorker_17) [xiaomi_gateway] Discovery attempt 1/4
2019-06-14 09:56:59 DEBUG (SyncWorker_17) [xiaomi_gateway] _send_cmd >> b'{"cmd":"read","sid":"158d00027cdb02"}'
2019-06-14 09:56:59 DEBUG (SyncWorker_17) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_ack', 'model': 'switch', 'sid': '158d00027cdb02', 'short_id': 7360, 'data': '{"voltage":3022}'}
2019-06-14 09:56:59 DEBUG (SyncWorker_17) [xiaomi_gateway] Registering device 158d00027cdb02, switch as: binary_sensor
2019-06-14 09:56:59 DEBUG (SyncWorker_17) [xiaomi_gateway] Discovery attempt 1/4
2019-06-14 09:56:59 DEBUG (SyncWorker_17) [xiaomi_gateway] _send_cmd >> b'{"cmd":"read","sid":"7811dcb37d98"}'
2019-06-14 09:56:59 DEBUG (SyncWorker_17) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_ack', 'model': 'gateway', 'sid': '7811dcb37d98', 'short_id': 0, 'data': '{"rgb":0,"illumination":1292,"proto_version":"1.1.2"}'}
2019-06-14 09:56:59 DEBUG (SyncWorker_17) [xiaomi_gateway] Registering device 7811dcb37d98, gateway as: sensor
2019-06-14 09:56:59 DEBUG (SyncWorker_17) [xiaomi_gateway] Registering device 7811dcb37d98, gateway as: light
2019-06-14 09:57:04 INFO (SyncWorker_17) [xiaomi_gateway] Gateway discovery finished in 5 seconds
2019-06-14 09:57:04 INFO (SyncWorker_17) [xiaomi_gateway] Creating Multicast Socket

Does anyone have any similar problem with Xiaomi Gateway? Please kindly share what is your experience with Xiaomi Gateway? I’m thinking about Zigbee2MQTT also, but will it be more reliable in long-term?

Try your wifi on channel 1, there may not be enough seperation at ZigBee channels don’t match the same as wifi channels. I run on wifi channel 1 and my gateways are ZigBee 15 and 25 and don’t have any issues

If the gateway becomes unavailable in HA it’s not related to interference as you connect to your gateway by WiFi. Interference only influences the connection between the sensors and the gateway itself.
I’m no longer using Xiaomi gateways but switched to Conbee/Deconz. The advantage is you create one big mesh network instead of three seperate networks as you’ll have right now (with possible interference between them). The more repeaters you have (like bulbs) the more stable it becomes.

I used to have my WiFi on channel 1, but I changed it to channel 7 several days ago in an attempt to fix my Xiaomi Gateway problems. I’m following the recommendation here as of this image :

which, CMIIW, should keep channel 7 of WiFi far enough from channel 11,15, and 25 of the zigbees… But changing the WiFi channel doesn’t seem to fix my issue…

As a matter of facts, I have several xiaomi mijia and aqara sensors which randomly become unavailable to both the gateway and HA (missing or goes offline in Xiaomi Home app, and also missing from HA dev-state). Pairing the sensors to one of the three gateways that I own results the same unreliability, after some days, a sensor or two become disconnected and I have to re-pair the sensor again… That’s why I’m beginning to think about third-party solution like Conbee/Deconz or Zigbee2MQTT.

I’m not familiar yet with Conbee, but I’ve done some reading on Zigbee2MQTT, and actually have ordered some of the parts from Ali. Do you have any comparison (real life, hopefully) about Zigbee2MQTT against Conbee/Deconz? Will the Zigbee2MQTT works as a mesh network as well?

The Gateway A just goes unavailable again… Let’s see what the logger says…

image

Hmm… strange enough, I’ve tried to find something related to error near the time when the Gateway A became unavaliable, which is around 1:54 PM as per the image. However no error or anything show up in the log :

2019-06-14 13:53:09 DEBUG (SyncWorker_2) [xiaomi_gateway] _send_cmd >> b'{ "cmd":"read","sid":"158d00022f4b8b"}'
2019-06-14 13:53:09 DEBUG (SyncWorker_2) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_rsp', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'battery_voltage': 3600}, {'channel_0': 'on'}, {'inuse': 0}, {'energy_consumed': 92791}, {'load_power': 0.0}]}
2019-06-14 13:53:09 DEBUG (SyncWorker_2) [xiaomi_gateway] read_ack << {'cmd': 'read_rsp', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'battery_voltage': 3600}, {'channel_0': 'on'}, {'inuse': 0}, {'energy_consumed': 92791}, {'load_power': 0.0}]}
2019-06-14 13:53:40 DEBUG (SyncWorker_18) [xiaomi_gateway] _send_cmd >> b'{ "cmd":"read","sid":"158d00022f4b8b"}'
2019-06-14 13:53:40 DEBUG (SyncWorker_18) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_rsp', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'battery_voltage': 3600}, {'channel_0': 'on'}, {'inuse': 0}, {'energy_consumed': 92791}, {'load_power': 0.0}]}
2019-06-14 13:53:40 DEBUG (SyncWorker_18) [xiaomi_gateway] read_ack << {'cmd': 'read_rsp', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'battery_voltage': 3600}, {'channel_0': 'on'}, {'inuse': 0}, {'energy_consumed': 92791}, {'load_power': 0.0}]}
2019-06-14 13:53:42 DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'gateway', 'sid': '7c49eb17ec14', 'short_id': 0, 'data': '{"rgb":0,"illumination":561}'}
2019-06-14 13:53:55 DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'load_power': 0.0}]}
2019-06-14 13:53:55 DEBUG (Thread-4) [xiaomi_gateway] MCAST (heartbeat) << {'cmd': 'heartbeat', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'battery_voltage': 3600}, {'channel_0': 'on'}, {'inuse': 0}, {'energy_consumed': 92791}, {'load_power': 0.0}]}
2019-06-14 13:54:11 DEBUG (SyncWorker_9) [xiaomi_gateway] _send_cmd >> b'{ "cmd":"read","sid":"158d00022f4b8b"}'
2019-06-14 13:54:11 DEBUG (SyncWorker_9) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_rsp', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'battery_voltage': 3600}, {'channel_0': 'on'}, {'inuse': 0}, {'energy_consumed': 92791}, {'load_power': 0.0}]}
2019-06-14 13:54:11 DEBUG (SyncWorker_9) [xiaomi_gateway] read_ack << {'cmd': 'read_rsp', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'battery_voltage': 3600}, {'channel_0': 'on'}, {'inuse': 0}, {'energy_consumed': 92791}, {'load_power': 0.0}]}
2019-06-14 13:54:41 DEBUG (SyncWorker_2) [xiaomi_gateway] _send_cmd >> b'{ "cmd":"read","sid":"158d00022f4b8b"}'
2019-06-14 13:54:41 DEBUG (SyncWorker_2) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_rsp', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'battery_voltage': 3600}, {'channel_0': 'on'}, {'inuse': 0}, {'energy_consumed': 92791}, {'load_power': 0.0}]}
2019-06-14 13:54:41 DEBUG (SyncWorker_2) [xiaomi_gateway] read_ack << {'cmd': 'read_rsp', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'battery_voltage': 3600}, {'channel_0': 'on'}, {'inuse': 0}, {'energy_consumed': 92791}, {'load_power': 0.0}]}
2019-06-14 13:54:51 DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'weather', 'sid': '158d000247fe8e', 'params': [{'temperature': 2925}]}
2019-06-14 13:54:52 DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'weather', 'sid': '158d000247fe8e', 'params': [{'humidity': 6901}]}
2019-06-14 13:54:52 DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'weather', 'sid': '158d000247fe8e', 'params': [{'pressure': 99100}]}
2019-06-14 13:55:12 DEBUG (SyncWorker_5) [xiaomi_gateway] _send_cmd >> b'{ "cmd":"read","sid":"158d00022f4b8b"}'
2019-06-14 13:55:12 DEBUG (SyncWorker_5) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_rsp', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'battery_voltage': 3600}, {'channel_0': 'on'}, {'inuse': 0}, {'energy_consumed': 92791}, {'load_power': 0.0}]}
2019-06-14 13:55:12 DEBUG (SyncWorker_5) [xiaomi_gateway] read_ack << {'cmd': 'read_rsp', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'battery_voltage': 3600}, {'channel_0': 'on'}, {'inuse': 0}, {'energy_consumed': 92791}, {'load_power': 0.0}]}
2019-06-14 13:55:43 DEBUG (SyncWorker_7) [xiaomi_gateway] _send_cmd >> b'{ "cmd":"read","sid":"158d00022f4b8b"}'
2019-06-14 13:55:43 DEBUG (SyncWorker_7) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_rsp', 'model': 'plug', 'sid': '158d00022f4b8b', 'params': [{'battery_voltage': 3600}, {'channel_0': 'on'}, {'inuse': 0}, {'energy_consumed': 92791}, {'load_power': 0.0}]}

Sensors are reporting to the other two gateways. But one switch sensor connected to Gateway A is not reporting anymore.

What’s weirder though, is that about 10 minutes before, someone (a delivery guy) pressed the switch button (which paired to Gateway A) however the logger showed error regarding ‘invalid key’ :

2019-06-14 13:32:50 DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'switch', 'sid': '158d00027cdaa2', 'short_id': 41337, 'data': '{"status":"click"}'}
2019-06-14 13:32:50 DEBUG (SyncWorker_8) [xiaomi_gateway] _send_cmd >> b'{"cmd": "write", "sid": "7811dcb37d98", "data": {"mid": 20, "vol": 75, "key": "864c811e93be5b82dc2193e6659e4f83"}}'
2019-06-14 13:32:50 DEBUG (SyncWorker_8) [xiaomi_gateway] _send_cmd resp << {'cmd': 'write_ack', 'sid': '7811dcb37d98', 'data': '{"error":"Invalid key"}'}
2019-06-14 13:32:50 DEBUG (SyncWorker_8) [xiaomi_gateway] write_ack << {'cmd': 'write_ack', 'sid': '7811dcb37d98', 'data': '{"error":"Invalid key"}'}
2019-06-14 13:32:50 ERROR (SyncWorker_8) [xiaomi_gateway] Got error element in data {"error":"Invalid key"}
2019-06-14 13:32:50 DEBUG (SyncWorker_8) [xiaomi_gateway] _send_cmd >> b'{"cmd" : "get_id_list"}'
2019-06-14 13:32:50 DEBUG (SyncWorker_8) [xiaomi_gateway] _send_cmd resp << {'cmd': 'get_id_list_ack', 'sid': '7811dcb37d98', 'token': 'I20ocPgOiLMCvgiZ', 'data': '["158d00027cdb02"]'}
2019-06-14 13:32:50 DEBUG (SyncWorker_8) [xiaomi_gateway] get_id_list << {'cmd': 'get_id_list_ack', 'sid': '7811dcb37d98', 'token': 'I20ocPgOiLMCvgiZ', 'data': '["158d00027cdb02"]'}
2019-06-14 13:32:50 DEBUG (SyncWorker_8) [xiaomi_gateway] _send_cmd >> b'{"cmd": "write", "sid": "7811dcb37d98", "data": {"mid": 20, "vol": 75, "key": "d03d3346b62ba60c36f534bfe1f19b62"}}'
2019-06-14 13:32:50 DEBUG (SyncWorker_8) [xiaomi_gateway] _send_cmd resp << {'cmd': 'write_ack', 'model': 'gateway', 'sid': '7811dcb37d98', 'short_id': 0, 'data': '{"rgb":0,"illumination":1292,"proto_version":"1.1.2"}'}
2019-06-14 13:32:50 DEBUG (SyncWorker_8) [xiaomi_gateway] write_ack << {'cmd': 'write_ack', 'model': 'gateway', 'sid': '7811dcb37d98', 'short_id': 0, 'data': '{"rgb":0,"illumination":1292,"proto_version":"1.1.2"}'}
2019-06-14 13:32:50 DEBUG (SyncWorker_2) [xiaomi_gateway] _send_cmd >> b'{"cmd": "write", "sid": "7c49eb17ec14", "data": {"mid": 20, "vol": 75, "key": "3e1b489edff52dfd8892e7ed88e42854"}}'
2019-06-14 13:32:50 DEBUG (SyncWorker_2) [xiaomi_gateway] _send_cmd resp << {'cmd': 'write_ack', 'model': 'gateway', 'sid': '7c49eb17ec14', 'short_id': 0, 'data': '{"rgb":0,"illumination":507,"proto_version":"1.1.2"}'}
2019-06-14 13:32:50 DEBUG (SyncWorker_2) [xiaomi_gateway] write_ack << {'cmd': 'write_ack', 'model': 'gateway', 'sid': '7c49eb17ec14', 'short_id': 0, 'data': '{"rgb":0,"illumination":507,"proto_version":"1.1.2"}'}
2019-06-14 13:32:53 DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'switch', 'sid': '158d00027cdaa2', 'short_id': 41337, 'data': '{"status":"click"}'}

so the logger showed that someone pressed the switch (click) and it should ring the bell in two gateways (gateway A ‘7811dcb37d98’ and gateway B ‘7c49eb17ec14’). However the automation failed in gateway A with {“error”:“Invalid key”}’} but succeed in gateway B. This doesn’t make sense because there’s no error during startup regarding gateway A, and I can control the light in gateway A sucessfully…

Any opinion about this?

It’s important to differentiate sensors becoming unavailable and the gateway becoming unavailable. These are two different problems. Although both will probably be solved by using a conbee or zigbee2mqtt gateway.

There is many information about both Conbee/Deconz and Zigbee2MQTT on this forum. Both seem to work pretty well. I decided to go for Conbee as it could handle more clients at that time, not sure it that is still true.

Sure, I know those are two different problems. The main priority problem is the gateway becomes unavailable in HA but still available in Xiaomi Home app and network connection still works OK, which suggest something wrong in the communication between the gateway and HA…

I’ve searched around and maybe this issue and PR could be what I’m looking for. I’ll try to find some spare time to try implementing the code revision in xiaomi_aqara component and will report back whether that fixes my issue…

Here’s the issue : https://github.com/home-assistant/home-assistant/issues/20329
And here’s the suggested PR : https://github.com/home-assistant/home-assistant/pull/21116