core: Xiaomi Gateway (Aqara) integration fails to discover Gateway

The problem

Hi there, trying to use the Xiaomi Gateway (Aqara) integration that supports all my sensors and my Gateway. The integration " Xiaomi Gateway (Aqara)" cannot be setup due to the fact that it doesn’t discover the Gateway. When I select the integration, the prompt asks:

"Xiaomi Aqara Gateway Connect to your Xiaomi Aqara Gateway The network interface to use “any”

Tried to use “any” and get the error: “Failed to discover a Xiaomi Aqara Gateway, try using the IP of the device running HomeAssistant as interface” or my HA IP address and get the error: “Unknown error occurred” and “Failed to discover a Xiaomi Aqara Gateway, try using the IP of the device running HomeAssistant as interface” or the Gateway’s IP address and get the error: “Unknown error occurred” and “Failed to discover a Xiaomi Aqara Gateway, try using the IP of the device running HomeAssistant as interface”

Can you please provide help with the issue? If I can help, I would be happy to contribute to the solution of the issue. Many people have the same issue and trying to find out a way to solve it. Some have mentioned that the HA 0.111 was the last version that the integration worked as it should. I cannot verify that as I’m fairly new to HA.

@danielhiversen @syssi

Sensors: Mi motion sensor (Model: lumi.sensor_motion.v2) Mi Door/Window Sensor (Model: lumi.sensor_magnet.v2) Mi Wireless button (Model: lumi.sensor_switch.v2) Gateway: lumi.gateway.v3-MW300 by Xiaomi Firmware: 1.4.1_176 (Latest)

Environment

  • Home Assistant Core release with the issue: Home Assistant 0.113.3
  • Last working Home Assistant Core release (if known): -
  • Operating environment (OS/Container/Supervised/Core): VM (fresh install) with official QCOW2 image
  • Integration causing this issue: Xiaomi Gateway (Aqara)
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/xiaomi_aqara/

Problem-relevant configuration.yaml

No custom .yaml, all in UI

Traceback/Error logs


Additional information

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 105 (24 by maintainers)

Most upvoted comments

            {
                "connection_class": "local_push",
                "data": {
                    "host": "192.168.1.22",
                    "interface": "any",
                    "key": "b22jb533kg1vgqx2",
                    "mac": "78:7c:2e:c3:cc:82",
                    "port": 9898,
                    "protocol": "1.1.2",
                    "sid": "787c2ec3cc82"
                },
                "domain": "xiaomi_aqara",
                "entry_id": "9d1bbfcef9dd4c47ab58b000fd55e711",
                "options": {},
                "source": "zeroconf",
                "system_options": {
                    "disable_new_entities": false
                },
                "title": "Xiaomi Aqara Gateway",
                "unique_id": "78:7c:2e:c3:cc:82",
                "version": 1
            }

78:7c:2e:c3:cc:82 - MAC address in lower case 787c2ec3cc82 - MAC address in lower case without “:”. b22jb533kg1vgqx2 - gateway password from MiHome application (About -> Wireless communication protocol - > Password) 192.168.1.22 - IP address of the gateway 9d1bbfcef9dd4c47ab58b000fd55e711 - I don’t know exactly, I think it’s just a random GUID for Home Assistant to link the gateway configuration and its devices. During the test, left one value for both gateways. If you use two gateways at once, the values should be different.

After changing the “core.config_entries” file you should restart Home Assistant.

Hi all,

Any updates regarding the issue? Any suggestions to try?

@syssi @Danielhiversen @starkillerOG

There are lots of people that cannot make the Aqara integration work on the latest versions.

See more here: Home assistant Forum regarding Aqara integration issues

Thanks

hi i did the maual change of the core file and it started to work but after a 3 hours the smoke ,gaz, leak sensors stopped and the temp continue to work fine. after a reset they work fir another 3 hours. ( the ports to the gw is open )

I tried to manually add another gateway again and it worked. image

After that, the other one worked too.

Still does not work through the interface, there is an error in the log:

Logger: xiaomi_gateway
Source: /usr/local/lib/python3.8/site-packages/xiaomi_gateway/__init__.py:175
First occurred: 7:04:40 PM (3 occurrences)
Last logged: 7:05:00 PM

Unknown gateway ip 192.168.1.24

image

Xiaomi_Miio uses direct TCP connection to the gateway. Xiaomi_aqara uses UDP multicast address for communication with the gateway. Do you have a setting in the router to allow UDP multicast? Furthermore you can try filling in the IP of the device running HomeAssistant instead of “any”

@techinpark Gateway -> “…” -> About -> Wireless communication protocol -> Password. image If there is no such item, you have to click 2.77.1 several times until it appears.

@techinpark I looked in my app and indeed it is updated and I can’t find it anymore. If you figure it out, please also let us know so we/you can update the documentation.

I think it is possible to retrieve the password through python-miio: https://github.com/rytilahti/python-miio/blob/7771f45f9b1724a5ecc632b591e83a667043f83e/miio/gateway.py#L351 (I wrote part of that code) But it is a bit of a hassel to do it that way…

@sj3fk3 This is caused by a lossy/bad wireless connection and/or poor wifi repeaters. Try to improve your wifi network or the position of your gateway.

I would like to challenge that assumption:

Screenshot 2020-09-28 at 20 56 35

The Xiaomi Gateway is in the living room, any more wifi coverage and it would start to glow without any mains…

Hi all,

3 weeks ago I purchased a Conbee 2 from Amazon. 3 days ago I installed it with Deconz and all sensors are working flawlessly, without any issues, fast and reliably.

I’m currently setting up an alarm system that uses all the sensors to arm home when away or at night.

I do not own a Xiaomi Gateway anymore as I sold it.

Please keep up the good work and I hope that you will ultimately find a solution.

Thanks again for everything.

Maybe this helps someone like me. I’ve been trying to get my Agara Gateway working since 0.112. All the tricks here were tried with no luck. I have been using older agara integration as custom_component until I noticed I couldn’t install HACS either. In its all simplicity, I had Firefox Adblock on when using my HA. Disabling Adblock and Agara & HACS installation went smoothly as everything earlier. “Sometimes simplest solutions are best”

Hi All

I’ve the same issue with Xiaomi Aqara integration.

arch armv7l
chassis embedded
dev false
docker true
docker_version 19.03.11
hassio true
host_os HassOS 4.12
installation_type Home Assistant OS
os_name Linux
os_version 4.19.127-v7l
python_version 3.8.3
supervisor 235
timezone Asia/Jerusalem
version 0.114.4
virtualenv false

Hi dears!

I’ve the same issue with Xiaomi MIio integration. After updating core version higher than 0.112.4 it is not working. In the same time, I’ve no issues with integration of Xiaomi Aqara Gateway.

Screenshot 2020-08-03 18 09 39 Screenshot 2020-08-03 19 32 59 Screenshot 2020-08-19 12 58 54 Screenshot 2020-08-03 19 23 57

I’d appreciate to recieve your kind support. System info: arch | armv7l chassis |   dev | false docker | true docker_version | 19.03.11 hassio | true host_os | Raspbian GNU/Linux 10 (buster) installation_type | Home Assistant Supervised os_name | Linux os_version | 4.19.118-v7+ python_version | 3.8.3 supervisor | 235 timezone | Europe/Moscow version | 0.114.4 virtualenv | false

Hello guys, I have exactly same problems mentioned above, and try everything I can do but not working. And now It is FINALLY SOLVED! This is working for me but could not be working for other cases.

SOLUTION: Delete ‘Aqara Cube’ and ‘wireless wall switch’ on Mi home from your Xiaomi Gateway.

The problem was that some Aqara devices have compatibility issue with the 0.112 or later system. For my case, I did Factory reset my Xiaomi Gateway and immediately my hassOs recognized new Xiaomi Gateway and added it with no any problem. But after add my all devices, suddenly all Zigbee devices are unavailable on my hassOs. So I checked every my devices and I finally found out the devices which causes the problem. For my case, It was Aqara Cube and wireless xiaomi wall switch (double locker). These two devices previously worked without any problems. Other devices could be problem but my case, only that two devices are problem.

System information Home Assistant 0.114.3 arch | armv7l chassis | embedded dev | false docker | true docker_version | 19.03.11 hassio | true host_os | HassOS 4.12 installation_type | Home Assistant OS os_name | Linux os_version | 4.19.127-v7 python_version | 3.8.3 supervisor | 235 timezone | Asia/Seoul version | 0.114.3 virtualenv | false

@manosioa I can tell becasue it’s enabled in the Unify controller that administers the whole wifi network as per accelle17 comments. Unifi APs can connect through mesh as well as wired, and that was the only difference. The first two gateways are wireless but to wired APs. The third, not working gateway is connecting to an AP which connected via wireless uplink (Mesh). However it was also the last gateway I tried to add.

Yeah, found this thread and I’ve had this issue for the past few versions. I just upgraded to 0.114.0 and problems remain, with the same dialogues and messages as described above. My variation on this is I have 3 hubs - two have been discovered and configured perfectly for Aqara and Miio, and the sensors discovered for both these hubs. However the third has configured correctly for Miio only, and the balance of sensors on that 3rd hub remain undiscovered. I also have a simple unifi network, and multicasting is enabled. In fact, these hubs worked perfectly with manual settings in earlier versions. Now dead 😦 I commented in another thread, that the only difference with the non-discovered hub is that it’s on a wireless uplink to an AP, not wired, but I wouldn’t think that would make a difference, but who knows. They are otherwise on the same network.

same here even on 0.114.1. I have unifi with multicast and igmp proxy enabled and I’m able to configure the gateway before 0.112 on the config. I only use the gateway for the sounds though, not as zigbee gateway. The workaround for me right now is to use the xiaomi_aqara 0.111.3 package as custom component.

Here’s the error when trying to add xiaomi aqara using the integration:

ERROR (MainThread) [aiohttp.server] Error handling request Traceback (most recent call last): File “/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py”, line 418, in start resp = await task File “/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py”, line 458, in _handle resp = await handler(request) File “/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py”, line 119, in impl return await handler(request) File “/usr/src/homeassistant/homeassistant/components/http/real_ip.py”, line 39, in real_ip_middleware return await handler(request) File “/usr/src/homeassistant/homeassistant/components/http/ban.py”, line 73, in ban_middleware return await handler(request) File “/usr/src/homeassistant/homeassistant/components/http/auth.py”, line 127, in auth_middleware return await handler(request) File “/usr/src/homeassistant/homeassistant/components/http/view.py”, line 129, in handle result = await result File “/usr/src/homeassistant/homeassistant/components/config/config_entries.py”, line 145, in post return await super().post(request, flow_id) File “/usr/src/homeassistant/homeassistant/components/http/data_validator.py”, line 60, in wrapper result = await method(view, request, *args, **kwargs) File “/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py”, line 106, in post result = await self._flow_mgr.async_configure(flow_id, data) File “/usr/src/homeassistant/homeassistant/data_entry_flow.py”, line 153, in async_configure result = await self._async_handle_step(flow, cur_step[“step_id”], user_input) File “/usr/src/homeassistant/homeassistant/data_entry_flow.py”, line 201, in _async_handle_step result: Dict = await getattr(flow, method)(user_input) File “/usr/src/homeassistant/homeassistant/components/xiaomi_aqara/config_flow.py”, line 90, in async_step_user self.selected_gateway = await self.hass.async_add_executor_job( File “/usr/local/lib/python3.8/concurrent/futures/thread.py”, line 57, in run result = self.fn(*self.args, **self.kwargs) File “/usr/local/lib/python3.8/site-packages/xiaomi_gateway/init.py”, line 227, in init resp = self._send_cmd(cmd) File “/usr/local/lib/python3.8/site-packages/xiaomi_gateway/init.py”, line 330, in _send_cmd _socket.sendto(cmd.encode(), (self.ip_adress, self.port)) socket.gaierror: [Errno -3] Try again

NB - I tried substituting the IP address instead o ‘any’ as per the suggestioin above, and got an error : image

Yeah, found this thread and I’ve had this issue for the past few versions. I just upgraded to 0.114.0 and problems remain, with the same dialogues and messages as described above. My variation on this is I have 3 hubs - two have been discovered and configured perfectly for Aqara and Miio, and the sensors discovered for both these hubs. However the third has configured correctly for Miio only, and the balance of sensors on that 3rd hub remain undiscovered. I also have a simple unifi network, and multicasting is enabled. In fact, these hubs worked perfectly with manual settings in earlier versions. Now dead 😦 I commented in another thread, that the only difference with the non-discovered hub is that it’s on a wireless uplink to an AP, not wired, but I wouldn’t think that would make a difference, but who knows. They are otherwise on the same network.

Try the latest beta of HomeAssistant and update the gateway to the latest firmware, it schould work then

I have now started the test server again (0.113.3) to take a screenshot. The gateway that I added manually stopped working (devices became unavailable). At the same time, everything works on the production server (0.111.4). Apparently, the way the gateway was manually added to “core.config_entries” cannot be considered reliable.

image

@manosioa lumi.vibration.aq1 lumi.sensor_switch.v2 lumi.sensor_wleak.aq1 lumi.sensor_magnet.aq2 lumi.sensor_magnet.v2 lumi.plug.v1 lumi.sensor_smoke.v1 image

In your case did it discover the devices on your Gateway?

Yeah. One gateway was without devices. Only light was found on this gateway, maybe something else. There were many devices on the second gateway. Everyone was detected and working.

I have the same problem. I have two identical gateways lumi.gateway.v3. They’re on the same subnet as Home Assistant. I was able to configure one of the gateways once. But during the experiments, I removed it and can’t add it anymore. I get the same error “Zeroconf”. I kept the settings from core.config_entries when I could add the gateway.

Now if you manually insert settings into core.config_entries, the gateway works. If I adjust the settings in core.config_entries to a second gateway, the gateway works too. I couldn’t add a second gateway through the interface once.

In version 0.111.0, everything works.

@manosioa you can install WireShark on OpenWRT and capture traffic in network with fitlers for example port=udp

Hi all,

Are there any suggestions I could try to get the gateway working?

@syssi @Danielhiversen

Your help would be much appreciated