Xiaomi Gateway - no online solution works to enable it

Hi, I’m very new to HASS but did a lot of reading before starting to setup my home automation.
I’ve installed hass on Pi 3b+, and successfully got Yeelight working without any issues. Unfortunately that wasn’t the case with xiaomi gateway. Here’s what I tried so far:

  • disabling/enabling LAN
  • resetting the key
  • in config adding/removing/mixing combinations of mac, key, interface (even set the discovery rate to 50)
  • reset the gateway twice, even created a new xiaomi account (app set to region Mainland China)
  • opened port 9898 on my router (for ip listed in network info on the app)

If I don’t include the interface ip I always get an error ‘component failed to initialize’ / ‘No gateway discovered’. When interface command is included I get:

Error during setup of component xiaomi_aqara

Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/setup.py”, line 148, in _async_setup_component
component.setup, hass, processed_config) # type: ignore
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/xiaomi_aqara.py”, line 130, in setup
xiaomi.discover_gateways()
File “/usr/local/lib/python3.6/site-packages/xiaomi_gateway/init.py”, line 43, in discover_gateways
_socket.bind((self._interface, 0))
OSError: [Errno 99] Address not available

The one thing I just can’t understand is howcome when I just have a fresh configuration (ie no editing) the ‘discovery’ automatically finds xiaomi-aqara in the ‘overview’ tab (it’s listed on the top as ‘invalid config’)

Hub info:
version code: 208
model: lumi.gateway.v3
fw_ver: 1.4.1_161.0143

Would really appreciate any help as I literally have no idea what else I can do.

Hi, how does your xiaomi section in your configuration.yaml looks like?

Below my config, with only the mac address & xiaomi key:

xiaomi_aqara:
  discovery_retry: 5
  gateways:
    - mac: !secret xiaomi_mac
      key: !secret xiaomi_key

I specified the mac address without colons, like this format: 7c49eb1a2b3c

Just to be sure: the key is not the password of your Xiaomi account. Were you able to access the developer mode in the Mi Home app to generate the key? If not, you could follow these instructions: https://www.domoticz.com/wiki/Xiaomi_Gateway_(Aqara)

Are your xiaomi gateway and your Home Assistant in the same network subnet? Can you ping the xiaomi gateway from your HA?

You could turn on debug logging by adding the lines below to your configuration.yaml:

logger:
  default: warn
  logs:
    xiaomi_gateway: debug

I hope this is helpful!

Thanks for your reply, I used the correct mac and key formats, here’s my setup in configuration file (also tried with and without mac):

xiaomi_aqara:
discovery_retry: 10
gateways:
- mac: 7811dcf9axxx
key: 0kw6y4asdccxxxxx

The gatewar and HA are connected to the same wifi.

Added the debug you suggested, but that doesn’t seem to trigger anything in dev logs

logger:
default: warn
logs:
xiaomi_gateway: debug

Also tried to add the ping, but apparently I’m doing something wrong:

xiaomi_aqara:
-platform: ping
host: 192.168.1.20

Getting following error with this code (the ip is correct, checked it on my router):

Invalid config for [xiaomi_aqara]: expected a dictionary for dictionary value @ data[‘xiaomi_aqara’]. Got [OrderedDict([(‘platform’, ‘ping’), (‘host’, ‘192.168.1.20’)])]. (See /config/configuration.yaml, line 99). Please check the docs at Xiaomi Gateway (Aqara) - Home Assistant

Edit:
Tried also completely removing the xiaomi_aqara code, getting exactly the same error from auto discovery:

Setup failed for xiaomi_aqara: Component failed to initialize.
No gateway discovered

It’s like my the config I apply doesn’t do anything.

Hi Aloowak.

Sometimes it’s very frustrating. I know that.

Could you please use the preformatted text

like this

Paste your config, than select it and than click on that sign </>

My first thoughts:

  1. Are you connected to a guest network? (The devices might not be allowed to communicate)
  2. my key looks like this 24529AB101727568 only numbers and CAPITAL LETTERS

my config looks like this

xiaomi_aqara:
  discovery_retry: 5
  gateways:
    - key: 24529AB101727568

if you format it like that

xiaomi_aqara:
 discovery_retry: 5
    gateways:
   - key: 05849AB101724907

you might get an error (not correct amount of spaces)

2 Likes

Hi totolino, thank you for the suggestions, unfortunately that didn’t work as well.

Both devices are on home wifi network (vodafone UK), everything works perfectly fine on my phone, not sure what kind of setting I should be looking for on the router, I opened the port 9898 for the gateway IP but that doesn’t seem to be doing anything.

Either I’m an idiot or there’s something wrong with my gateway… anyways here are the screenshots from my phone and the code in configurator (tried both with and without mac):

1 Like

Hi.

Did you try to create a new API Key?

If discovery finds it, it might not be a router problem.

and did you read the docs ? there is a part with connection problems and how to fix them on the bottom.

Password is not the key! U must follow the instructions

Yes, I generated like 10 new keys.
Tried all the options listed:

  • LAN access enabled (as visible on the screen)
  • no firewall, running it from Pi image downloaded from HA website
  • router seems to be supporting multicast (default vodafone UK router)
  • removed/added/added blank mac
  • discovery always set to 10
  • reset LAN access several times
  • hard reset gate two times, even linked it with new xiaomi account just in case
  • don’t believe any other options listed are applicable for me

I’m changing the router (the one I have is rubbish anyway), will arrive tomorrow so will post an update whether that worked.

@thundergreen - what do you mean password is not the key? I followed all the instructions and that’s exactly what they say:

Follow the setup process using your phone and Mi-Home app. From here you will be able to retrieve the key (password) from within the app following this tutorial.

In newer versions of the gateway, its not in chinese and says password
in older versions it was in chinese.

Your router may provide internet access to your devices, but can they connect to each other?

You could try to ping your Xiaomi gateway from the Hassio command line with the ping command.

There is also the possibility it doesn’t work, depending on the hardware and firmware version.

But the jury is still out it seems.

I find that sometimes reinstalling hassio helps.

I also realise that refreshing the key sometimes causes more harm that help. The app somehow changes back to the first set of keys.

@tedsluis I’m afraid I don’t know how to run the ping command, tried the following

device_tracker:
  - platform: ping
    hosts:
      hostone: 192.168.1.20 

and got the error

Unable to load /config/known_devices.yaml: Config file not found: /config/known_devices.yaml

@walaj thanks a lot for sharing this! seems like my case is exactly the one described, very disappointing… I might grab another gateway and enable lan before any fw updates

@Don_Lim I tried installing hass.io on my old pi 1b but had exactly the same results as on pi 3b+

(sorry for double post but ‘new users can only mention 2 users in a post’)

@Aloowak I meant linux ping command, not the device_tracker :wink:

Do you have SSH access to your HA? If so you can enter the linux or hassio commandline and type ping 192.168.1.20

If you don’t have SSH access to hassio yet, you could install it

@tedsluis thanks for the link, enabled SSH and ping’ed the gateway, all fine (4-8ms).

I got the new router and nothing changed (as expected).
Connected without any issues to yeelight, xiaomi vacuum and dyson fan.

I guess it’s the fw issue @walaj mentioned before. Will buy a new gateway and open Lan before running any updates, hopefully this will solve the problem.

My friend just meet the same problem as you described here. No solution yet.

The source code was not changed since v0.81 https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/xiaomi_aqara.py

On second thought, I noticed the system time was not correct, I’ll ask him to sync the datetime and try again.

There is a know issue with firmware 1.4.1_161.0143 and compatibility with HA. Is has been discussed in many other threads on the forums for some time now.

Basic rule of thumb I have with anything that connects to HA is, if it is working, do not update it unless it is necessary because of a breaking change or adds a significant feature to the product that you can not live without.

Any news or tips regarding these issues?
Anyone knows a way to downgrade the gateway firmware?
I’m seeing a lot of issues with people who ordered recently …

I had a similar problem a while back and it turned out to be my Bell 2000 router. It did not support multicast very well. I changed it to a different router (TP-Link) that had multicast support and the Xiaomi gateway has worked flawlessly since then.

1 Like