Xiaomi gateway sensors not communicate with HA

Hi,
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.

My config:

xiaomi_aqara:
   discovery_retry: 10
   gateways:
     - mac: xxx
       key: xxx
       host: xxx

My host running from Qnap-> virtual station-> Ubuntu server -> docker hass io.
-Ubuntu server firewall disabled,

  • Ports opened: 9898 open, 4321 open/filtered

If i on the hassio debug logs, the result is:

019-12-01 08:46:09 DEBUG (SyncWorker_6) [homeassistant.components.xiaomi_aqara] Expecting 1 gateways
2019-12-01 08:46:09 INFO (SyncWorker_6) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 1)
2019-12-01 08:46:09 INFO (SyncWorker_6) [xiaomi_gateway] Xiaomi Gateway 04cf8ca9ddd1 configured at IP 192.168.1.135:9898
2019-12-01 08:46:09 DEBUG (SyncWorker_6) [xiaomi_gateway] _send_cmd >> b'{"cmd":"read","sid":"04cf8ca9ddd1"}'
2019-12-01 08:46:09 DEBUG (SyncWorker_6) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_ack', 'model': 'gateway', 'sid': '4cf8ca9ddd1', 'short_id': 0, 'data': '{"rgb":0,"illumination":1292,"proto_version":"1.1.2"}'}
2019-12-01 08:46:09 INFO (SyncWorker_6) [xiaomi_gateway] Discovering Xiaomi Devices
2019-12-01 08:46:09 DEBUG (SyncWorker_6) [xiaomi_gateway] _send_cmd >> b'{"cmd" : "get_id_list"}'
2019-12-01 08:46:09 DEBUG (SyncWorker_6) [xiaomi_gateway] _send_cmd resp << {'cmd': 'get_id_list_ack', 'sid': '04cf8ca9ddd1', 'token': 'i4Z2MCdM69zHE5EZ', 'data': '["158d0002c6c1aa","158d0002892c5c","158d0002892d1d","158d0002c5f3ff","158d0002c5f4d7","158d0002018b7a","158d000395b2e0"]'}
2019-12-01 08:46:09 INFO (SyncWorker_6) [xiaomi_gateway] Found 8 devices
2019-12-01 08:46:09 DEBUG (SyncWorker_6) [xiaomi_gateway] Discovery attempt 1/4
2019-12-01 08:46:09 DEBUG (SyncWorker_6) [xiaomi_gateway] _send_cmd >> b'{"cmd":"read","sid":"158d0002c6c1aa"}'
2019-12-01 08:46:09 DEBUG (SyncWorker_6) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_ack', 'model': 'switch', 'sid': '158d0002c6c1aa', 'short_id': 65170, 'data': '{"voltage":3022}'}
2019-12-01 08:46:09 DEBUG (SyncWorker_6) [xiaomi_gateway] Registering device 158d0002c6c1aa, switch as: binary_sensor
2019-12-01 08:46:09 DEBUG (SyncWorker_6) [xiaomi_gateway] Discovery attempt 1/4
2019-12-01 08:46:09 DEBUG (SyncWorker_6) [xiaomi_gateway] _send_cmd >> b'{"cmd":"read","sid":"158d0002892c5c"}'
2019-12-01 08:46:09 DEBUG (SyncWorker_6) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_ack', 'model': 'motion', 'sid': '158d0002892c5c', 'short_id': 61330, 'data': '{"voltage":3015}'}
2019-12-01 08:46:09 DEBUG (SyncWorker_6) [xiaomi_gateway] Registering device 158d0002892c5c, motion as: binary_sensor

etc… etc …

2019-12-01 08:46:11 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.yeelight
2019-12-01 08:46:15 INFO (SyncWorker_6) [xiaomi_gateway] Gateway discovery finished in 5 seconds
2019-12-01 08:46:15 INFO (SyncWorker_6) [xiaomi_gateway] Creating Multicast Socket
2019-12-01 08:46:15 DEBUG (SyncWorker_6) [homeassistant.components.xiaomi_aqara] Gateways discovered. Listening for broadcasts
2019-12-01 08:46:15 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.xiaomi_aqara
2019-12-01 08:46:19 ERROR (Thread-3) [xiaomi_gateway] Unknown gateway ip 192.168.1.191
2019-12-01 08:46:22 WARNING (MainThread) [homeassistant.setup] Setup of default_config is taking over 10 seconds.
2019-12-01 08:46:29 ERROR (Thread-3) [xiaomi_gateway] Unknown gateway ip 192.168.1.191
2019-12-01 08:46:39 ERROR (Thread-3) [xiaomi_gateway] Unknown gateway ip 192.168.1.191
2019-12-01 08:46:39 ERROR (Thread-3) [xiaomi_gateway] Unknown gateway ip 192.168.1.191
2019-12-01 08:46:39 WARNING (MainThread) [homeassistant.components.frontend] Overwriting integration hacs
2019-12-01 08:46:40 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 399, in _async_add_entity
    raise HomeAssistantError(msg)
homeassistant.exceptions.HomeAssistantError: Entity id already exists: sensor.hacs. Platform hacs does not generate unique IDs
2019-12-01 08:46:46 DEBUG (SyncWorker_3) [homeassistant.components.xiaomi_aqara.switch] Update data from hub: Plug_158d0002018b7a
2019-12-01 08:46:46 DEBUG (SyncWorker_3) [xiaomi_gateway] _send_cmd >> b'{ "cmd":"read","sid":"158d0002018b7a"}'
2019-12-01 08:46:46 DEBUG (SyncWorker_3) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_ack', 'model': 'plug', 'sid': '158d0002018b7a', 'short_id': 28118, 'data': '{"voltage":3600,"status":"off","inuse":"0","power_consumed":"1822","load_power":"0.00"}'}
2019-12-01 08:46:46 DEBUG (SyncWorker_3) [xiaomi_gateway] read_ack << {'cmd': 'read_ack', 'model': 'plug', 'sid': '158d0002018b7a', 'short_id': 28118, 'data': '{"voltage":3600,"status":"off","inuse":"0","power_consumed":"1822","load_power":"0.00"}'}
2019-12-01 08:46:46 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d0002018b7a: off>: {'voltage': 3600, 'status': 'off', 'inuse': '0', 'power_consumed': '1822', 'load_power': '0.00'}
2019-12-01 08:46:49 ERROR (Thread-3) [xiaomi_gateway] Unknown gateway ip 192.168.1.191

So the sensors not working :frowning:

I can switch the gateway lights, but the sensort not working.

This config is good, beacuse all worked yesterday. ( before blackout )

Please help me :frowning:

Do you have the Gateway assigned a fixed IP address from your router? Are you sure it has been assigned 192.168.1.191 after the power outage?

Also, you don’t need to hide internal IP addresses on the forum (eg: 192.168.1.191) as they are of zero use to any hacker

Hi,
The 192.168.1.191 ip is the Qnap ip.
The xiaomi gateway Ip is : 192.168.1.135
The hass io host IP is : 192.168.1.210
Ping successfully each other.

All fixed in router.

Try commenting out the MAC & host IP under the gateway config. I only have the key: in my config and it works. Just something to try…

Okey, strange because this config worked.
( config from first post )

No the config is:

xiaomi_aqara:
   discovery_retry: 10
   gateways:
       key: xyz

From log:

2019-12-01 09:42:42 INFO (SyncWorker_0) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 10)
2019-12-01 09:42:47 INFO (SyncWorker_0) [xiaomi_gateway] Gateway discovery finished in 5 seconds
2019-12-01 09:42:47 ERROR (SyncWorker_0) [homeassistant.components.xiaomi_aqara] No gateway discovered
2019-12-01 09:42:47 ERROR (MainThread) [homeassistant.setup] Setup failed for xiaomi_aqara: Integration failed to initialize.

From ui, the gateway is not available :frowning:

hmmm. The only other difference is that I don’t have the discovery_retry at all either.

Ok, i deleted the retry.

2019-12-01 09:50:42 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for shelly which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-12-01 09:50:42 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-12-01 09:50:48 DEBUG (SyncWorker_5) [homeassistant.components.xiaomi_aqara] Expecting 1 gateways
2019-12-01 09:50:48 INFO (SyncWorker_5) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 1)
2019-12-01 09:50:49 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.updater
2019-12-01 09:50:49 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.yeelight
2019-12-01 09:50:49 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.yeelight
2019-12-01 09:50:49 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.yeelight
2019-12-01 09:50:53 INFO (SyncWorker_5) [xiaomi_gateway] Gateway discovery finished in 5 seconds
2019-12-01 09:50:53 INFO (SyncWorker_5) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 2)
2019-12-01 09:50:58 WARNING (MainThread) [homeassistant.setup] Setup of xiaomi_aqara is taking over 10 seconds.
2019-12-01 09:50:58 INFO (SyncWorker_5) [xiaomi_gateway] Gateway discovery finished in 5 seconds
2019-12-01 09:50:58 INFO (SyncWorker_5) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 3)
2019-12-01 09:51:00 WARNING (MainThread) [homeassistant.setup] Setup of default_config is taking over 10 seconds.
2019-12-01 09:51:03 INFO (SyncWorker_5) [xiaomi_gateway] Gateway discovery finished in 5 seconds
2019-12-01 09:51:03 ERROR (SyncWorker_5) [homeassistant.components.xiaomi_aqara] No gateway discovered
2019-12-01 09:51:03 ERROR (MainThread) [homeassistant.setup] Setup failed for xiaomi_aqara: Integration failed to initialize.

Well the strange thing is that in your first post the log shows the gateway being configured at IP address 192.168.1.135 but then further down it’s like it’s trying to find out at 192.168.1.191 ? weird Have you tried power cycling the gateway since the blackout? (perhaps with your original config)

mm :frowning:

Not good .

 [xiaomi_gateway] Unknown gateway ip 192.168.1.191 

Maybe the router / virtual machine setup is wrong. I dont now really.

what it means in nmap result:
4321 open/filtered

This is OK ?

mmmm . uff…

Now, i see the log :

2019-12-01 19:24:50 DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'magnet', 'sid': '158d0002c5f3ff', 'short_id': 33422, 'data': '{"status":"open"}'}
2019-12-01 19:24:59 DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'magnet', 'sid': '158d0002c5f3ff', 'short_id': 33422, 'data': '{"status":"close"}'}

BUT!
In the sensor log, nothing :’(

Now the config is the following:

 xiaomi_aqara:
   discovery_retry: 10
   gateways:
     - mac: xxx
       key: xxx
       host: 192.168.1.135  --this is the xiaomi gateway
     - mac: xxx
       host: 192.168.1.191 -- this is the qnap nas, where i host the hassio
       disable: true

192.168.1.191 is disabled, because is the HOST, where the hassio live.
I dont know why discover this device.

:slight_smile: now… the best.
No error, no data, no log. Nothing!

config:
xiaomi_aqara:
   discovery_retry: 5
   gateways:
     - mac: xx
       key: xxx
       host: 192.168.1.135
     - mac: xxx
       key: fxx
       host: 192.168.1.191
       disable: true

Thanks xiaomi :frowning:

I will buy conbee 2 stick.
Xiaomi gateway… I’ll throw it in the trash

Why do you have your hass host (.191) listed as a xiaomi gateway?

Because the hassio try to parse as gateway. ( maybe )

The router ip is 192.168.1.1
The Qnap ip is 192.168.191
The hassio ip ( on qnap ) 192.168.1.210
The xiaomi gateway is 192.168.1.135

But the qnap is NOT an xiaomi gateway. logic.

Yep.
I know.

You only list your Xiaomi gateway there. Not random machines on your network.

Ok. If i not list that ip, i got error. ( I mentioned above, please read it )

And i checked the source code ( ? ) this line.
https://raw.githubusercontent.com/lazcad/homeassistant/master/components/xiaomi.py

 data = json.loads(data.decode("ascii"))
                gateway = self.gateways.get(ip_add)
                if gateway is None:
                    _LOGGER.error('Unknown gateway ip %s', ip_add)
                    continue

And now, the debug log is ‘empty’ no error, no warning.
But unfortunately sensor data not arrive

This is the only device that should be under gateways in your config.