Xiaomi Gateway setup problems

I have been trying to setup my Xiaomi gateway along with all the cool sensors, for a few weeks now however without luck.

My setup:

What I have done:

  • Given a static IP to the gateway: 192.168.1.90
  • Pinged it image
  • Checked that port 9898 and 4321 are open Image
  • Enabled lan access and generating a password by following Domoticz.com
    • Tried using a One Plus 2
    • Tried using a Samsung galaxy (not sure model)
  • Enabling / Disabling IGMP Snooping in router settings
  • Enabling / Disabling MLD Snooping in router settings
  • Reseting the gateway by pressing the button for 30 secs and repeat the Domoticz guide
  • Rebooting router
  • Increasing discovery_retry to 25
  • Adding mac to the configuration
    • Formatted with colons separation all uppercase
    • Formatted without colons separation all lowercase
    • Formatted without colons separation all uppercase
  • Defining host with the ip of the gateway
  • Changing Profile->Settings->Region to “China”

With help from Vasiley#9091(Thanks!) from the discord channel, we managed to get some kind of result.

This is the used configuration that got me the furthest:

configuration.yaml

xiaomi_aqara:
  discovery_retry: 25
  gateways:
     - key: !secret xiaomi_gateway_key
       mac: !secret xiaomi_gateway_mac
       host: 192.168.1.90

secrets.yaml
xiaomi_gateway_mac: 7C49_________
xiaomi_gateway_key: m34en__________

This is the log on boot: home-assistant.log
Whats worth noticing is that it does not use all 25 attempts, and that it seems like it does discover the gateway.
Also when going into the services under developer tools in Home Assistant at start typing xiaomi, it suggest xiaomi_aqara with all the difference services like play_ringtone, add_device and so on. Clearly something worked… right?

However when trying to run any of the services like xiaomi_aqara.play_ringtone with the following data

{
   "gw_mac": "7C49_________",
   "ringtone_id": 8,
   "ringtone_vol": 50
}

The following line is printed in the log

DEBUG (SyncWorker_2) [xiaomi_gateway] Gateway Token was not obtained yet. Cannot send commands to the gateway.

Also I guess I would expect some binary sensors showing up in the States tab under Developer tools, but that’s not the case either.

I have been searched the internet for possibly solutions, spent multiple hours getting help from awesome people on the Discord, but still haven’t found a solution.

What could be problem and what should I try next?

EDIT:
I did update to the new firmware before I enabled lan access and generated the password. Also I’m able to add new sensors to the hub with the Mi Home App, and they are working just fine within the app.

the GW_mac does it contain uppercase or lowercase characters, mine is lowercase and works perfectly

have you also tried putting them directly in the config instead of the secrets file, just to rule that out also

Making it lower case when calling the service, yields the same result.
Also just pasted the secrets in directly, but also the same result :confused:

have you logged an issue on github? @syssi the components maintainer maybe able to assist there

there is this issue that is very similar

Not yet, I wanted to make sure that it wasn’t some kind of dumb mistake on my side, before proceeding to create a issue.

there is also this one

From my understanding, its a question whether or not the ports are open on the gateway. Which I think they are, as I mentioned, but I also did carry out a surgery and following the steps as told. Even though I didn’t check if the ports were open or closed before doing performing the operation(wops).

i was reading on the openhab website and they have done some extensive research there, it seems that in some cases.

  1. upgrading the firmware before enabling lan access can cause issues
  2. After gaining access to the internals of the gateway and monitoring the services, some gateway models (eu from the comments) there are no services being published. https://community.openhab.org/t/solved-openhab2-xiaomi-mi-gateway-does-not-respond/52963/188

I see that but I don’t quite understand, do they find a solution? The link you just posted, he simply concludes that the gateway aren’t listening on the port 4321 and 9898 right?

yes thats correct they are not listening on thos ports, and there is no solution. until an firwareupdate resolves

Damn that sucks, but very relieved to know that at least. No reason for me to fight with it until the next update then. Thanks a lot!

i would still log the issue on git hub, the issue described there may not be yours. the person who maintains the component will be able to assist more

1 Like

Good idea, I will do that then.

My memory usually fails for such details but I think there was a issue with the remote xiaomi server/region. Are you using mainland china?

Well if you mean the settings in Profile->Settings->Region then it was set to “China” and I don’t see any option to choose “mainland china” which is strange because I do remember seeing the option somewhere. So the might not be the correct place to set it.

Set my gateway and 2 smoke detectors up yesterday. Running fine in version 88.2. I am going to upgrade to the latest soon.

I am running Mi Home on an iPad. I created an account at mi.com. Logged into the app and set my location to China. Mainland China is no longer an option. Then I went add device. Choose the gateway from the list. Followed the install instructions. Then within the Gateway I added my secondary devices which are Smoke Detectors. Important that you add your devices once inside the gateway.

I then added the gateway info to Home Assistant using the One Gateway setup. I have the gateway light and the 2 smoke detectors listed on the states page. I did get a token error but you can generate a new one in the Mi Home app. Did that and updated my key in the configuration.yaml file. Restarted Home assistant and everything seemed fine.