Xiaomi_aqara issue

Try to Nmap your gateway to see whether the ports needed are open

Nmap - sU 192.168.x.x -p 9898,4321

Mine is the simplest possible and works

xiaomi_aqara:
 discovery_retry: 5
 gateways:
   - key: xxxxxxxxxxxxxxxxx

Your spacing is wrong after gateways:. Add two extra spaces on every line below that one.

As @j.assuncao said, your spacing is wrong, just copy and paste the code I put above, and change the MAC and Key to your’s and as long as it isn’t faulty, should be good to go.

1 Like

Here’s my config

xiaomi_aqara:
  discovery_retry: 10
  gateways:
    - mac: XXXXXXXXXXXX
      key: somesupersecretkey   

Restarted and still having the exact same symptoms as before

you may have a faulty gateway then, have a look over this thread,

seem’s @hoedha had one, and it worked all ok in the mi home app, but not with HA.

@Urge2Automate please clarify whether you can see and control the Xiaomi Gateway from HA? My problem was that I can’t even see the gateway in the HA. Your error log is different than mine, and I think you’re in a better position than me.

So please let us know more detailed information of your error :

  1. What is your wireless router? Are you sure it supports multicast?
  2. Make sure you’re running HA and Xiaomi Gateway in one subnet.
  3. What is your result when performing nmap, tcpdump, and ngrep like below?

nmap -sU -Pn 192.168.0.108 -p 9898,4321

ngrep port 9898

tcpdump -A -i eno1 udp port 4321 or udp port 9898

Also, enable logger in conf.yaml like below to get more detailed logs :

logger:
  default: warn
  logs:
    homeassistant.components.xiaomi_aqara: debug
    homeassistant.components.sensor.xiaomi_aqara: debug
    homeassistant.components.switch.xiaomi_aqara: debug
    homeassistant.components.binary_sensor: debug
    xiaomi_gateway: debug

While Xiaomi gateway and sensors are very affordable, but I found the quality control is a bit letdown. For example, I have 3 motion sensors (aqara version), 2 of them works fine, but the last one is erratically reporting motion when no one around, and reporting clear when clearly my hand is waiving in front of it…

Here’s the debug that I got on start

2018-09-18 16:12:39 DEBUG (SyncWorker_9) [homeassistant.components.xiaomi_aqara] Expecting 1 gateways
2018-09-18 16:12:39 INFO (SyncWorker_9) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 1)
2018-09-18 16:12:39 INFO (SyncWorker_9) [xiaomi_gateway] Xiaomi Gateway 7811dcba9c1d configured at IP 192.168.50.16:9898
2018-09-18 16:12:39 DEBUG (SyncWorker_9) [xiaomi_gateway] _send_cmd >> b'{"cmd":"read","sid":"7811dcba9c1d"}'
2018-09-18 16:12:39 DEBUG (SyncWorker_9) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_ack', 'model': 'gateway', 'sid': '7811dcba9c1d', 'short_id': 0, 'data': '{"rgb":0,"illumination":1292,"proto_version":"1.1
.2"}'}
2018-09-18 16:12:39 INFO (SyncWorker_9) [xiaomi_gateway] Discovering Xiaomi Devices
2018-09-18 16:12:39 DEBUG (SyncWorker_9) [xiaomi_gateway] _send_cmd >> b'{"cmd" : "get_id_list"}'
2018-09-18 16:12:40 DEBUG (SyncWorker_9) [xiaomi_gateway] _send_cmd resp << {'cmd': 'get_id_list_ack', 'sid': '7811dcba9c1d', 'token': 'pNXmm70sBBu5iavr', 'data': '["158d0002790351","158d0001d58fa0"]'}
2018-09-18 16:12:40 INFO (SyncWorker_9) [xiaomi_gateway] Found 3 devices
2018-09-18 16:12:40 DEBUG (SyncWorker_9) [xiaomi_gateway] _send_cmd >> b'{"cmd":"read","sid":"158d0002790351"}'
2018-09-18 16:12:40 DEBUG (SyncWorker_9) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_ack', 'model': 'sensor_cube.aqgl01', 'sid': '158d0002790351', 'short_id': 6944, 'data': '{"voltage":3025}'}
2018-09-18 16:12:40 DEBUG (SyncWorker_9) [xiaomi_gateway] Registering device 158d0002790351, sensor_cube.aqgl01 as: binary_sensor
2018-09-18 16:12:40 DEBUG (SyncWorker_9) [xiaomi_gateway] _send_cmd >> b'{"cmd":"read","sid":"158d0001d58fa0"}'
2018-09-18 16:12:40 DEBUG (SyncWorker_9) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_ack', 'model': 'motion', 'sid': '158d0001d58fa0', 'short_id': 7385, 'data': '{"voltage":3015}'}
2018-09-18 16:12:40 DEBUG (SyncWorker_9) [xiaomi_gateway] Registering device 158d0001d58fa0, motion as: binary_sensor
2018-09-18 16:12:40 DEBUG (SyncWorker_9) [xiaomi_gateway] _send_cmd >> b'{"cmd":"read","sid":"7811dcba9c1d"}'
2018-09-18 16:12:40 DEBUG (SyncWorker_9) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_ack', 'model': 'gateway', 'sid': '7811dcba9c1d', 'short_id': 0, 'data': '{"rgb":0,"illumination":1292,"proto_version":"1.1
.2"}'}
2018-09-18 16:12:40 DEBUG (SyncWorker_9) [xiaomi_gateway] Registering device 7811dcba9c1d, gateway as: sensor
2018-09-18 16:12:40 DEBUG (SyncWorker_9) [xiaomi_gateway] Registering device 7811dcba9c1d, gateway as: light
2018-09-18 16:12:40 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.nest
2018-09-18 16:12:45 INFO (SyncWorker_9) [xiaomi_gateway] Gateway discovery finished in 5 seconds
2018-09-18 16:12:45 INFO (SyncWorker_9) [xiaomi_gateway] Creating Multicast Socket
2018-09-18 16:12:45 DEBUG (SyncWorker_9) [homeassistant.components.xiaomi_aqara] Gateways discovered. Listening for broadcasts
2018-09-18 16:12:45 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.xiaomi_aqara
2018-09-18 16:12:50 ERROR (Thread-29) [xiaomi_gateway] Unknown gateway ip 192.168.50.42
2018-09-18 16:13:00 ERROR (Thread-29) [xiaomi_gateway] Unknown gateway ip 192.168.50.42

I haven’t been able to test the multicast yet. I’m running open-wrt (LEDE) router and didn’t find an easy explanation of enabling multicast. But did check nmap

sudo nmap -sU -Pn 192.168.50.16 -p 9898,4321

Starting Nmap 7.60 ( https://nmap.org ) at 2018-09-19 11:52 PDT
Nmap scan report for 192.168.50.16
Host is up (0.15s latency).

PORT     STATE         SERVICE
4321/udp open|filtered rwhois
9898/udp open          monkeycom
MAC Address: 78:11:DC:BA:9C:1D (Xiaomi Electronics,co.)

I had a problem with one of my door sensors, it arrived with a dead battery, so bought a new one, it was dead in two days again, so had to go through a dispute on the lovely Chinese site, but got my money back easy enough and just ordered another one, and that was fine. Just make sure you buy through somewhere that has an easyish return process

Same problem here. Since a few days HA is not working properly with the hub. It is recognized and set up by HA, but the “Unknown gateway ip 192.168.1.200” appears constantly, and always appears just when I tail -f the log file and press a mapped physical button linked to the hub. No action is triggered. Curiously, 192.168.1.200 is the ip address of the host where HA is running; it’s not the hub ip (however, it’s recognized with the correct ip, 192.168.1.132).
When I restart HA and after hub is set up, HA receives data from sensors and is able to store in a database, but some hours later (2? 3?) HA complaints and sensors change to “unavailable” state, hence, no data is stored -> I have to restart HA again. Restarting HA only fixes gathering sensors data. Actions and automations are never triggered.
I have tcpdumped interfaces and I can see traffic from the hub, reaching my host, with the corresponding sensor and switches data. Apparently, everything is fine.
The only “strange” setup in my environment, is that I’m using linux software bridge utils (bridge-utils package). I have a br0 interface, with p4p1 and eth0 interfaces connected. p4p1 interface is where traffic is received from the hub.

brctl show:
br0 8000.00e05331834b no eth0
p4p1

however, muliticast socket and network traffic seem to be correct (224.0.0.50 is binded to br0)

Running HA 0.92.2 under python virtual environment
Linux mint 18, kernel 4.4.0
Tried previous mentioned fixes, but no change at all.

Any help is appreciated.

Thanks

Being able to see sensors but being able to control stuff is generally a sign that the key is not present or wrong.

Hi.
Same :frowning:

Any suggestion?

I have a similar problem, both ports tested open on both gateways with nmap. But I still get these messages in my logs along with a heap of bulb closed connection errors. However, everything still seems to be working just fine, lights are controlled via node red with xiaomi sensors etc etc
and yes, my router supports multicast and it is enabled (unifi gateway)

Cannot connect to Gateway
December 5, 2019, 11:08 PM components/xiaomi_aqara/binary_sensor.py (ERROR) - message first occurred at December 5, 2019, 7:54 PM and shows up 21 times

As you can see it occurs 21 times in a short span of ~8 hours. any suggestions?

My Xiaomi gateway arrived this week, and was setup and working in minutes, using an iPhone. I was skeptical until I actually succeeded going through the process the first time. I would seriously double-check @nickrout 's message above. Be certain your gateway’s MAC address is entered in lower-case without colon separators, and the key value from the Mi app screen 100% matches what you entered in configuration.yaml.

yeah done all that. It works fine, just with a lot of messages in logs intermittently

It looks like a network issue frankly. Your wifi may be dodgy.

Don’t forget too that mixing wifi and zigbee is tricky, they both use 2.4GHz spectrum. As someone said in another thread, its physics!

I should mention, I ordered my gateway from eBay, and the CN-to-US ‘universal plug adapter’ shipped with it was an extremely poorly-built item. It would not remain plugged in, due to lack of friction/contact. The US plug blades were too thin and not spaced nearly correctly. Even being quite careful with it, the gateway was prone to dying and restarting frequently. I immediately ordered and swapped in a better plug adapter, and now it’s rock-solid reliable. It is in the same room with line-of-sight to a wireless access point, though.

I am lucky, NZ sockets take chinese plugs.

If I have to choose a foreign plug, I go for UK plugs and use a UK - NZ adaptor. They are bulkier than US plugs, but are very “positive” in their connectivity, much better than the US rubbish.

uk plug - the most over engineering power plug in the universe :smiley:

I am lucky, NZ sockets take chinese plugs.

I assume you have the same issue we have - the chinese plugs are actually upside down, and so frequently block the socket swtich…

btw, I made a posting about how to do this without the gateway and its only about $25