AlexxIT / XiaomiGateway3

Home Assistant custom component for control Xiaomi Multimode Gateway (aka Gateway 3), Xiaomi Multimode Gateway 2, Aqara Hub E1 on default firmwares over LAN
https://github.com/AlexxIT/Blog
MIT License
2.46k stars 345 forks source link

Unable to turn off ZHA mode #934

Closed levkanm closed 1 year ago

levkanm commented 1 year ago

I turned on the ZHA mode before, and later wanted to turn it off,but after turning off the switch and waiting for a while, the ZHA integration still shows that it is working.

屏幕截图 2023-01-20 013159 屏幕截图 2023-01-20 013712

After that, I tried to re-flash the gateway firmware and reinstall the integration, and the ZHA integration finally showed that it could not connect.

屏幕截图 2023-01-20 013638

But after some time, the ZHA integration shows working again, but I did not turn on the ZHA mode of the gateway.

AlexxIT commented 1 year ago

What version of integration are you currently using?

levkanm commented 1 year ago

What version of integration are you currently using?

v3.0-alpha.1

AlexxIT commented 1 year ago

Alpha has big changes on this point:

By default zigbee chip works with MiHome (on default zigbee firmware). When you connects to gw via ZHA or z2m - zigbee chip switchs from MiHome to TCP mode until next gateway reboot. ZHA and z2m both can work with default and with custom zigbee firmware. MiHome can work only with default zigbee firmware.

levkanm commented 1 year ago

Alpha has big changes on this point:

  • Checkbox in settings do nothing (will be deleted)
  • Zigbee chip firmware flashes via Gateway dropdown entity
  • ZHA/z2m mode ready to connect full time 24/7

By default zigbee chip works with MiHome (on default zigbee firmware). When you connects to gw via ZHA or z2m - zigbee chip switchs from MiHome to TCP mode until next gateway reboot. ZHA and z2m both can work with default and with custom zigbee firmware. MiHome can work only with default zigbee firmware.

How do I get the gateway back to the default zigbee firmware?My gateway has been going offline occasionally lately, and I think it has something to do with ZHA mode.

AlexxIT commented 1 year ago
  • Zigbee chip firmware flashes via Gateway dropdown entity
osnwt commented 1 year ago

Updated from 3-alpha to 3.0 release. Wanted to change back to Xiaomi mode. Cannot flash original Zigbee firmware.

I choose "Zigbee flash EZSP", "Firmware" (does not matter which one), the result: ERROR

Tried with old firmware (was recommended), now on the latest 1.5.4 - no difference.

AlexxIT commented 1 year ago

Try to reboot gateway and flash again. Try to flash Custom and later default fw. Check Hass logs for errors

osnwt commented 1 year ago

Done, no change:


2023-01-23 14:21:52.558 WARNING (MainThread) [custom_components.xiaomi_gateway3.core.mini_miio] 10.1.0.11 | Device offline
2023-01-23 14:23:34.543 ERROR (MainThread) [custom_components.xiaomi_gateway3.core.ezsp] 10.1.0.11 [FWUP] Can't update firmware
Traceback (most recent call last):
File "/config/custom_components/xiaomi_gateway3/core/ezsp.py", line 52, in update_zigbee_firmware
cur_fw = await read_firmware(host)
File "/config/custom_components/xiaomi_gateway3/core/ezsp.py", line 104, in read_firmware
await asyncio.wait_for(ezsp._probe(), timeout=10)
File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
return fut.result()
File "/usr/local/lib/python3.10/site-packages/bellows/ezsp/__init__.py", line 74, in _probe
await self.connect(use_thread=False)
File "/usr/local/lib/python3.10/site-packages/bellows/ezsp/__init__.py", line 118, in connect
self._gw = await bellows.uart.connect(self._config, self, use_thread=use_thread)
File "/usr/local/lib/python3.10/site-packages/bellows/uart.py", line 397, in connect
protocol, _ = await _connect(config, application)
File "/usr/local/lib/python3.10/site-packages/bellows/uart.py", line 372, in _connect
baudrate=config[CONF_DEVICE_BAUDRATE],
KeyError: 'baudrate'
2023-01-23 14:23:34.968 ERROR (MainThread) [frontend.js.latest.202301100] :0:0 Script error.
AlexxIT commented 1 year ago

Thanks. I'll check. Maybe problem with latest Hass versions. This works near 2022.10 version

osnwt commented 1 year ago

Any updates on this issue?

Currently I am stuck at z2m mode which I can't switch back. As a last resort, I installed HAOS 9.1, HACS, downloaded GW3 2.1.2. But can't install the integration: Не удалось загрузить мастер настройки: {"message":"Invalid handler specified"}.

Also I tried to reflash zigbee chip manually using sx tool, but also without success. Thanks, the GW still works in z2m mode, but any solution or at least a manual workaround would be greatly appreciated.

AlexxIT commented 1 year ago

@osnwt fixed in latest master version. Will be in next release

osnwt commented 1 year ago

Excellent, waiting for it...

osnwt commented 1 year ago

Still no luck, but for other reason, see logs... What service should listen there?

10.1.0.11 [FWUP] Can't update firmware
Traceback (most recent call last):
  File "/config/custom_components/xiaomi_gateway3/core/ezsp.py", line 52, in update_zigbee_firmware
    cur_fw = await read_firmware(host)
  File "/config/custom_components/xiaomi_gateway3/core/ezsp.py", line 104, in read_firmware
    await asyncio.wait_for(ezsp._probe(), timeout=10)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.10/site-packages/bellows/ezsp/__init__.py", line 74, in _probe
    await self.connect(use_thread=False)
  File "/usr/local/lib/python3.10/site-packages/bellows/ezsp/__init__.py", line 118, in connect
    self._gw = await bellows.uart.connect(self._config, self, use_thread=use_thread)
  File "/usr/local/lib/python3.10/site-packages/bellows/uart.py", line 397, in connect
    protocol, _ = await _connect(config, application)
  File "/usr/local/lib/python3.10/site-packages/bellows/uart.py", line 368, in _connect
    transport, protocol = await zigpy.serial.create_serial_connection(
  File "/usr/local/lib/python3.10/site-packages/zigpy/serial.py", line 36, in create_serial_connection
    transport, protocol = await loop.create_connection(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('10.1.0.11', 8889)
AlexxIT commented 1 year ago

@osnwt maybe you disable internet for the gateway? Goto gateway telnet and run ps

osnwt commented 1 year ago

Tried to ping external servers. It gets IPv6 address instead of IPv4 and fails to reach it. On IPv4 the same server is reachable. So I'll try to disable IPv6 somewhere and retry.

osnwt commented 1 year ago

Seems something is wrong with the hub system.

I have no IPv6 in my LAN. Router uses few DNS servers, each of them returns both A and AAAA addresses:

# cat /etc/resolv.conf
nameserver 10.1.0.1
nameserver 93.100.1.2
nameserver 94.19.255.3

This obviously fails:

# ping google.com
PING google.com (2a00:1450:4010:c08::66): 56 data bytes
ping: sendto: Network is unreachable

But hub doesn't have any IPv6 addresses configured except link local which should not be used outside of LAN:

# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue
    link/ether 54:ef:44:3d:12:fd brd ff:ff:ff:ff:ff:ff
    inet 10.1.0.11/24 brd 10.1.0.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::56ef:44ff:fe3d:12fd/64 scope link
       valid_lft forever preferred_lft forever
3: wlan0-9: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 54:ef:44:3d:12:fd brd ff:ff:ff:ff:ff:ff
4: tmp.wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 00:e0:4c:81:86:86 brd ff:ff:ff:ff:ff:ff
5: wlan0-1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 00:e0:4c:81:86:86 brd ff:ff:ff:ff:ff:ff
6: wlan0-2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 00:e0:4c:81:86:86 brd ff:ff:ff:ff:ff:ff
7: wlan0-3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 00:e0:4c:81:86:86 brd ff:ff:ff:ff:ff:ff
8: wlan0-4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 00:e0:4c:81:86:86 brd ff:ff:ff:ff:ff:ff
9: wlan0-5: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 00:e0:4c:81:86:86 brd ff:ff:ff:ff:ff:ff
10: wlan0-6: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 00:e0:4c:81:86:86 brd ff:ff:ff:ff:ff:ff
11: wlan0-7: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 00:e0:4c:81:86:86 brd ff:ff:ff:ff:ff:ff
12: wlan0-8: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 00:e0:4c:81:86:86 brd ff:ff:ff:ff:ff:ff
13: pwlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 00:e0:4c:81:96:96 brd ff:ff:ff:ff:ff:ff
14: sit0: <NOARP> mtu 1480 qdisc noop
    link/sit 0.0.0.0 brd 0.0.0.0
15: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 00:12:34:56:78:90 brd ff:ff:ff:ff:ff:ff
16: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop
    link/ether 00:12:34:56:78:91 brd ff:ff:ff:ff:ff:ff

So it's an issue with the hub, why it uses IPv6 instead of IPv4... Have no idea yet how to fix it.

osnwt commented 1 year ago

I have some busybox binary in /data (perhaps, left from manual firmware updates). So tried it as well as original one from /bin. Here are results:

# /bin/busybox ping google.com
PING google.com (2a00:1450:4010:c08::8a): 56 data bytes
ping: sendto: Network is unreachable

# /data/busybox ping google.com
PING google.com (64.233.165.100): 56 data bytes
64 bytes from 64.233.165.100: seq=0 ttl=108 time=5.287 ms
64 bytes from 64.233.165.100: seq=1 ttl=108 time=5.323 ms
64 bytes from 64.233.165.100: seq=2 ttl=108 time=5.129 ms
^C

So internal busybox wants IPv6 and fails. But alternative busybox works. I tried to reflash another firmware (was on mgl03_1.5.4_0090_stock, now mgl03_1.5.0_0102_stock) - same issues.

Definitely it is not for this thread anymore, but I have no idea what to do. May try to factory reset...

AlexxIT commented 1 year ago

You can download openmiio manually to gateway. But you will need to update it to latest version every time

PlutoVYS commented 1 year ago

Still no luck, but for other reason, see logs... What service should listen there?

10.1.0.11 [FWUP] Can't update firmware
Traceback (most recent call last):
  File "/config/custom_components/xiaomi_gateway3/core/ezsp.py", line 52, in update_zigbee_firmware
    cur_fw = await read_firmware(host)
  File "/config/custom_components/xiaomi_gateway3/core/ezsp.py", line 104, in read_firmware
.......
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('10.1.0.11', 8889)

I have same error:

File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect return await fut File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.212.213', 8889)

osnwt commented 1 year ago

You can download openmiio manually to gateway. But you will need to update it to latest version every time

What and where to get and where to put?

Also, if you download it from an external server, maybe you can either somehow embed it into the integration, or let it download it to Home Assistant, then send to the hub, or as a last chance put a copy of firmware to an external server which does not have any IPv6 addresses. Say, ya.ru or google.com both have AAAA records and can't be pinged. github.com for me gives just A record and can be pinged via IPv4.

AlexxIT commented 1 year ago

There is no suitable protocol for send files from integration to gateway. You can find links in integration sources. Shell folder

osnwt commented 1 year ago

It seems the issue is not resolved despite closed. So let me give more info.

First, I blocked AAAA responses from local DNS and edited resolve.conf to be able to download anything needed. So far I have openmiio_agent in the /data folder:

drwxrwxrwx    2 app      0              160 Jan 23 13:41 basic_app
drwxr-xr-x    2 admin    0              240 Jan 23 13:41 basic_gw
-rwxr-xr-x    1 admin    0               73 Jan  1  1970 ble_info
-rwxr-xr-x    1 admin    0          1576152 Oct  3 01:15 busybox
drwxr-xr-x    2 admin    0              520 Jan  1  1970 conf
drwxr-xr-x    2 admin    0              320 Jan  1  1970 factory
drwxr-xr-x    2 admin    0              240 Feb  2 09:31 firmware
-rw-r--r--    1 admin    0                0 Feb  2 09:31 firmware.bin
drwxr-xr-x    2 admin    0              224 Jan  1  1970 hw_setting
-rw-r--r--    1 admin    0             1724 Jan 30 22:31 libnsl.so.0
drwxr-xr-x    3 admin    0              224 Jan 23 13:41 local
drwxr-xr-x    2 admin    0             1936 Feb  8 16:15 miio
-rw-r--r--    1 admin    0            12288 Feb  2 09:28 miioconfig.db
drwx------    2 admin    0              232 Oct  6 02:16 mijia_automation
-rw-r--r--    1 admin    0                0 Jan  1  1970 mount_ok
-rwxr-xr-x    1 admin    0           939384 Feb  1 22:59 openmiio_agent
-rw-r--r--    1 admin    0             1597 Feb  2 10:05 openmiio_agent.json
-rw-r--r--    1 admin    0               90 Feb  8 16:11 passwd
-rw-r--r--    1 admin    0               90 Feb  8 15:47 passwd-
-rwxr-xr-x    1 admin    0            74188 Oct  5 01:35 ser2net
-rw-r--r--    1 admin    0               85 Feb  8 16:11 shadow
-rw-r--r--    1 admin    0               85 Feb  8 15:47 shadow-
-rwxr-xr-x    1 admin    0          1091339 Sep 25 14:01 silabs_ncp_bt
drwxr-xr-x    3 admin    0              448 Sep 27 22:25 silicon_zigbee_host
-rwxr-xr-x    1 admin    0            72632 Jan 30 22:31 sx
drwxr-xr-x    2 admin    0              864 Nov  2 03:14 zigbee
drwxr-xr-x    2 admin    0              504 Jan 23 12:30 zigbee_gw
drwxr-xr-x    2 admin    0              232 Jan 23 13:41 zoneinfo

Attempt to update firmware still gave me:

ConnectionRefusedError: [Errno 111] Connect call failed ('10.1.0.11', 8889)

Here is the process list (some system processes skipped):

  893 admin     1584 S    {kick_wdog_timer} /bin/sh /bin/kick_wdog_timer
  895 admin     1584 S    syslogd
  929 admin        0 SW   [ubi_bgt0d]
  935 admin        0 SW   [ubifs_bgt0_0]
 1061 admin     1424 S    mdnsd
 1079 admin        0 SW<  [kworker/0:1H]
 1082 admin     1632 S    {miio_client_hel} /bin/sh /bin/miio_client_helper_nomqtt.sh
 1086 admin     5952 S    basic_gw
 1088 admin     2816 S    zigbee_agent -f /etc/zigbee_agent.conf
 1132 admin     6416 S    mijia_automation -d /data/mijia_automation/
 1140 admin     4832 S    basic_app 464064582
 1145 admin     1632 S    {app_monitor.sh} /bin/sh /bin/app_monitor.sh
 1440 admin     6496 S    wpa_supplicant -Dnl80211 -iwlan0 -c /tmp/wpa_supplicant.conf -B
 1478 admin     1584 S    udhcpc -i wlan0 -t 20 -T 2 -n -S -x hostname lumi_gateway_mgl03 -s /etc/udhcp/simple.script
 1489 admin        0 SW   [kworker/u2:2]
 1491 admin     8224 S    homekitserver
 1513 admin    21216 S    silabs_ncp_bt -p /dev/ttyS1 -n
 1724 admin    35360 S    idmruntime
 1726 admin     9440 S    central_service_lite
 1741 admin     1584 S    {idmipd.sh} /bin/sh /bin/idmipd.sh
 1915 admin     1584 S    telnetd
 1929 admin     1584 S    ntpd -l
 1953 admin     1600 S    -sh
 1979 admin     1696 S    mosquitto -d
 1995 admin    11376 S    zigbee_gw
 2752 admin    12608 S    miio_client -l 4 -d /data/miio/ -L /var/log/miio_client.log -D
 2912 admin      848 S    /bin/miio_recv_line
 3065 admin     649m S    /data/openmiio_agent miio mqtt cache z3 --zigbee.tcp=8888
 3079 admin     1584 S    tail Lumi_Z3GatewayHost_MQTT -f /dev/null
 3086 admin        0 Z    [Lumi_Z3GatewayH]
 6463 admin     1584 S    -/bin/login
 6530 admin     1568 S    sleep 5
 6537 admin     1568 S    sleep 10
 6547 admin     1584 R    ps

So miio_agent is listening on port 8888, and isn't on 8889.

From the integration code I found the command line to start it on port 8889:

/data/openmiio_agent --zigbee.tcp=8889 &

Being started, it listened on port 8889. But on another attempt to flash firmware I've got the same error.

Anything else I could try to help resolving the issue? Would be happy to help.

AlexxIT commented 1 year ago

You can enable integration debug logs and check if this msg

https://github.com/AlexxIT/XiaomiGateway3/blob/7596fc1d6c342fe9ba0e088bcb48aa65f42c31b2/custom_components/xiaomi_gateway3/core/ezsp.py#L22

exist there. And later check if any error exist in logs.

Yuke-hd commented 1 year ago

I had the same issue, lucky for me I have a DEV envrionment (raspberry pi running with HA pre-2022.10 version), I manually intalled v2.1.2, then in the integration config turned on and turn off "mode ZHA or z2m", then in my Prod envrionment, the gateway can stay in "mihome" mode no problem

kkmaslowski commented 1 year ago

I have the same error on 3.1.0 and gw firmware 1.5.0_0102:

2023-03-01 20:52:18.292 ERROR (bellows.thread_0) [bellows.uart] Lost serial connection: OSError('Server closed connection')
2023-03-01 20:52:18.295 ERROR (MainThread) [bellows.ezsp] NCP entered failed state. Requesting APP controller restart
2023-03-01 20:52:18.298 WARNING (MainThread) [bellows.thread] Attempted to use a closed event loop
2023-03-01 20:52:18.815 WARNING (MainThread) [bellows.zigbee.application] ControllerApplication reset unsuccessful: ConnectionRefusedError(111, "Connect call failed ('192.168.10.119', 8888)")
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/bellows/zigbee/application.py", line 637, in _reset_controller_loop
    await self._reset_controller()
  File "/usr/local/lib/python3.10/site-packages/bellows/zigbee/application.py", line 658, in _reset_controller
    await self.connect()
  File "/usr/local/lib/python3.10/site-packages/bellows/zigbee/application.py", line 124, in connect
    self._ezsp = await bellows.ezsp.EZSP.initialize(self.config)
  File "/usr/local/lib/python3.10/site-packages/bellows/ezsp/__init__.py", line 101, in initialize
    await ezsp.connect(use_thread=zigpy_config[conf.CONF_USE_THREAD])
  File "/usr/local/lib/python3.10/site-packages/bellows/ezsp/__init__.py", line 118, in connect
    self._gw = await bellows.uart.connect(self._config, self, use_thread=use_thread)
  File "/usr/local/lib/python3.10/site-packages/bellows/uart.py", line 389, in connect
    protocol, connection_done = await thread.run_coroutine_threadsafe(
  File "/usr/local/lib/python3.10/site-packages/bellows/uart.py", line 368, in _connect
    transport, protocol = await zigpy.serial.create_serial_connection(
  File "/usr/local/lib/python3.10/site-packages/zigpy/serial.py", line 36, in create_serial_connection
    transport, protocol = await loop.create_connection(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.10.119', 8888)
2023-03-01 20:52:19.312 ERROR (MainThread) [custom_components.xiaomi_gateway3.core.ezsp] 192.168.10.119 [FWUP] Can't update firmware
Traceback (most recent call last):
  File "/config/custom_components/xiaomi_gateway3/core/ezsp.py", line 52, in update_zigbee_firmware
    cur_fw = await read_firmware(host)
  File "/config/custom_components/xiaomi_gateway3/core/ezsp.py", line 104, in read_firmware
    await asyncio.wait_for(ezsp._probe(), timeout=10)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.10/site-packages/bellows/ezsp/__init__.py", line 74, in _probe
    await self.connect(use_thread=False)
  File "/usr/local/lib/python3.10/site-packages/bellows/ezsp/__init__.py", line 118, in connect
    self._gw = await bellows.uart.connect(self._config, self, use_thread=use_thread)
  File "/usr/local/lib/python3.10/site-packages/bellows/uart.py", line 397, in connect
    protocol, _ = await _connect(config, application)
  File "/usr/local/lib/python3.10/site-packages/bellows/uart.py", line 368, in _connect
    transport, protocol = await zigpy.serial.create_serial_connection(
  File "/usr/local/lib/python3.10/site-packages/zigpy/serial.py", line 36, in create_serial_connection
    transport, protocol = await loop.create_connection(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.10.119', 8889)
2023-03-01 20:52:32.754 WARNING (SyncWorker_8) [custom_components.solarman.solarman] Querying inverter 1709992578 at 192.168.10.106:8899 failed on connection start with exception [OSError]
igelbro commented 1 year ago

Same issue. Flash from integration:

File "/config/custom_components/xiaomi_gateway3/core/ezsp.py", line 52, in update_zigbee_firmware cur_fw = await read_firmware(host) File "/config/custom_components/xiaomi_gateway3/core/ezsp.py", line 104, in read_firmware await asyncio.wait_for(ezsp._probe(), timeout=10) File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for return fut.result() File "/usr/local/lib/python3.10/site-packages/bellows/ezsp/init.py", line 75, in _probe await self.connect(use_thread=False) File "/usr/local/lib/python3.10/site-packages/bellows/ezsp/init.py", line 119, in connect self._gw = await bellows.uart.connect(self._config, self, use_thread=usethread) File "/usr/local/lib/python3.10/site-packages/bellows/uart.py", line 406, in connect protocol, = await _connect(config, application) File "/usr/local/lib/python3.10/site-packages/bellows/uart.py", line 377, in _connect transport, protocol = await zigpy.serial.create_serial_connection( File "/usr/local/lib/python3.10/site-packages/zigpy/serial.py", line 32, in create_serial_connection transport, protocol = await loop.create_connection( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1076, in create_connection raise exceptions[0] File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1060, in create_connection sock = await self._connect_sock( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 969, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 501, in sock_connect return await fut File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 541, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.1.4', 8889)

Flash from console:

Preparing Killing default zigbee software killall: socat: no process killed killall: daemon_app.sh: no process killed Done

Press Ctrl+C to cancel in 5 seconds!

Detected EZSP v7 Rebooting to bootloader Sending upload command Sending ncp-uart-sw_mgl03_6_7_10_z2m.gbl, 1548 blocks: Give your local XMODEM receive command now.

Xmister commented 1 year ago

I was facing a similar issue, and found out a few things:

kkmaslowski commented 1 year ago

@igelbro how to flash it manually from console? Do you see that gateway works more stable on custom EZSP FW?

igelbro commented 1 year ago

@kkmaslowski https://github.com/zvldz/mgl03_fw/tree/main/zigbee

igelbro commented 1 year ago

@Xmister If you set up Zigbee2Mqtt in HA (and keep the XiaomiGateway3 addon running), it will be in the right state for the console flash to finish. Not for me :(

kkmaslowski commented 1 year ago

@kkmaslowski https://github.com/zvldz/mgl03_fw/tree/main/zigbee

Can I flash it if I use ZHA mode? I see that ncp-uart-sw_mgl03_6_7_8_z2m.gbl is for Zigbee2MQTT.

igelbro commented 1 year ago

@kkmaslowski Don`t know. ncp-uart-sw_mgl03_6_6_2_stock.gbl for return to stock firmware

Xmister commented 1 year ago

@Xmister If you set up Zigbee2Mqtt in HA (and keep the XiaomiGateway3 addon running), it will be in the right state for the console flash to finish. Not for me :(

I'm sorry to hear that. It took about 5 minutes for the flash to complete for me. You can telnet to the device and see if Lumi_Z3GatewayHost_MQTT keeps restarting. In that case try to restart zigbee2mqtt.

Can I flash it if I use ZHA mode? I see that ncp-uart-sw_mgl03_6_7_8_z2m.gbl is for Zigbee2MQTT.

I think it should work with ZHA as well. I used 6.7.10 though.

Do you see that gateway works more stable on custom EZSP FW?

For me it got rid of the Zigbee timeouts in Z2M.

kkmaslowski commented 1 year ago

@Xmister i tried to flash ncp-uart-sw_mgl03_6_7_10_z2m.gbl without success, it stuck after 'Sending ncp-uart-sw_mgl03_6_7_10_z2m.gbl, 1548 blocks: Give your local XMODEM receive command now' Zrzut ekranu z 2023-03-21 14-39-49

Xmister commented 1 year ago

Maybe the device firmware also matters. I'm using 1.5.4. How long did you wait for the flash to finish? Have you been checking top in another terminal to see what processes are running?

AlexxIT commented 1 year ago

I can confirm that flashing from Hass GUI works fine for:

If something doesn't work for you - maybe you have blocked internet for gateway or have problems with IPv6

Cheerpipe commented 1 year ago

@Xmister i tried to flash ncp-uart-sw_mgl03_6_7_10_z2m.gbl without success, it stuck after 'Sending ncp-uart-sw_mgl03_6_7_10_z2m.gbl, 1548 blocks: Give your local XMODEM receive command now' Zrzut ekranu z 2023-03-21 14-39-49

Try this:

1.- Disable ZHA or stop Z2M. 2.- Reboot hub. 3.- Reload Gateway3 integration in HA. (Make sure "Xiaomi Multimode Gateway" entity is available) 4.- Enable ZHA or start Z2M. Make sure it is working. It will ensure HUB is in Z2M/ZHA mode.

  1. Telnet your HUB.
  2. Run flash script 7.- Repeat 1 to 5 until succeed

I successfully flashed mine on fifth try.

szymucha94 commented 1 year ago

@Xmister i tried to flash ncp-uart-sw_mgl03_6_7_10_z2m.gbl without success, it stuck after 'Sending ncp-uart-sw_mgl03_6_7_10_z2m.gbl, 1548 blocks: Give your local XMODEM receive command now' Zrzut ekranu z 2023-03-21 14-39-49

Try this:

1.- Disable ZHA or stop Z2M. 2.- Reboot hub. 3.- Reload Gateway3 integration in HA. (Make sure "Xiaomi Multimode Gateway" entity is available) 4.- Enable ZHA or start Z2M. Make sure it is working. It will ensure HUB is in Z2M/ZHA mode. 5. Telnet your HUB. 6. Run flash script 7.- Repeat 1 to 5 until succeed

I successfully flashed mine on fifth try.

I gave up after 10 attempts. I also have the same problem.

AlexxIT commented 1 year ago

Try to flash from integration v3.2.1 GUI

szymucha94 commented 1 year ago

Try to flash from integration v3.2.1 GUI

already did yesterday multiple times. Always r err esults in error: err_ha manual ver restarting before another attempt, killing xiaomi processes, replacing send_v7() with send_v8() and to_btl_7() with to_btl_8() - nothing changes the outcome, it always fails. And yet zigbee works normally in z2m mode. I'm not sure what kind of black magic you were doing in 2.x version of your integration (as I flashed it via old GUI - where z2m mode had to be ticked in integration settings) but this is definitely broken now.

AlexxIT commented 1 year ago

Check integration debug logs. I think it just can't download openmiio app from GitHub. Maybe your Hass server has problem with internet

szymucha94 commented 1 year ago

Check integration debug logs. I think it just can't download openmiio app from GitHub. Maybe your Hass server has problem with internet

no, it doesn't. openmiio is running and listening on port 8888 so naturally it was downloaded.

szymucha94 commented 1 year ago

@AlexxIT what do you mean "check integration debug logs"? Output that I've sent is all that I see in HA logs.

123

why does it attempt to reach port 8889 when openmiio is listening on 8888? 1234

AlexxIT commented 1 year ago

Whole update process in one function: https://github.com/AlexxIT/XiaomiGateway3/blob/6c1499a0b49edbf723cf8bf7e3ec406d01ffe57a/custom_components/xiaomi_gateway3/core/ezsp.py#L45-L48

Are you sure you using latest integration version?

You can run /data/openmiio_agent --log.level=info and check app version