home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.07k stars 29.73k forks source link

Sometimes sensors don't work via ZHA until restarting the ZHA integration #93425

Closed segrey2k closed 8 months ago

segrey2k commented 1 year ago

The problem

The operation of the sensor through ZHA stops, sometimes, about once a day. After restarting the ZHA integration, the sensor works again. Only one sensor connected via ZHA based on ptvo.info.

What version of Home Assistant Core has the issue?

core-2023.5.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

zha

Link to integration documentation on our website

https://www.home-assistant.io/integrations/zha/

Diagnostics information

config_entry-zha-a1f1a2a7ec71ca2c2e8dd56cf2fc8492.json (1).txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2023-05-23 13:25:25.318 DEBUG (MainThread) [zigpy_znp.api] Received command: SYS.ResetInd.Callback(Reason=<ResetReason.PowerUp: 0>, TransportRev=2, ProductId=2, MajorRel=2, MinorRel=7, MaintRel=2)
2023-05-23 13:25:25.319 DEBUG (MainThread) [zigpy_znp.api] Command was not handled
2023-05-23 13:25:53.438 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/zigpy_znp/api.py", line 1058, in request_callback_rsp
    return await callback_rsp
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/zigpy_znp/api.py", line 1055, in request_callback_rsp
    async with async_timeout.timeout(timeout):
  File "/usr/local/lib/python3.10/site-packages/async_timeout/__init__.py", line 129, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.10/site-packages/async_timeout/__init__.py", line 212, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
2023-05-23 13:25:53.494 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/zigpy_znp/api.py", line 1056, in request_callback_rsp
    await self.request(request, timeout=timeout, **response_params)
  File "/usr/local/lib/python3.10/site-packages/zigpy_znp/api.py", line 1017, in request
    response = await response_future
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/zigpy_znp/api.py", line 1055, in request_callback_rsp
    async with async_timeout.timeout(timeout):
  File "/usr/local/lib/python3.10/site-packages/async_timeout/__init__.py", line 129, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.10/site-packages/async_timeout/__init__.py", line 212, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
2023-05-23 13:25:53.505 DEBUG (MainThread) [zigpy_znp.api] Sending request: AF.DataRequestExt.Req(DstAddrModeAddress=AddrModeAddress(mode=<AddrMode.NWK: 2>, address=0x1C48), DstEndpoint=5, DstPanId=0x0000, SrcEndpoint=1, ClusterId=12, TSN=241, Options=<TransmitOptions.SUPPRESS_ROUTE_DISC_NETWORK|ACK_REQUEST: 48>, Radius=0, Data=b'\x18\xF1\x0B\x0A\x00')
2023-05-23 13:25:53.512 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/zigpy_znp/api.py", line 1056, in request_callback_rsp
    await self.request(request, timeout=timeout, **response_params)
  File "/usr/local/lib/python3.10/site-packages/zigpy_znp/api.py", line 1017, in request
    response = await response_future
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/zigpy_znp/api.py", line 1055, in request_callback_rsp
    async with async_timeout.timeout(timeout):
  File "/usr/local/lib/python3.10/site-packages/async_timeout/__init__.py", line 129, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.10/site-packages/async_timeout/__init__.py", line 212, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
2023-05-23 13:25:53.527 DEBUG (MainThread) [zigpy_znp.api] Sending request: SYS.Ping.Req()
2023-05-23 13:25:53.543 DEBUG (MainThread) [zigpy_znp.api] Received command: AF.DataRequestExt.Rsp(Status=<Status.INVALID_PARAMETER: 2>)
2023-05-23 13:25:53.544 DEBUG (MainThread) [zigpy_znp.api] Command was not handled
2023-05-23 13:25:53.546 DEBUG (MainThread) [zigpy_znp.api] Received command: SYS.Ping.Rsp(Capabilities=<MTCapabilities.APP_CNF|GP|APP|UTIL|SAPI|ZDO|AF|SYS: 1913>)
2023-05-23 13:26:20.623 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x1C48](sensors02): Device seen - marking the device available and resetting counter
2023-05-23 13:26:20.624 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x1C48](sensors02): Update device availability -  device available: True - new availability: True - changed: False
2023-05-23 13:26:23.552 DEBUG (MainThread) [zigpy_znp.api] Sending request: SYS.Ping.Req()
2023-05-23 13:26:23.567 DEBUG (MainThread) [zigpy_znp.api] Received command: SYS.Ping.Rsp(Capabilities=<MTCapabilities.APP_CNF|GP|APP|UTIL|SAPI|ZDO|AF|SYS: 1913>)
2023-05-23 13:26:53.573 DEBUG (MainThread) [zigpy_znp.api] Sending request: SYS.Ping.Req()
2023-05-23 13:26:53.587 DEBUG (MainThread) [zigpy_znp.api] Received command: SYS.Ping.Rsp(Capabilities=<MTCapabilities.APP_CNF|GP|APP|UTIL|SAPI|ZDO|AF|SYS: 1913>)
2023-05-23 13:27:23.593 DEBUG (MainThread) [zigpy_znp.api] Sending request: SYS.Ping.Req()
2023-05-23 13:27:23.607 DEBUG (MainThread) [zigpy_znp.api] Received command: SYS.Ping.Rsp(Capabilities=<MTCapabilities.APP_CNF|GP|APP|UTIL|SAPI|ZDO|AF|SYS: 1913>)

Additional information

Sensor works via my custom quirk. There are 3 DS18B20 sensors with cc2530. Firmware made via ptvo.info.

home-assistant[bot] commented 1 year ago

Hey there @dmulcahey, @adminiuga, @puddly, mind taking a look at this issue as it has been labeled with an integration (zha) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `zha` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign zha` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


zha documentation zha source (message by IssueLinks)

puddly commented 1 year ago

Please include the custom quirk and the diagnostics for this specific device.

segrey2k commented 1 year ago

my custom quirk:


"""Device handler for PTVO dallas sensors (3) temp and voltage inside"""
import logging
from zigpy.profiles import zha
from zigpy.quirks import CustomCluster, CustomDevice
from zhaquirks import Bus, LocalDataCluster
from zigpy.zcl.clusters.homeautomation import Diagnostic, ElectricalMeasurement
from zigpy.zcl.clusters.general import Basic, AnalogInput, MultistateValue, MultistateInput, PowerConfiguration
from zigpy.zcl.clusters.measurement import TemperatureMeasurement
from zigpy.zcl.clusters.smartenergy import Metering

from zhaquirks.const import (
    DEVICE_TYPE,
    ENDPOINTS,
    INPUT_CLUSTERS,
    MODELS_INFO,
    OUTPUT_CLUSTERS,
    PROFILE_ID,
)

_LOGGER = logging.getLogger(__name__)

TEMPERATURE_REPORTED = "temperature_reported"
ELECTRICAL_REPORTED = "electrical_reported"

class AnalogInputCluster(CustomCluster, AnalogInput):
    """Analog input cluster, for temperature and voltage measurenent."""

    cluster_id = AnalogInput.cluster_id

    def __init__(self, *args, **kwargs):
        """Init."""
        self._current_state = {}
        super().__init__(*args, **kwargs)

    def _update_attribute(self, attrid, value):
        super()._update_attribute(attrid, value)
        if value is not None and attrid == 0x0055 and self.endpoint.endpoint_id < 5: # temperature in 1-4 clusters
            self.endpoint.device.temperature_bus.listener_event(TEMPERATURE_REPORTED, [self.endpoint.endpoint_id, round(value * 100)])
        elif value is not None and attrid == 0x0055 and self.endpoint.endpoint_id == 5: # voltage in 5 cluster
            self.endpoint.device.electrical_bus.listener_event(ELECTRICAL_REPORTED, round(value * 100))
#        else:
#            _LOGGER.warning(
#                "[0x%04x:%s:0x%04x] unhandled attribute: 0x%04x",
#                self.endpoint.device.nwk,
#                self.endpoint.endpoint_id,
#                self.cluster_id,
#                attrid,
#            )

class TemperatureMeasurementCluster(CustomCluster, TemperatureMeasurement):

    cluster_id = TemperatureMeasurement.cluster_id
    #ATTR_ID = 0
    MEASURED_VALUE_ID = 0x0000

    def __init__(self, *args, **kwargs):
        """Init."""
        super().__init__(*args, **kwargs)
        self.endpoint.device.temperature_bus.add_listener(self)

    def temperature_reported(self, value):
        """Temperature reported."""
        if self.endpoint.endpoint_id == value[0]:
            self._update_attribute(self.MEASURED_VALUE_ID, value[1])

class ElectricalMeasurementCluster(CustomCluster, ElectricalMeasurement):

    cluster_id = ElectricalMeasurement.cluster_id
    POWER_ID = 0x050B
    VOLTAGE_ID = 0x0505
    CURRENT_ID = 0x0508
    FREQUENCY_ID = 0x0300
    POWER_FACTOR_ID = 0x0510

    def __init__(self, *args, **kwargs):
        """Init."""
        super().__init__(*args, **kwargs)
        self.endpoint.device.electrical_bus.add_listener(self)

    def electrical_reported(self, value):
        """Voltage reported."""
#        if self.endpoint.endpoint_id == 5:
        self._update_attribute(self.VOLTAGE_ID, value/100)

class sensors02(CustomDevice):
    """Dallas sensors based on PTVO firmware."""

    def __init__(self, *args, **kwargs):
        """Init device."""
        self.temperature_bus = Bus()
        self.electrical_bus = Bus()

        super().__init__(*args, **kwargs)

    signature = {
        ENDPOINTS: {
        1: {
          PROFILE_ID: 0x0104,
          DEVICE_TYPE: 0x0100,
          INPUT_CLUSTERS: [
            Basic.cluster_id,
            AnalogInput.cluster_id,
          ],
          OUTPUT_CLUSTERS: [Basic.cluster_id]
        },
        2: {
          PROFILE_ID: 0x0104,
          DEVICE_TYPE: 0x0100,
          INPUT_CLUSTERS: [AnalogInput.cluster_id],
          OUTPUT_CLUSTERS: []
        },
        3: {
          PROFILE_ID: 0x0104,
          DEVICE_TYPE: 0x0100,
          INPUT_CLUSTERS: [AnalogInput.cluster_id],
          OUTPUT_CLUSTERS: []
        },
        4: {
          PROFILE_ID: 0x0104,
          DEVICE_TYPE: 0x0100,
          INPUT_CLUSTERS: [AnalogInput.cluster_id],
          OUTPUT_CLUSTERS: []
        },
        5: {
          PROFILE_ID: 0x0104,
          DEVICE_TYPE: 0x0100,
          INPUT_CLUSTERS: [AnalogInput.cluster_id],
          OUTPUT_CLUSTERS: []
        },
      },
      MODELS_INFO: [("ptvo.info", "sensors02")]
    }

    replacement = {
        ENDPOINTS: {
           1: {
                DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR,
                INPUT_CLUSTERS: [
                    Basic,
                    AnalogInputCluster,
                    TemperatureMeasurementCluster,
                ],
                OUTPUT_CLUSTERS: [Basic],
            },
            2: {
                DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR,
                INPUT_CLUSTERS: [
                    AnalogInputCluster,
                    TemperatureMeasurementCluster,
                ],
                OUTPUT_CLUSTERS: [],
            },
            3: {
                DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR,
                INPUT_CLUSTERS: [
                    AnalogInputCluster,
                    TemperatureMeasurementCluster,
                ],
                OUTPUT_CLUSTERS: [],
            },
            4: {
                DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR,
                INPUT_CLUSTERS: [
                    AnalogInputCluster,
                    TemperatureMeasurementCluster,
                    ElectricalMeasurementCluster,
                ],
                OUTPUT_CLUSTERS: [],
            },
            5: {
                DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR,
                INPUT_CLUSTERS: [
                    AnalogInputCluster,
                ],
                OUTPUT_CLUSTERS: [],
            },
        },
    }

Diagnostics: zha-a1f1a2a7ec71ca2c2e8dd56cf2fc8492-ptvo.info sensors02-1aaeadffceffbe1f27bb6aa453278fa9.json (27).txt

puddly commented 1 year ago

From the log:

2023-05-23 13:25:25.318 DEBUG (MainThread) [zigpy_znp.api] Received command: SYS.ResetInd.Callback(Reason=<ResetReason.PowerUp: 0>, TransportRev=2, ProductId=2, MajorRel=2, MinorRel=7, MaintRel=2)

It looks like your coordinator is physically rebooting. What coordinator is this?

segrey2k commented 1 year ago

Coordinator is сс2538 + сс2592 via UART. Flashed by MODKAMRU_V3_UART-no-flow-control.hex. I didn't restart coordinator or OS for resuming work of sensors, only ZHA.

kmil4 commented 1 year ago

I'm having a very similar issue suddenly.

mmichon commented 1 year ago

For my Sonoff 3.0, I need unplug and replug the USB dongle, then reload the integration. Upon reboot/HA restart, it reverts to error upon load. On Jun 11, 2023 at 9:22 PM -0700, kmil4 @.***>, wrote:

I'm having a very similar issue suddenly. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

issue-triage-workflows[bot] commented 12 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

segrey2k commented 12 months ago

I can't check it now, unfortunately. I'll do it later. Thank you for notification.

issue-triage-workflows[bot] commented 9 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.