Xiaomi_aqara issue

I’ve been having trouble with my xiaomi gateway. I’ve read through all the issues and other topics on here and nothing has helped. I have

  1. Tried putting the MAC as upper case
  2. Tried regenerating the key (in Android)
  3. Tried putting in the host and the interface (also tried without)

Its seeing the gateway, and I can toggle the gateway light on and off. So its being recognized. It even see’s the two sensors. A motion detection, and a ‘cube’. All are working via the Android app, none via HA. And none of my automations execute for either the cube or motion detection (they do register via the Android app as seeing motion or moving the cube)

Seeing this error in the logs over and over, despite having added the options listed below
2018-09-16 14:25:58 ERROR (Thread-29) [xiaomi_gateway] Unknown gateway ip 192.168.xx.xx

(that IP is the IP of the Intel Nuc its running on)

Interesting note, if I trigger one of my automations waiting on the cube or the motion sensor I see this in the logs. This is the only time the error shows up. And yes, I’ve re-generated the key about 5 times so far using a Android device

2018-09-16 14:25:03 ERROR (SyncWorker_8) [xiaomi_gateway] Got error element in data {“error”:“Invalid key”}

My config:

xiaomi_aqara:
  interface: 192.168.xx.xx
  discovery_retry: 10
  gateways:
  - host: 192.168.xx.xx
    mac: XXXXXXXXXXXX
    key: verysecretkeyhereofcourse

Running HA version 0.75.3 on a Intel Nuc

this is my setup for my hub,

xiaomi_aqara:
  discovery_retry: 10
  gateways:
    - mac: 78:11:dc:b8:d8:ee
      key: 6B44B5E2EED9430B

You dont need to much for the setup, so maybe give that a try, but with your information.

Yes, those are the very first settings I tried. I’m still getting the same error when I use only those settings.

thanks

see this posting for details on checking networking…

and maybe PyXiaomiGateway Problem: {"error":"Invalid key"}

I had a similar problem with mine and I was using an iPhone to generate the key - it gave me a key but it just didn’t work. Some people have reported success with an iPhone but not me. I don’t have an android, so in the end I downloaded BlueStacks android emulator and installed Mi Home and gotthe key and it magically started working.

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