Open baimard opened 3 years ago
Hi,
your bug seems to be similar to issue #55 Did you upgrade Zigate's firmware ? A new release (3.1e) has just been delivered
Do you know how I could watch my firmware version of zigate ?
you should be able to see it in the visualization tab in ZHA configuation
3.1d for me, new question ... where is the last firmware ...
Merci beaucoup !
Je vais essayer voir si ça corrige.
another bug :
home_assistant.1.mag30mglug26@x-kaki | 2021-05-18 22:55:43 ERROR (MainThread) [zigpy_zigate.api] Received unhandled response 0x8012
home_assistant.1.mag30mglug26@x-kaki | 2021-05-18 22:55:43 ERROR (MainThread) [zigpy_zigate.api] Received unhandled response 0x8012
home_assistant.1.mag30mglug26@x-kaki | 2021-05-18 22:55:44 ERROR (MainThread) [zigpy_zigate.api] Received unhandled response 0x8012
home_assistant.1.mag30mglug26@x-kaki | 2021-05-18 22:55:44 ERROR (MainThread) [zigpy_zigate.api] Received unhandled response 0x8012
home_assistant.1.mag30mglug26@x-kaki | 2021-05-18 22:55:44 ERROR (MainThread) [zigpy_zigate.api] Received unhandled response 0x8012
home_assistant.1.mag30mglug26@x-kaki | 2021-05-18 22:55:44 ERROR (MainThread) [zigpy_zigate.api] Received unhandled response 0x8012
Always same deconnection ...
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:25:57 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=light, service=turn_off, service_data=entity_id=light.beta_level_on_off>
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:25:57 DEBUG (MainThread) [zigpy_zigate.zigbee.application] request (0x5231, 260, 6, 1, 1, 18, b'\x01\x12\x00', True, False)
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:25:57 DEBUG (MainThread) [zigpy_zigate.uart] Send: 0x0530 b'025231010100060104000003011200'
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:25:57 DEBUG (MainThread) [zigpy_zigate.uart] Frame to send: b'\x050\x00\x0fH\x02R1\x01\x01\x00\x06\x01\x04\x00\x00\x03\x01\x12\x00'
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:25:57 DEBUG (MainThread) [zigpy_zigate.uart] Frame escaped: b'\x02\x150\x02\x10\x02\x1fH\x02\x12R1\x02\x11\x02\x11\x02\x10\x02\x16\x02\x11\x02\x14\x02\x10\x02\x10\x02\x13\x02\x11\x12\x02\x10'
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:25:58 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:25:58 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0530
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:25:58 DEBUG (MainThread) [zigpy_zigate.uart] Send: 0x0530 b'025231010100060104000003011200'
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:25:58 DEBUG (MainThread) [zigpy_zigate.uart] Frame to send: b'\x050\x00\x0fH\x02R1\x01\x01\x00\x06\x01\x04\x00\x00\x03\x01\x12\x00'
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:25:58 DEBUG (MainThread) [zigpy_zigate.uart] Frame escaped: b'\x02\x150\x02\x10\x02\x1fH\x02\x12R1\x02\x11\x02\x11\x02\x10\x02\x16\x02\x11\x02\x14\x02\x10\x02\x10\x02\x13\x02\x11\x12\x02\x10'
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:26:00 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:26:00 DEBUG (MainThread) [zigpy.device] [0x5231] Delivery error for seq # 0x12, on endpoint id 1 cluster 0x0006: ZiGate doesn't answer to command
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:26:00 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x5231:1:0x0006]: command failed: 'off' args: '()' kwargs '{}' exception: '[0x5231:1:0x0006]: Message send failure'
home_assistant.1.k28tajqju8bv@x-kaki | 2021-05-18 23:26:00 DEBUG (MainThread) [homeassistant.components.zha.entity] light.beta_level_on_off: turned off: [0x5231:1:0x0006]: Message send failure
There is a really big problem, I can't identify what happend. I can do every debug you want, to try to solve this issue !
Could you please take this problem in consideration ?
Same here, I can also help with debug if you need information
I use firmware 3.1e Yesterday all is working. This morning: devices Offlines
Hi, I have the same problem. There is a query that is disconnected and no longer makes the plugin work. A little try catch would at least prevent the plugin from crashing
2021-06-13 21:04:43 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530 ┤
│2021-06-13 21:04:43 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0530 ┤
│2021-06-13 21:04:43 DEBUG (MainThread) [zigpy_zigate.uart] Send: 0x0530 b'02a6e10101000001040000050057000400' ┤
│2021-06-13 21:04:43 DEBUG (MainThread) [zigpy_zigate.uart] Frame to send: b'\x050\x00\x112\x02\xa6\xe1\x01\x01\x00\x00\x01\x04\x00\x00\x05\x00W\x00\x04\┤
│2021-06-13 21:04:43 DEBUG (MainThread) [zigpy_zigate.uart] Frame escaped: b'\x02\x150\x02\x10\x112\x02\x12\xa6\xe1\x02\x11\x02\x11\x02\x10\x02\x10\x02\x┤
│2021-06-13 21:04:44 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530 ┤
│2021-06-13 21:04:44 DEBUG (MainThread) [zigpy.device] [0xa6e1] Delivery error for seq # 0x57, on endpoint id 1 cluster 0x0000: ZiGate doesn't answer to command│
And after nothing
I just performed a test against the code in the dev branch which is supposed to implement the reconnect feature.
2021-06-14 14:51:37 DEBUG (MainThread) [zigpy_zigate.uart] Closed serial connection
but no reconnection attempt was made by the lib. I had to force integration reload to have the connection back:
2021-06-14 14:55:06 DEBUG (MainThread) [zigpy_zigate.uart] Connection made
I added some debug code into the lib, just to be sure.
def connection_lost(self, exc) -> None:
"""Port was closed expecteddly or unexpectedly."""
if self._connected_future and not self._connected_future.done():
if exc is None:
LOGGER.info("Connection lost - no exception");
self._connected_future.set_result(True)
else:
LOGGER.info("Connection lost with exception %s", exc);
self._connected_future.set_exception(exc)
if exc is None:
LOGGER.debug("Closed serial connection")
return
LOGGER.error("Lost serial connection: %s", exc)
self._api.connection_lost(exc)
The "connection lost" messages I added are never called when we hit a disconnect. We might need to examine zigpy implementation in details to understand if this code (which is common to xbee, combee...) do work with other devices or if there is just a duplicated bug. Connection lost with USB devices is probably a rare issue
Like it seems to come after 'No response to command 0x0530', that is to say, a 'hardware' crash, this is probably common to xbee, combee and other but they don't crash so we don't see the same trouble.
I think we are dealing with 2 bugs. To check.
Like it seems to come after 'No response to command 0x0530', that is to say, a 'hardware' crash, this is probably common to xbee, combee and other but they don't crash so we don't see the same trouble.
I think we are dealing with 2 bugs. To check.
For me it's a global connection problem. After a delay, connection crash and we have lot of errors.
Depending on the command that we send we have a different return. But the basic problem is the connection
My 2 cents, don't know if this is related, but in Wifi, the plugin needs to maintain the IP connection, otherwise after a Timeout ( 4 or 5 minutes) the line is droped
is it possible to add simply a "ping" or other every 30s to maintain the connection ?
Like it seems to come after 'No response to command 0x0530', that is to say, a 'hardware' crash, this is probably common to xbee, combee and other but they don't crash so we don't see the same trouble. I think we are dealing with 2 bugs. To check.
For me it's a global connection problem. After a delay, connection crash and we have lot of errors.
Depending on the command that we send we have a different return. But the basic problem is the connection
Do other Zigbee radio modules have the same troubles ?
Like it seems to come after 'No response to command 0x0530', that is to say, a 'hardware' crash, this is probably common to xbee, combee and other but they don't crash so we don't see the same trouble. I think we are dealing with 2 bugs. To check.
For me it's a global connection problem. After a delay, connection crash and we have lot of errors. Depending on the command that we send we have a different return. But the basic problem is the connection
Do other Zigbee radio modules have the same troubles ?
that a very good question, with the title of this issue I don't know if other product owner read this thread
Most other zigbee radio modules are USB modules
I can confirm I'm affected with zigate on usb. For now I have rollback to HASS version 2021.3.0 (docker install)
deCONZ radios have much problems with USB disconnections and comports is not mapped OK in docker (in native deCONZ and ZHA).
Tasmota, and ESPHome that using ESP chips looks working OK with EFR32 and TI chips also tuya ZBGW is working OK with EFR32 radios over Ethernet.
EFR32 / bellows is going in fault state if the counter is going of sync then loosing packages in the WiFi / Eth network but is nicely logged in the error log.
I can confirm I'm affected with zigate on usb. For now I have rollback to HASS version 2021.3.0 (docker install)
Interesting, can you confirm that you don't use any wifi between zigate/usb and your home assistant ?
I confirm. I'm using Hass with docker on a NUC running archlinux. I don't know if it can influence but my USB Zigate is on a USB hub. I can try without tonight if you want?
I confirm. I'm using Hass with docker on a NUC running archlinux. I don't know if it can influence but my USB Zigate is on a USB hub. I can try without tonight if you want?
Thank you, I don't think that it's necessary. The main point is that wifi seem not be the cause. As far as I'm remember when I put my PiZigate directly on my raspberry pi3, I already have 'Devices Offline' disconnects on my zigbee2mqtt, so this seems to exonerate wifi
is it possible to add simply a "ping" or other every 30s to maintain the connection ?
I need to check logs, but I think that plugin already ask periodically for state of sensors...
2021-06-13 21:04:43 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530 ┤ │2021-06-13 21:04:43 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0530 ┤ │2021-06-13 21:04:43 DEBUG (MainThread) [zigpy_zigate.uart] Send: 0x0530 b'02a6e10101000001040000050057000400' ┤ │2021-06-13 21:04:43 DEBUG (MainThread) [zigpy_zigate.uart] Frame to send: b'\x050\x00\x112\x02\xa6\xe1\x01\x01\x00\x00\x01\x04\x00\x00\x05\x00W\x00\x04\┤ │2021-06-13 21:04:43 DEBUG (MainThread) [zigpy_zigate.uart] Frame escaped: b'\x02\x150\x02\x10\x112\x02\x12\xa6\xe1\x02\x11\x02\x11\x02\x10\x02\x10\x02\x┤ │2021-06-13 21:04:44 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530 ┤ │2021-06-13 21:04:44 DEBUG (MainThread) [zigpy.device] [0xa6e1] Delivery error for seq # 0x57, on endpoint id 1 cluster 0x0000: ZiGate doesn't answer to command│
And after nothing
To my mind, after Retry command, if module don't answer again then we should initialize connection like we do on start. What do you think about?
Citation de pipiche le 16 juin 2021, 15 h 27 min
Domoticz ping régulièrement la ZiGate (si il n'y a pas eu de communication In et Out depuis un laps de temps)
Si on ne reçoit pas de réponse au ping, on va insister
Si malgré les retry pas de réponse, alors le plugin est relancé avec un restart de la ZiGate
This seems a good process.
So the problem is in HASS core ?
Citation de pipiche le 16 juin 2021, 15 h 27 min Domoticz ping régulièrement la ZiGate (si il n'y a pas eu de communication In et Out depuis un laps de temps) Si on ne reçoit pas de réponse au ping, on va insister Si malgré les retry pas de réponse, alors le plugin est relancé avec un restart de la ZiGate
This seems a good process. To be complet, Wifi module (as per their documentation and specifications) has a Timeout and this is up to the client to keep the line live!
Yes, but as I can see in logs, we have a 0x0530 exchange every minute. (more over this seem to happen with usb module too that are not concern about wifi timeout)
So the problem is in HASS core ?
At least the core can be improved by adding same process, retry and restart if failure stay.
Any update ?
not yet, sorry for that
By the past, I wasn't experiment these disconnection. Anyone know how I can rollback HASS before the changes in causes?
I have solved the problem temporary by changing this function :
async def command(self, cmd, data=b'', wait_response=None, wait_status=True):
tries = 2
while tries > 0:
tries -= 1
await self._lock.acquire()
try:
return await asyncio.wait_for(
self._command(cmd, data, wait_response, wait_status),
timeout=COMMAND_TIMEOUT
)
except asyncio.TimeoutError:
LOGGER.warning("No response to command 0x%04x", cmd)
if tries > 0:
LOGGER.warning("Retry command 0x%04x", cmd)
else:
raise NoResponseError
finally:
self._lock.release()
by :
async def command(self, cmd, data=b'', wait_response=None, wait_status=True):
tries = 2
while tries > 0:
tries -= 1
await self._lock.acquire()
try:
return await asyncio.wait_for(
self._command(cmd, data, wait_response, wait_status),
timeout=COMMAND_TIMEOUT
)
except asyncio.TimeoutError:
LOGGER.warning("No response to command 0x%04x", cmd)
if tries > 0:
LOGGER.warning("Retry command 0x%04x", cmd)
LOGGER.warning("Close uart")
self.close()
LOGGER.warning("connect uart")
await self.connect()
else:
raise NoResponseError
finally:
self._lock.release()
Finally, the update of the zigpy_zigae does not have update in HASS.
After 24h, all work very well. Sensor and light.
To give more precisions file to change is in (docker image v2021.11) :
line 128 in this folder : /usr/local/lib/python3.9/site-packages/zigpy_zigate
Personnaly, I have docker cp the entyre folder in my host and I have mount a volume between docker container and my host.
Debug log :
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 03:14:45 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 03:14:45 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0530
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 03:14:45 WARNING (MainThread) [zigpy_zigate.api] Close uart
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 03:14:45 WARNING (MainThread) [zigpy_zigate.api] connect uart
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 03:25:20 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 03:25:20 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0530
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 03:25:20 WARNING (MainThread) [zigpy_zigate.api] Close uart
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 03:25:20 WARNING (MainThread) [zigpy_zigate.api] connect uart
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:01:41 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:01:41 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0530
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:01:41 WARNING (MainThread) [zigpy_zigate.api] Close uart
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:01:41 WARNING (MainThread) [zigpy_zigate.api] connect uart
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:14:21 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:14:21 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0530
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:14:21 WARNING (MainThread) [zigpy_zigate.api] Close uart
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:14:21 WARNING (MainThread) [zigpy_zigate.api] connect uart
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:14:21 WARNING (MainThread) [zigpy_zigate.zigbee.application] Unexpected message send failure
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:48:37 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:48:37 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0530
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:48:37 WARNING (MainThread) [zigpy_zigate.api] Close uart
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 04:48:37 WARNING (MainThread) [zigpy_zigate.api] connect uart
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 05:03:22 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 05:03:22 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0530
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 05:03:22 WARNING (MainThread) [zigpy_zigate.api] Close uart
home_assistant.1.2syn7mmyqsiu@ocre | 2021-11-08 05:03:22 WARNING (MainThread) [zigpy_zigate.api] connect uart
@baimard thanks for sharing, on battery powered sensor too? Which firmware is your zigate on?
ZiGate-WiFi v2.00 https://github.com/fairecasoimeme/ZiGate-WiFi/releases/tag/v2.00
Zigate 3.20 https://github.com/fairecasoimeme/ZiGate/releases
I try to check the connection every minute but I don't know how to deal with the asyncio librairie.
In fact, I don't which command I can send to the ZigateWifi to check connectivity. :(
Because actually my modification work for every hardware interrogated by HASS, but if it's the hardware who need to send data without request (opening door sensor), there is a possibility that the connection is down and that I don't have the information.
To keep the line active you can use some zigate command like
0x0014 get status 0x0010 get zigate version
Il faut une tache que s’assure qu’il y ait eu au moins un échange dans les 4’ sinon faire une commande pour garder la liaison TCP/IP’s-wifi
Envoyé de mon iPhone
Le 9 nov. 2021 à 12:45, jquievreux @.***> a écrit :
@baimard thanks for sharing, on battery powered sensor too? Which firmware is your zigate on?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
To keep the line active you can use some zigate command like 0x0014 get status 0x0010 get zigate version Il faut une tache que s’assure qu’il y ait eu au moins un échange dans les 4’ sinon faire une commande pour garder la liaison TCP/IP’s-wifi Envoyé de mon iPhone … Le 9 nov. 2021 à 12:45, jquievreux @.***> a écrit : @baimard thanks for sharing, on battery powered sensor too? Which firmware is your zigate on? — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
Merci beaucoup, je vais lancer un thread qui va tourner en permanence pour vérifier l'état de la connexion merci !
Après je ferais soit un fork soit un pull request ! Mais j'y suis presque en tout cas !
Absolument, l'idéal, c'est de regarder si il y a du trafic dans la fenetre des 4 minutes et dans ce cas ne rien faire, sinon envoyer une commande.
Pour faire simple un simple get_status toutes les 4 minutes permettra de détecter la connexion, sinon je vais devoir implémenter des traceurs d'action partout ... ou un loggeur
Le 10/11/2021 à 09:20, Pipiche a écrit :
Absolument, l'idéal, c'est de regarder si il y a du trafic dans la fenetre des 4 minutes et dans ce cas ne rien faire, sinon envoyer une commande.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zigpy/zigpy-zigate/issues/89#issuecomment-964885592, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZ5OEMHTTM26FPSMF6XN2DULITORANCNFSM447BR76Q. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
so I do that simply ...
async def connect(self):
assert self._uart is None
self._uart = await zigpy_zigate.uart.connect(self._config, self)
self._thread = threading.Thread(target=self.loop_check_connection) #89
self._thread.start() #89
def loop_check_connection(self):
while True:
time.sleep(300)
LOGGER.warning("Check ---")
try:
asyncio.run(self.get_network_state())
except:
LOGGER.warning("thread error") #Because of concurrent access
I have no more error ... :
logs
home_assistant.1.01xbc0atho3i@ocre | 2021-11-16 10:20:18 WARNING (Thread-4) [zigpy_zigate.api] Check ---
home_assistant.1.01xbc0atho3i@ocre | 2021-11-16 10:20:18 WARNING (MainThread) [zigpy_zigate.api] data_received
home_assistant.1.01xbc0atho3i@ocre | 2021-11-16 10:20:18 WARNING (MainThread) [zigpy_zigate.api] data_received
home_assistant.1.01xbc0atho3i@ocre | 2021-11-16 10:21:50 WARNING (MainThread) [zigpy_zigate.api] data_received
home_assistant.1.01xbc0atho3i@ocre | 2021-11-16 10:23:02 WARNING (MainThread) [zigpy_zigate.api] data_received
home_assistant.1.01xbc0atho3i@ocre | 2021-11-16 10:23:02 WARNING (MainThread) [zigpy_zigate.api] data_received
home_assistant.1.01xbc0atho3i@ocre | 2021-11-16 10:23:02 WARNING (MainThread) [zigpy_zigate.api] data_received
home_assistant.1.01xbc0atho3i@ocre | 2021-11-16 10:23:02 WARNING (MainThread) [zigpy_zigate.api] data_received
home_assistant.1.01xbc0atho3i@ocre | 2021-11-16 10:23:02 WARNING (MainThread) [zigpy_zigate.api] data_received
home_assistant.1.01xbc0atho3i@ocre | 2021-11-16 10:23:02 WARNING (MainThread) [zigpy_zigate.api] data_received
home_assistant.1.01xbc0atho3i@ocre | 2021-11-16 10:23:02 WARNING (MainThread) [zigpy_zigate.api] data_received
home_assistant.1.01xbc0atho3i@ocre | 2021-11-16 10:23:02 WARNING (MainThread) [zigpy_zigate.api] data_received
Entyre file : api.py
import asyncio
import binascii
import functools
import logging
import enum
import datetime
from typing import Any, Dict
import serial
import zigpy.exceptions
import zigpy_zigate.config
import zigpy_zigate.uart
from . import types as t
import time
import threading
LOGGER = logging.getLogger(__name__)
COMMAND_TIMEOUT = 1.5
PROBE_TIMEOUT = 3.0
RESPONSES = {
0x004D: (t.NWK, t.EUI64, t.uint8_t, t.uint8_t),
0x8000: (t.uint8_t, t.uint8_t, t.uint16_t, t.Bytes),
0x8002: (t.uint8_t, t.uint16_t, t.uint16_t, t.uint8_t, t.uint8_t,
t.Address, t.Address, t.Bytes),
0x8009: (t.NWK, t.EUI64, t.uint16_t, t.uint64_t, t.uint8_t),
0x8010: (t.uint16_t, t.uint16_t),
0x8011: (t.uint8_t, t.NWK, t.uint8_t, t.uint16_t, t.uint8_t),
0x8012: (t.uint32_t,),
0x8017: (t.uint32_t,),
0x8024: (t.uint8_t, t.NWK, t.EUI64, t.uint8_t),
0x8035: (t.uint8_t, t.uint32_t),
0x8048: (t.EUI64, t.uint8_t),
0x8701: (t.uint8_t, t.uint8_t),
0x8702: (t.uint8_t, t.uint8_t, t.uint8_t, t.Address, t.uint8_t),
0x8806: (t.uint8_t,),
}
COMMANDS = {
0x0002: (t.uint8_t,),
0x0016: (t.uint32_t,),
0x0018: (t.uint8_t,),
0x0019: (t.uint8_t,),
0x0020: (t.uint64_t,),
0x0021: (t.uint32_t,),
0x0026: (t.EUI64, t.EUI64),
0x0049: (t.NWK, t.uint8_t, t.uint8_t),
0x0530: (t.uint8_t, t.NWK, t.uint8_t, t.uint8_t, t.uint16_t, t.uint16_t, t.uint8_t, t.uint8_t, t.LBytes),
0x0806: (t.uint8_t,),
}
class AutoEnum(enum.IntEnum):
def _generate_next_value_(name, start, count, last_values):
return count
class PDM_EVENT(AutoEnum):
E_PDM_SYSTEM_EVENT_WEAR_COUNT_TRIGGER_VALUE_REACHED = enum.auto()
E_PDM_SYSTEM_EVENT_DESCRIPTOR_SAVE_FAILED = enum.auto()
E_PDM_SYSTEM_EVENT_PDM_NOT_ENOUGH_SPACE = enum.auto()
E_PDM_SYSTEM_EVENT_LARGEST_RECORD_FULL_SAVE_NO_LONGER_POSSIBLE = enum.auto()
E_PDM_SYSTEM_EVENT_SEGMENT_DATA_CHECKSUM_FAIL = enum.auto()
E_PDM_SYSTEM_EVENT_SEGMENT_SAVE_OK = enum.auto()
E_PDM_SYSTEM_EVENT_EEPROM_SEGMENT_HEADER_REPAIRED = enum.auto()
E_PDM_SYSTEM_EVENT_SYSTEM_INTERNAL_BUFFER_WEAR_COUNT_SWAP = enum.auto()
E_PDM_SYSTEM_EVENT_SYSTEM_DUPLICATE_FILE_SEGMENT_DETECTED = enum.auto()
E_PDM_SYSTEM_EVENT_SYSTEM_ERROR = enum.auto()
E_PDM_SYSTEM_EVENT_SEGMENT_PREWRITE = enum.auto()
E_PDM_SYSTEM_EVENT_SEGMENT_POSTWRITE = enum.auto()
E_PDM_SYSTEM_EVENT_SEQUENCE_DUPLICATE_DETECTED = enum.auto()
E_PDM_SYSTEM_EVENT_SEQUENCE_VERIFY_FAIL = enum.auto()
E_PDM_SYSTEM_EVENT_PDM_SMART_SAVE = enum.auto()
E_PDM_SYSTEM_EVENT_PDM_FULL_SAVE = enum.auto()
class NoResponseError(zigpy.exceptions.APIException):
pass
class ZiGate:
def __init__(self, device_config: Dict[str, Any]):
self._app = None
self._config = device_config
self._uart = None
self._awaiting = {}
self._status_awaiting = {}
self._lock = asyncio.Lock()
self.network_state = None
@classmethod
async def new(cls, config: Dict[str, Any], application=None) -> "ZiGate":
api = cls(config)
await api.connect()
api.set_application(application)
return api
async def connect(self):
assert self._uart is None
self._uart = await zigpy_zigate.uart.connect(self._config, self)
self._thread = threading.Thread(target=self.loop_check_connection)
self._thread.start()
def loop_check_connection(self):
while True:
time.sleep(300)
LOGGER.warning("Check ---")
try:
asyncio.run(self.get_network_state())
except:
LOGGER.warning("thread error")
def close(self):
if self._uart:
self._uart.close()
self._uart = None
def set_application(self, app):
self._app = app
def data_received(self, cmd, data, lqi):
#LOGGER.warning("data_received")
LOGGER.warning("data received %s %s LQI:%s", hex(cmd),
binascii.hexlify(data), lqi)
if cmd not in RESPONSES:
LOGGER.error('Received unhandled response 0x%04x', cmd)
return
data, rest = t.deserialize(data, RESPONSES[cmd])
if cmd == 0x8000:
if data[2] in self._status_awaiting:
fut = self._status_awaiting.pop(data[2])
fut.set_result((data, lqi))
if cmd in self._awaiting:
fut = self._awaiting.pop(cmd)
fut.set_result((data, lqi))
self.handle_callback(cmd, data, lqi)
async def command(self, cmd, data=b'', wait_response=None, wait_status=True):
tries = 2
while tries > 0:
tries -= 1
await self._lock.acquire()
try:
return await asyncio.wait_for(
self._command(cmd, data, wait_response, wait_status),
timeout=COMMAND_TIMEOUT
)
except asyncio.TimeoutError:
LOGGER.warning("No response to command 0x%04x", cmd)
if tries > 0:
LOGGER.warning("Retry command 0x%04x", cmd)
LOGGER.warning("Close uart")
self.close()
LOGGER.warning("connect uart")
await self.connect()
else:
raise NoResponseError
finally:
self._lock.release()
def _command(self, cmd, data=b'', wait_response=None, wait_status=True):
self.lock = True
self._uart.send(cmd, data)
if wait_status:
fut = asyncio.Future()
self._status_awaiting[cmd] = fut
if wait_response:
fut = asyncio.Future()
self._awaiting[wait_response] = fut
self.lock = False
if wait_status or wait_response:
return fut
async def version(self):
return await self.command(0x0010, wait_response=0x8010)
async def version_str(self):
version, lqi = await self.version()
version = '{:x}'.format(version[1])
version = '{}.{}'.format(version[0], version[1:])
return version
async def get_network_state(self):
return await self.command(0x0009, wait_response=0x8009)
async def set_raw_mode(self, enable=True):
data = t.serialize([enable], COMMANDS[0x0002])
await self.command(0x0002, data)
async def reset(self):
self._command(0x0011, wait_status=False)
async def erase_persistent_data(self):
self._command(0x0012, wait_status=False)
async def set_time(self, dt=None):
""" set internal time
if timestamp is None, now is used
"""
dt = dt or datetime.datetime.now()
timestamp = int((dt - datetime.datetime(2000, 1, 1)).total_seconds())
data = t.serialize([timestamp], COMMANDS[0x0016])
self._command(0x0016, data)
async def get_time_server(self):
timestamp, lqi = await self._command(0x0017, wait_response=0x8017)
dt = datetime.datetime(2000, 1, 1) + datetime.timedelta(seconds=timestamp[0])
return dt
async def set_led(self, enable=True):
data = t.serialize([enable], COMMANDS[0x0018])
await self.command(0x0018, data)
async def set_certification(self, typ='CE'):
cert = {'CE': 1, 'FCC': 2}[typ]
data = t.serialize([cert], COMMANDS[0x0019])
await self.command(0x0019, data)
async def set_tx_power(self, power=63):
if power > 63:
power = 63
if power < 0:
power = 0
data = t.serialize([power], COMMANDS[0x0806])
power, lqi = await self.command(0x0806, data, wait_response=0x8806)
return power[0]
async def set_channel(self, channels=None):
channels = channels or [11, 14, 15, 19, 20, 24, 25, 26]
if not isinstance(channels, list):
channels = [channels]
mask = functools.reduce(lambda acc, x: acc ^ 2 ** x, channels, 0)
data = t.serialize([mask], COMMANDS[0x0021])
await self.command(0x0021, data),
async def set_extended_panid(self, extended_pan_id):
data = t.serialize([extended_pan_id], COMMANDS[0x0020])
await self.command(0x0020, data)
async def permit_join(self, duration=60):
data = t.serialize([0xfffc, duration, 0], COMMANDS[0x0049])
return await self.command(0x0049, data)
async def start_network(self):
return await self.command(0x0024, wait_response=0x8024)
async def remove_device(self, zigate_ieee, ieee):
data = t.serialize([zigate_ieee, ieee], COMMANDS[0x0026])
return await self.command(0x0026, data)
async def raw_aps_data_request(self, addr, src_ep, dst_ep, profile,
cluster, payload, addr_mode=2, security=0):
'''
Send raw APS Data request
'''
radius = 0
data = t.serialize([addr_mode, addr,
src_ep, dst_ep, cluster, profile,
security, radius, payload], COMMANDS[0x0530])
return await self.command(0x0530, data)
def handle_callback(self, *args):
"""run application callback handler"""
if self._app:
try:
self._app.zigate_callback_handler(*args)
except Exception as e:
LOGGER.exception("Exception running handler", exc_info=e)
@classmethod
async def probe(cls, device_config: Dict[str, Any]) -> bool:
"""Probe port for the device presence."""
api = cls(zigpy_zigate.config.SCHEMA_DEVICE(device_config))
try:
await asyncio.wait_for(api._probe(), timeout=PROBE_TIMEOUT)
return True
except (
asyncio.TimeoutError,
serial.SerialException,
zigpy.exceptions.ZigbeeException,
) as exc:
LOGGER.debug(
"Unsuccessful radio probe of '%s' port",
device_config[zigpy_zigate.config.CONF_DEVICE_PATH],
exc_info=exc,
)
finally:
api.close()
return False
async def _probe(self) -> None:
"""Open port and try sending a command"""
try:
device = next(serial.tools.list_ports.grep(self._config[zigpy_zigate.config.CONF_DEVICE_PATH]))
if device.description == 'ZiGate':
return
except StopIteration:
pass
await self.connect()
await self.set_raw_mode()
Why are you not submitting a PR ? so your patch would be merge into the code
Because I've tested, and I have an other error I need to solve that before the PR.
After 24 h of usage I have this : the thread goes into an error, and I don't know why :(
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:07:15 ERROR (Thread-4) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:11 ERROR (Thread-566) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:11 ERROR (Thread-559) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:13 WARNING (Thread-554) [zigpy_zigate.api] No response to command 0x0009
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:13 WARNING (Thread-554) [zigpy_zigate.api] Retry command 0x0009
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:13 WARNING (Thread-554) [zigpy_zigate.api] Close uart
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:13 ERROR (Thread-554) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:15 WARNING (Thread-571) [zigpy_zigate.api] No response to command 0x0009
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:15 WARNING (Thread-571) [zigpy_zigate.api] Retry command 0x0009
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:15 WARNING (Thread-571) [zigpy_zigate.api] Close uart
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:15 WARNING (Thread-571) [zigpy_zigate.api] connect uart
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:15 ERROR (Thread-4) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:16 WARNING (Thread-571) [zigpy_zigate.api] No response to command 0x0009
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:12:16 ERROR (Thread-571) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:13:13 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:13:13 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0530
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:13:13 WARNING (MainThread) [zigpy_zigate.api] Close uart
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:13:13 WARNING (MainThread) [zigpy_zigate.api] connect uart
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:13:15 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:13:15 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0530
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:13:15 WARNING (MainThread) [zigpy_zigate.api] Close uart
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:13:15 WARNING (MainThread) [zigpy_zigate.api] connect uart
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:13:17 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:13:18 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:16:25 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0530
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:16:25 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0530
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:16:25 WARNING (MainThread) [zigpy_zigate.api] Close uart
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:16:25 WARNING (MainThread) [zigpy_zigate.api] connect uart
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:17:12 ERROR (Thread-559) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:17:13 ERROR (Thread-554) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:17:15 ERROR (Thread-577) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:18:15 ERROR (Thread-580) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:22:13 ERROR (Thread-554) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:22:13 ERROR (Thread-566) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:22:16 ERROR (Thread-4) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:23:15 ERROR (Thread-579) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:27:13 ERROR (Thread-554) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:27:13 ERROR (Thread-559) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:27:16 ERROR (Thread-577) [zigpy_zigate.api] thread error
home_assistant.1.5ktr66b42u1p@ocre | 2021-12-11 20:28:17 ERROR (Thread-580) [zigpy_zigate.api] thread error
You don't need to use threads when working with asyncio, you can use tasks:
async def connect(self):
...
self._watchdog_task = asyncio.create_task(self.watchdog_loop())
def close(self):
...
self._watchdog_task.cancel()
async def watchdog_loop(self):
while True:
await asyncio.sleep(30)
LOGGER.warning("Check ---")
try:
await self.get_network_state()
except Exception as exc:
LOGGER.warning("Failed to get network state, treating as disconnect", exc_info=exc)
self.connection_lost(exc) # Treat this as a disconnect
break
I don't have a ZiGate to test but this is roughly what other radio libraries do.
I don't know why I can't deal with asyncio, but I'm gone try again with your sample code. Thank you.
I tried updating to 0.8.0, it just doesn't work, my solution still works with the 0.7.3 package. I downgrade everything to HASS...
Very sad situation!
@baimard What does the debug log show with 0.8.0? https://www.home-assistant.io/integrations/zha/#debug-logging
home_assistant.1.iayelvp8clwa@home3 | 2022-03-16 20:52:17 WARNING (MainThread) [zigpy_zigate.zigbee.application] Extended error code 133
home_assistant.1.iayelvp8clwa@home3 | 2022-03-16 20:52:17 WARNING (MainThread) [zigpy_zigate.zigbee.application] Extended error code 133
home_assistant.1.iayelvp8clwa@home3 | 2022-03-16 20:52:17 WARNING (MainThread) [zigpy_zigate.zigbee.application] Extended error code 133
home_assistant.1.iayelvp8clwa@home3 | 2022-03-16 20:52:17 WARNING (MainThread) [zigpy_zigate.zigbee.application] Extended error code 131
home_assistant.1.iayelvp8clwa@home3 | 2022-03-16 20:52:17 WARNING (MainThread) [zigpy_zigate.zigbee.application] Extended error code 131
home_assistant.1.iayelvp8clwa@home3 | 2022-03-16 20:52:17 WARNING (MainThread) [homeassistant.components.zha.core.channels.base] [0x1500:1:0x0001]: async_initialize: all attempts have failed: [DeliveryError('[0x1500:1:0x0001]: Message send failure'), DeliveryError('[0x1500:1:0x0001]: Message send failure'), DeliveryError('[0x1500:1:0x0001]: Message send failure'), DeliveryError('[0x1500:1:0x0001]: Message send failure')]
home_assistant.1.iayelvp8clwa@home3 | 2022-03-16 20:52:18 WARNING (MainThread) [zigpy_zigate.zigbee.application] Extended error code 133
home_assistant.1.iayelvp8clwa@home3 | 2022-03-16 20:52:18 WARNING (MainThread) [zigpy_zigate.zigbee.application] Extended error code 131
home_assistant.1.iayelvp8clwa@home3 | 2022-03-16 20:52:18 WARNING (MainThread) [zigpy_zigate.zigbee.application] Extended error code 131
home_assistant.1.iayelvp8clwa@home3 | 2022-03-16 20:52:18 WARNING (MainThread) [homeassistant.components.zha.core.channels.base] [0x1500:1:0x0405]: async_initialize: all attempts have failed: [DeliveryError('[0x1500:1:0x0405]: Message send failure'), DeliveryError('[0x1500:1:0x0405]: Message send failure'), DeliveryError('[0x1500:1:0x0405]: Message send failure'), DeliveryError('[0x1500:1:0x0405]: Message send failure')]
you need more ?
Dear,
Home Assistant : 2021.5.4 ZHA : Last version in HASS ZiGate-WiFi v2.00 with esp-link v3.2.50-gfe4f565-dirty
I use Zigate wifi with ZHA in Home Assistant, after random time (30 min to 4hours), Home Assistant show that :
After this message, all my sensor light etc. not work with the device.
Home assistant don't send any request to my zigate wifi.
Tcpdump : 192.168.4.252 si my HASS 192.168.4.227 Zigate Wifi
So two questions :
Thank you