Problem with energy summation on HIKING DDS238-2 Zigbee Smart Meter

Hi to all.
On March 11, 2023, the device stopped counting energy. The entity “sensor.licznik_summation_delivered” became unavailable. Up until that moment, everything had been working fine for several months. In the logs, I have the following error message:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/zigpy_deconz/uart.py", line 84, in data_received
    self._api.data_received(frame)
  File "/usr/local/lib/python3.10/site-packages/zigpy_deconz/api.py", line 373, in data_received
    getattr(self, f"_handle_{command.name}")(data)
  File "/usr/local/lib/python3.10/site-packages/zigpy_deconz/api.py", line 505, in _handle_aps_data_indication
    self._app.handle_rx(
  File "/usr/local/lib/python3.10/site-packages/zigpy_deconz/zigbee/application.py", line 430, in handle_rx
    self.packet_received(
  File "/usr/local/lib/python3.10/site-packages/zigpy/application.py", line 875, in packet_received
    self.handle_message(
  File "/usr/local/lib/python3.10/site-packages/zigpy/application.py", line 381, in handle_message
    return sender.handle_message(
  File "/usr/local/lib/python3.10/site-packages/zigpy/device.py", line 370, in handle_message
    self.endpoints[src_ep].handle_message(
  File "/usr/local/lib/python3.10/site-packages/zigpy/endpoint.py", line 224, in handle_message
    handler(hdr, args, dst_addressing=dst_addressing)
  File "/usr/local/lib/python3.10/site-packages/zigpy/zcl/__init__.py", line 373, in handle_message
    self.handle_cluster_request(hdr, args, dst_addressing=dst_addressing)
  File "/usr/local/lib/python3.10/site-packages/zhaquirks/tuya/__init__.py", line 494, in handle_cluster_request
    zvalue = ztype(tuya_data)
  File "/usr/local/lib/python3.10/site-packages/zigpy/types/basic.py", line 96, in __new__
    raise ValueError(
ValueError: 72071 is not an unsigned 16 bit integer

The number 72071 corresponds to the current reading of the meter, which is 720.71 kWh. "I tried to pair the device again, restore a backup from the beginning of March, as well as install on a clean installation.

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2023.4.6",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.10.10",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/Warsaw",
    "os_name": "Linux",
    "os_version": "6.1.24",
    "supervisor": "2023.04.0",
    "host_os": "Home Assistant OS 10.0",
    "docker_version": "23.0.3",
    "chassis": "vm",
    "run_as_root": true
  },
  "custom_components": {
    "xiaomi_gateway3": {
      "version": "3.2.1",
      "requirements": [
        "zigpy>=0.44.1"
      ]
    },
    "ble_monitor": {
      "version": "11.9.0",
      "requirements": [
        "pycryptodomex>=3.14.1",
        "janus>=1.0.0",
        "aioblescan>=0.2.14",
        "btsocket>=0.2.0",
        "pyric>=0.1.6.3"
      ]
    },
    "better_thermostat": {
      "version": "1.0.2",
      "requirements": []
    },
    "hacs": {
      "version": "1.32.1",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    },
    "xiaomi_miot": {
      "version": "0.7.7",
      "requirements": [
        "construct==2.10.56",
        "python-miio>=0.5.6",
        "micloud>=0.3"
      ]
    }
  },
  "integration_manifest": {
    "domain": "zha",
    "name": "Zigbee Home Automation",
    "after_dependencies": [
      "onboarding",
      "usb"
    ],
    "codeowners": [
      "@dmulcahey",
      "@adminiuga",
      "@puddly"
    ],
    "config_flow": true,
    "dependencies": [
      "file_upload"
    ],
    "documentation": "https://www.home-assistant.io/integrations/zha",
    "iot_class": "local_polling",
    "loggers": [
      "aiosqlite",
      "bellows",
      "crccheck",
      "pure_pcapy3",
      "zhaquirks",
      "zigpy",
      "zigpy_deconz",
      "zigpy_xbee",
      "zigpy_zigate",
      "zigpy_znp"
    ],
    "requirements": [
      "bellows==0.35.1",
      "pyserial==3.5",
      "pyserial-asyncio==0.6",
      "zha-quirks==0.0.97",
      "zigpy-deconz==0.20.0",
      "zigpy==0.54.1",
      "zigpy-xbee==0.17.0",
      "zigpy-zigate==0.10.3",
      "zigpy-znp==0.10.0"
    ],
    "usb": [
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*2652*",
        "known_devices": [
          "slae.sh cc2652rb stick"
        ]
      },
      {
        "vid": "1A86",
        "pid": "55D4",
        "description": "*sonoff*plus*",
        "known_devices": [
          "sonoff zigbee dongle plus v2"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*sonoff*plus*",
        "known_devices": [
          "sonoff zigbee dongle plus"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*tubeszb*",
        "known_devices": [
          "TubesZB Coordinator"
        ]
      },
      {
        "vid": "1A86",
        "pid": "7523",
        "description": "*tubeszb*",
        "known_devices": [
          "TubesZB Coordinator"
        ]
      },
      {
        "vid": "1A86",
        "pid": "7523",
        "description": "*zigstar*",
        "known_devices": [
          "ZigStar Coordinators"
        ]
      },
      {
        "vid": "1CF1",
        "pid": "0030",
        "description": "*conbee*",
        "known_devices": [
          "Conbee II"
        ]
      },
      {
        "vid": "10C4",
        "pid": "8A2A",
        "description": "*zigbee*",
        "known_devices": [
          "Nortek HUSBZB-1"
        ]
      },
      {
        "vid": "0403",
        "pid": "6015",
        "description": "*zigate*",
        "known_devices": [
          "ZiGate+"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*zigate*",
        "known_devices": [
          "ZiGate"
        ]
      },
      {
        "vid": "10C4",
        "pid": "8B34",
        "description": "*bv 2010/10*",
        "known_devices": [
          "Bitron Video AV2010/10"
        ]
      }
    ],
    "zeroconf": [
      {
        "type": "_esphomelib._tcp.local.",
        "name": "tube*"
      },
      {
        "type": "_zigate-zigbee-gateway._tcp.local.",
        "name": "*zigate*"
      },
      {
        "type": "_zigstar_gw._tcp.local.",
        "name": "*zigstar*"
      },
      {
        "type": "_slzb-06._tcp.local.",
        "name": "slzb-06*"
      }
    ],
    "is_built_in": true
  },
  "data": {
    "ieee": "**REDACTED**",
    "nwk": 30556,
    "manufacturer": "_TZE200_ewxhg6o9",
    "model": "TS0601",
    "name": "_TZE200_ewxhg6o9 TS0601",
    "quirk_applied": true,
    "quirk_class": "zhaquirks.tuya.ts0601_din_power.TuyaPowerMeter",
    "manufacturer_code": 4098,
    "power_source": "Mains",
    "lqi": 255,
    "rssi": -57,
    "last_seen": "2023-04-24T10:56:19",
    "available": true,
    "device_type": "Router",
    "signature": {
      "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.Router: 1>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress|RxOnWhenIdle|MainsPowered|FullFunctionDevice: 142>, manufacturer_code=4098, maximum_buffer_size=82, maximum_incoming_transfer_size=82, server_mask=11264, maximum_outgoing_transfer_size=82, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=True, *is_security_capable=False)",
      "endpoints": {
        "1": {
          "profile_id": 260,
          "device_type": "0x0051",
          "in_clusters": [
            "0x0000",
            "0x0004",
            "0x0005",
            "0x0006",
            "0x0702",
            "0x0b04",
            "0xef00"
          ],
          "out_clusters": [
            "0x000a",
            "0x0019"
          ]
        }
      }
    },
    "active_coordinator": false,
    "entities": [
      {
        "entity_id": "sensor.licznik_active_power",
        "name": "_TZE200_ewxhg6o9 TS0601"
      },
      {
        "entity_id": "sensor.licznik_rms_current",
        "name": "_TZE200_ewxhg6o9 TS0601"
      },
      {
        "entity_id": "sensor.licznik_rms_voltage",
        "name": "_TZE200_ewxhg6o9 TS0601"
      },
      {
        "entity_id": "sensor.licznik_power_factor",
        "name": "_TZE200_ewxhg6o9 TS0601"
      },
      {
        "entity_id": "switch.licznik_switch",
        "name": "_TZE200_ewxhg6o9 TS0601"
      }
    ],
    "neighbors": [
      {
        "device_type": "Coordinator",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x0000",
        "permit_joining": "Unknown",
        "depth": "0",
        "lqi": "189"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x0543",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "160"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x0E9F",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "168"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x1B73",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "112"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x3490",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "136"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x3F95",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "168"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x45D3",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "142"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x7CA1",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "98"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xAB37",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "155"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xC403",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "145"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xCD5A",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "142"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Parent",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xE3D4",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "220"
      }
    ],
    "routes": [
      {
        "dest_nwk": "0x0000",
        "route_status": "Active",
        "memory_constrained": false,
        "many_to_one": true,
        "route_record_required": false,
        "next_hop": "0x0000"
      },
      {
        "dest_nwk": "0x341B",
        "route_status": "Active",
        "memory_constrained": false,
        "many_to_one": false,
        "route_record_required": false,
        "next_hop": "0xE3D4"
      },
      {
        "dest_nwk": "0xC403",
        "route_status": "Active",
        "memory_constrained": false,
        "many_to_one": false,
        "route_record_required": false,
        "next_hop": "0xE3D4"
      },
      {
        "dest_nwk": "0xBF3D",
        "route_status": "Active",
        "memory_constrained": false,
        "many_to_one": false,
        "route_record_required": false,
        "next_hop": "0xBF3D"
      }
    ],
    "endpoint_names": [
      {
        "name": "SMART_PLUG"
      }
    ],
    "user_given_name": "Licznik",
    "device_reg_id": "5bc7f83e8f33ec763055592478e0cfd7",
    "area_id": "korytarz",
    "cluster_details": {
      "1": {
        "device_type": {
          "name": "SMART_PLUG",
          "id": 81
        },
        "profile_id": 260,
        "in_clusters": {
          "0x0000": {
            "endpoint_attribute": "basic",
            "attributes": {
              "0x0001": {
                "attribute_name": "app_version",
                "value": 68
              },
              "0x0004": {
                "attribute_name": "manufacturer",
                "value": "_TZE200_ewxhg6o9"
              },
              "0x0005": {
                "attribute_name": "model",
                "value": "TS0601"
              }
            },
            "unsupported_attributes": {}
          },
          "0x0004": {
            "endpoint_attribute": "groups",
            "attributes": {},
            "unsupported_attributes": {
              "0xfffe": {
                "attribute_name": "attr_reporting_status"
              }
            }
          },
          "0x0005": {
            "endpoint_attribute": "scenes",
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0xef00": {
            "endpoint_attribute": "tuya_manufacturer",
            "attributes": {
              "0x0212": {
                "attribute_name": "current",
                "value": 932
              },
              "0x0213": {
                "attribute_name": "power",
                "value": 1113
              },
              "0x0214": {
                "attribute_name": "voltage",
                "value": 2351
              },
              "0x0101": {
                "attribute_name": "switch",
                "value": 1
              }
            },
            "unsupported_attributes": {}
          },
          "0x0b04": {
            "endpoint_attribute": "electrical_measurement",
            "attributes": {
              "0x0400": {
                "attribute_name": "ac_frequency_multiplier",
                "value": 1
              },
              "0x0401": {
                "attribute_name": "ac_frequency_divisor",
                "value": 100
              },
              "0x0505": {
                "attribute_name": "rms_voltage",
                "value": 235.1
              },
              "0x0508": {
                "attribute_name": "rms_current",
                "value": 932
              },
              "0x050b": {
                "attribute_name": "active_power",
                "value": 111.3
              },
              "0x0602": {
                "attribute_name": "ac_current_multiplier",
                "value": 1
              },
              "0x0603": {
                "attribute_name": "ac_current_divisor",
                "value": 1000
              }
            },
            "unsupported_attributes": {
              "0x0600": {
                "attribute_name": "ac_voltage_multiplier"
              },
              "0x0601": {
                "attribute_name": "ac_voltage_divisor"
              },
              "0x0000": {
                "attribute_name": "measurement_type"
              },
              "0x0403": {
                "attribute_name": "power_divisor"
              },
              "0x0604": {
                "attribute_name": "ac_power_multiplier"
              },
              "0x0605": {
                "attribute_name": "ac_power_divisor"
              },
              "0x0402": {
                "attribute_name": "power_multiplier"
              },
              "0x0507": {
                "attribute_name": "rms_voltage_max"
              },
              "0x0300": {
                "attribute_name": "ac_frequency"
              },
              "0x050a": {
                "attribute_name": "rms_current_max"
              },
              "0x0302": {
                "attribute_name": "ac_frequency_max"
              },
              "0x050d": {
                "attribute_name": "active_power_max"
              },
              "0x050f": {
                "attribute_name": "apparent_power"
              }
            }
          },
          "0x0702": {
            "endpoint_attribute": "smartenergy_metering",
            "attributes": {
              "0x0300": {
                "attribute_name": "unit_of_measure",
                "value": 0
              }
            },
            "unsupported_attributes": {
              "0x0400": {
                "attribute_name": "instantaneous_demand"
              },
              "0x0301": {
                "attribute_name": "multiplier"
              },
              "0x0302": {
                "attribute_name": "divisor"
              },
              "0x0303": {
                "attribute_name": "summation_formatting"
              },
              "0x0304": {
                "attribute_name": "demand_formatting"
              },
              "0x0306": {
                "attribute_name": "metering_device_type"
              },
              "0x0000": {
                "attribute_name": "current_summ_delivered"
              },
              "0x0100": {
                "attribute_name": "current_tier1_summ_delivered"
              },
              "0x0102": {
                "attribute_name": "current_tier2_summ_delivered"
              },
              "0x0104": {
                "attribute_name": "current_tier3_summ_delivered"
              },
              "0x0106": {
                "attribute_name": "current_tier4_summ_delivered"
              },
              "0x0108": {
                "attribute_name": "current_tier5_summ_delivered"
              },
              "0x010a": {
                "attribute_name": "current_tier6_summ_delivered"
              },
              "0x0200": {
                "attribute_name": "status"
              }
            }
          },
          "0x0006": {
            "endpoint_attribute": "on_off",
            "attributes": {
              "0x0000": {
                "attribute_name": "on_off",
                "value": 1
              }
            },
            "unsupported_attributes": {
              "0x0000": {
                "attribute_name": "on_off"
              },
              "0x4003": {
                "attribute_name": "start_up_on_off"
              }
            }
          }
        },
        "out_clusters": {
          "0x000a": {
            "endpoint_attribute": "time",
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0x0019": {
            "endpoint_attribute": "ota",
            "attributes": {},
            "unsupported_attributes": {}
          }
        }
      }
    }
  }
}

1 Like

same situation here.
sensor.hiking_summation_delivered does not update and therefore energy dashboard shows no consumption.
Should we report issue to ZHA issue tracker somewhere?

Same to me… 67302 is exactly the meter reading 673.02 kWh

2023-04-14 21:36:49.726 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/zigbee/application.py", line 592, in on_af_message
    self.packet_received(
  File "/usr/local/lib/python3.10/site-packages/zigpy/application.py", line 946, in packet_received
    self.handle_message(
  File "/usr/local/lib/python3.10/site-packages/zigpy/application.py", line 461, in handle_message
    return sender.handle_message(
  File "/usr/local/lib/python3.10/site-packages/zigpy/device.py", line 374, in handle_message
    self.endpoints[src_ep].handle_message(
  File "/usr/local/lib/python3.10/site-packages/zigpy/endpoint.py", line 224, in handle_message
    handler(hdr, args, dst_addressing=dst_addressing)
  File "/usr/local/lib/python3.10/site-packages/zigpy/zcl/__init__.py", line 375, in handle_message
    self.handle_cluster_request(hdr, args, dst_addressing=dst_addressing)
  File "/usr/local/lib/python3.10/site-packages/zhaquirks/tuya/__init__.py", line 494, in handle_cluster_request
    zvalue = ztype(tuya_data)
  File "/usr/local/lib/python3.10/site-packages/zigpy/types/basic.py", line 94, in __new__
    raise ValueError(
ValueError: 67302 is not an unsigned 16 bit integer

How we can fix it?

Same here. I have not been doing any updates either of HA or zigbee2mqtt….

My problem has gone with the latest update:
Home Assistant 2023.4.5
Supervisor 2023.04.0
Operating System 10.0

I had to readd the device via ZHA integration and also do take note on changing sensor names.
“Summation” sensor is gone.
New Riemann integration sensor needs to be added that can be used in Energy Dashboard.
I’ve used sensor.hiking_active_power as a source for Riemann sensor.

My still not work.

Some extra info, for better understanding.
It’s custom zha quirks file, with this attr TUYA_TOTAL_ENERGY_ATTR: ("energy", t.uint16_t, True),

2023-05-11 05:05:43.066 DEBUG (MainThread) [zigpy_znp.api] Received command: AF.IncomingMsg.Callback(GroupId=0x0000, ClusterId=61184, SrcAddr=0x4EBB, SrcEndpoint=1, DstEndpoint=1, WasBroadcast=<Bool.false: 0>, LQI=18, SecurityUse=<Bool.false: 0>, TimeStamp=4079236, TSN=0, Data=b'\x09\x07\x01\x00\x79\x11\x02\x00\x04\x00\x16\x77\xD9', MacSrcAddr=0x4EBB, MsgResultRadius=29)
2023-05-11 05:05:43.068 DEBUG (MainThread) [zigpy.application] Received a packet: ZigbeePacket(src=AddrModeAddress(addr_mode=<AddrMode.NWK: 2>, address=0x4EBB), src_ep=1, dst=AddrModeAddress(addr_mode=<AddrMode.NWK: 2>, address=0x0000), dst_ep=1, source_route=None, extended_timeout=False, tsn=0, profile_id=260, cluster_id=61184, data=Serialized[b'\t\x07\x01\x00y\x11\x02\x00\x04\x00\x16w\xd9'], tx_options=<TransmitOptions.NONE: 0>, radius=29, non_member_radius=0, lqi=18, rssi=None)
2023-05-11 05:05:43.070 DEBUG (MainThread) [zigpy.zcl] [0x4EBB:1:0xef00] Received ZCL frame: b'\t\x07\x01\x00y\x11\x02\x00\x04\x00\x16w\xd9'
2023-05-11 05:05:43.071 DEBUG (MainThread) [zigpy.zcl] [0x4EBB:1:0xef00] Decoded ZCL frame header: ZCLHeader(frame_control=FrameControl(frame_type=<FrameType.CLUSTER_COMMAND: 1>, is_manufacturer_specific=0, direction=<Direction.Client_to_Server: 1>, disable_default_response=0, reserved=0, *is_cluster=True, *is_general=False), tsn=7, command_id=1, *direction=<Direction.Client_to_Server: 1>)
2023-05-11 05:05:43.073 DEBUG (MainThread) [zigpy.zcl] [0x4EBB:1:0xef00] Decoded ZCL frame: TuyaManufClusterDinPower:get_data(param=Command(status=0, tsn=121, command_id=529, function=0, data=[4, 0, 22, 119, 217]))
2023-05-11 05:05:43.073 DEBUG (MainThread) [zigpy.zcl] [0x4EBB:1:0xef00] Received command 0x01 (TSN 7): get_data(param=Command(status=0, tsn=121, command_id=529, function=0, data=[4, 0, 22, 119, 217]))
2023-05-11 05:05:43.074 DEBUG (MainThread) [zhaquirks.tuya] [0x4ebb:1:0xef00] Received value [0, 22, 119, 217] for attribute 0x0211 (command 0x0001)
2023-05-11 05:05:43.075 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/zigbee/application.py", line 609, in on_af_message
	self.packet_received(
File "/usr/local/lib/python3.10/site-packages/zigpy/application.py", line 1007, in packet_received
	self.handle_message(
File "/usr/local/lib/python3.10/site-packages/zigpy/application.py", line 522, in handle_message
	return sender.handle_message(
File "/usr/local/lib/python3.10/site-packages/zigpy/device.py", line 374, in handle_message
	self.endpoints[src_ep].handle_message(
File "/usr/local/lib/python3.10/site-packages/zigpy/endpoint.py", line 230, in handle_message
	handler(hdr, args, dst_addressing=dst_addressing)
File "/usr/local/lib/python3.10/site-packages/zigpy/zcl/__init__.py", line 380, in handle_message
	self.handle_cluster_request(hdr, args, dst_addressing=dst_addressing)
File "/usr/local/lib/python3.10/site-packages/zhaquirks/tuya/__init__.py", line 494, in handle_cluster_request
	zvalue = ztype(tuya_data)
File "/usr/local/lib/python3.10/site-packages/zigpy/types/basic.py", line 94, in __new__
	raise ValueError(
ValueError: 1472473 is not an unsigned 16 bit integer

P.S. I’m not so familiar with zha to do tests in debugger…

I’m already created PR with fix, but it takes time to be merged, and included in HA patch release.
If you have Tuya/Hiking Energy Monitor you can try this zha quirk file:

  1. Add in you /config/configuration.yaml this lines:
zha:
  custom_quirks_path: /config/custom_zha_quirks/
  1. Place this code in /config/custom_zha_quirks/custom_ts0601_din_power.py and restart zha integration.
"""Tuya Din Power Meter."""
import logging
from zigpy.profiles import zha
import zigpy.types as t
from zigpy.zcl.clusters.general import Basic, Groups, Ota, Scenes, Time
from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement
from zigpy.zcl.clusters.smartenergy import Metering

from zhaquirks import Bus, LocalDataCluster
from zhaquirks.const import (
    DEVICE_TYPE,
    ENDPOINTS,
    INPUT_CLUSTERS,
    MODELS_INFO,
    OUTPUT_CLUSTERS,
    PROFILE_ID,
)
from zhaquirks.tuya import TuyaManufClusterAttributes, TuyaOnOff, TuyaSwitch

TUYA_TOTAL_ENERGY_ATTR = 0x0211
TUYA_CURRENT_ATTR = 0x0212
TUYA_POWER_ATTR = 0x0213
TUYA_VOLTAGE_ATTR = 0x0214
TUYA_DIN_SWITCH_ATTR = 0x0101

SWITCH_EVENT = "switch_event"

"""Hiking Power Meter Attributes"""
HIKING_DIN_SWITCH_ATTR = 0x0110
HIKING_TOTAL_ENERGY_DELIVERED_ATTR = 0x0201
HIKING_TOTAL_ENERGY_RECEIVED_ATTR = 0x0266
HIKING_VOLTAGE_CURRENT_ATTR = 0x0006
HIKING_POWER_ATTR = 0x0267
HIKING_FREQUENCY_ATTR = 0x0269
HIKING_POWER_FACTOR_ATTR = 0x026F
HIKING_TOTAL_REACTIVE_ATTR = 0x026D
HIKING_REACTIVE_POWER_ATTR = 0x026E


_LOGGER = logging.getLogger(__name__)


class TuyaManufClusterDinPower(TuyaManufClusterAttributes):
    """Manufacturer Specific Cluster of the Tuya Power Meter device."""

    attributes = {
        TUYA_TOTAL_ENERGY_ATTR: ("energy", t.uint32_t, True),
        TUYA_CURRENT_ATTR: ("current", t.int16s, True),
        TUYA_POWER_ATTR: ("power", t.uint16_t, True),
        TUYA_VOLTAGE_ATTR: ("voltage", t.uint16_t, True),
        TUYA_DIN_SWITCH_ATTR: ("switch", t.uint8_t, True),
    }

    def _update_attribute(self, attrid, value):
        super()._update_attribute(attrid, value)
        if attrid == TUYA_TOTAL_ENERGY_ATTR:
            self.endpoint.smartenergy_metering.energy_deliver_reported(value / 100)
        elif attrid == TUYA_CURRENT_ATTR:
            self.endpoint.electrical_measurement.current_reported(value)
        elif attrid == TUYA_POWER_ATTR:
            self.endpoint.electrical_measurement.power_reported(value / 10)
        elif attrid == TUYA_VOLTAGE_ATTR:
            self.endpoint.electrical_measurement.voltage_reported(value / 10)
        elif attrid == TUYA_DIN_SWITCH_ATTR:
            self.endpoint.device.switch_bus.listener_event(
                SWITCH_EVENT, self.endpoint.endpoint_id, value
            )


class TuyaPowerMeasurement(LocalDataCluster, ElectricalMeasurement):
    """Custom class for power, voltage and current measurement."""

    cluster_id = ElectricalMeasurement.cluster_id

    POWER_ID = 0x050B
    VOLTAGE_ID = 0x0505
    CURRENT_ID = 0x0508
    REACTIVE_POWER_ID = 0x050E
    AC_FREQUENCY_ID = 0x0300
    TOTAL_REACTIVE_POWER_ID = 0x0305
    POWER_FACTOR_ID = 0x0510

    AC_CURRENT_MULTIPLIER = 0x0602
    AC_CURRENT_DIVISOR = 0x0603
    AC_FREQUENCY_MULTIPLIER = 0x0400
    AC_FREQUENCY_DIVISOR = 0x0401

    _CONSTANT_ATTRIBUTES = {
        AC_CURRENT_MULTIPLIER: 1,
        AC_CURRENT_DIVISOR: 1000,
        AC_FREQUENCY_MULTIPLIER: 1,
        AC_FREQUENCY_DIVISOR: 100,
    }

    def voltage_reported(self, value):
        """Voltage reported."""
        self._update_attribute(self.VOLTAGE_ID, value)

    def power_reported(self, value):
        """Power reported."""
        self._update_attribute(self.POWER_ID, value)

    def power_factor_reported(self, value):
        """Power Factor reported."""
        self._update_attribute(self.POWER_FACTOR_ID, value)

    def reactive_power_reported(self, value):
        """Reactive Power reported."""
        self._update_attribute(self.REACTIVE_POWER_ID, value)

    def current_reported(self, value):
        """Ampers reported."""
        self._update_attribute(self.CURRENT_ID, value)

    def frequency_reported(self, value):
        """AC Frequency reported."""
        self._update_attribute(self.AC_FREQUENCY_ID, value)

    def reactive_energy_reported(self, value):
        """Summation Reactive Energy reported."""
        self._update_attribute(self.TOTAL_REACTIVE_POWER_ID, value)


class TuyaElectricalMeasurement(LocalDataCluster, Metering):
    """Custom class for total energy measurement."""

    cluster_id = Metering.cluster_id
    CURRENT_DELIVERED_ID = 0x0000
    CURRENT_RECEIVED_ID = 0x0001
    POWER_WATT = 0x0000

    """Setting unit of measurement."""
    _CONSTANT_ATTRIBUTES = {0x0300: POWER_WATT}

    def energy_deliver_reported(self, value):
        """Summation Energy Deliver reported."""
        self._update_attribute(self.CURRENT_DELIVERED_ID, value)

    def energy_receive_reported(self, value):
        """Summation Energy Receive reported."""
        self._update_attribute(self.CURRENT_RECEIVED_ID, value)


class HikingManufClusterDinPower(TuyaManufClusterAttributes):
    """Manufacturer Specific Cluster of the Hiking Power Meter device."""

    attributes = {
        HIKING_DIN_SWITCH_ATTR: ("switch", t.uint8_t, True),
        HIKING_TOTAL_ENERGY_DELIVERED_ATTR: ("energy_delivered", t.uint16_t, True),
        HIKING_TOTAL_ENERGY_RECEIVED_ATTR: ("energy_received", t.uint16_t, True),
        HIKING_VOLTAGE_CURRENT_ATTR: ("voltage_current", t.uint32_t, True),
        HIKING_POWER_ATTR: ("power", t.uint16_t, True),
        HIKING_FREQUENCY_ATTR: ("frequency", t.uint16_t, True),
        HIKING_TOTAL_REACTIVE_ATTR: ("total_reactive_energy", t.int32s, True),
        HIKING_REACTIVE_POWER_ATTR: ("reactive_power", t.int16s, True),
        HIKING_POWER_FACTOR_ATTR: ("power_factor", t.uint16_t, True),
    }

    def _update_attribute(self, attrid, value):
        super()._update_attribute(attrid, value)
        if attrid == HIKING_DIN_SWITCH_ATTR:
            self.endpoint.device.switch_bus.listener_event(SWITCH_EVENT, 16, value)
        elif attrid == HIKING_TOTAL_ENERGY_DELIVERED_ATTR:
            self.endpoint.smartenergy_metering.energy_deliver_reported(value / 100)
        elif attrid == HIKING_TOTAL_ENERGY_RECEIVED_ATTR:
            self.endpoint.smartenergy_metering.energy_receive_reported(value / 100)
        elif attrid == HIKING_VOLTAGE_CURRENT_ATTR:
            self.endpoint.electrical_measurement.current_reported(value >> 16)
            self.endpoint.electrical_measurement.voltage_reported(
                (value & 0x0000FFFF) / 10
            )
        elif attrid == HIKING_POWER_ATTR:
            self.endpoint.electrical_measurement.power_reported(value)
        elif attrid == HIKING_FREQUENCY_ATTR:
            self.endpoint.electrical_measurement.frequency_reported(value)
        elif attrid == HIKING_TOTAL_REACTIVE_ATTR:
            self.endpoint.electrical_measurement.reactive_energy_reported(value)
        elif attrid == HIKING_REACTIVE_POWER_ATTR:
            self.endpoint.electrical_measurement.reactive_power_reported(value)
        elif attrid == HIKING_POWER_FACTOR_ATTR:
            self.endpoint.electrical_measurement.power_factor_reported(value / 10)


class TuyaPowerMeter(TuyaSwitch):
    """Tuya power meter device."""

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

    signature = {
        # "node_descriptor": "<NodeDescriptor byte1=1 byte2=64 mac_capability_flags=142 manufacturer_code=4098
        #                       maximum_buffer_size=82 maximum_incoming_transfer_size=82 server_mask=11264
        #                       maximum_outgoing_transfer_size=82 descriptor_capability_field=0>",
        # device_version=1
        # input_clusters=[0x0000, 0x0004, 0x0005, 0xef00]
        # output_clusters=[0x000a, 0x0019]
        MODELS_INFO: [
            ("_TZE200_byzdayie", "TS0601"),
            ("_TZE200_ewxhg6o9", "TS0601"),
        ],
        ENDPOINTS: {
            # <SimpleDescriptor endpoint=1 profile=260 device_type=51
            # device_version=1
            # input_clusters=[0, 4, 5, 61184]
            # output_clusters=[10, 25]>
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    TuyaManufClusterAttributes.cluster_id,
                ],
                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
            }
        },
    }

    replacement = {
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    TuyaManufClusterDinPower,
                    TuyaPowerMeasurement,
                    TuyaElectricalMeasurement,
                    TuyaOnOff,
                ],
                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
            }
        }
    }


class HikingPowerMeter(TuyaSwitch):
    """Hiking Power Meter Device - DDS238-2."""

    signature = {
        # "node_descriptor": "<NodeDescriptor byte1=1 byte2=64 mac_capability_flags=142 manufacturer_code=4098
        #                       maximum_buffer_size=82 maximum_incoming_transfer_size=82 server_mask=11264
        #                       maximum_outgoing_transfer_size=82 descriptor_capability_field=0>",
        # device_version=1
        # input_clusters=[0x0000, 0x0004, 0x0005, 0xef00]
        # output_clusters=[0x000a, 0x0019]
        MODELS_INFO: [("_TZE200_bkkmqmyo", "TS0601")],
        ENDPOINTS: {
            # <SimpleDescriptor endpoint=1 profile=260 device_type=51
            # device_version=1
            # input_clusters=[0, 4, 5, 61184]
            # output_clusters=[10, 25]>
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    TuyaManufClusterAttributes.cluster_id,
                ],
                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
            }
        },
    }

    replacement = {
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    HikingManufClusterDinPower,
                    TuyaElectricalMeasurement,
                    TuyaPowerMeasurement,
                ],
                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
            },
            16: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    TuyaOnOff,
                ],
                OUTPUT_CLUSTERS: [],
            },
        }
    }

2 Likes

Good work gordio. Now working again . Nice
Thanks for help