-
Notifications
You must be signed in to change notification settings - Fork 713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Device Support Request] TS0601 by _TZE204_rhblgy0z DIN Power #2553
Comments
it seems the same device (same signature but different manufacturer) of issue #2549) |
@Srjosep |
I have no idea... searching for the same. I found some code for z2m, and the manufacturer data to make it work. But not sure where to start learning to create the quirk. Koenkk/zigbee2mqtt#18419 (comment) |
Hi, """Tuya Din Power Meter.""" from zhaquirks import Bus, LocalDataCluster TUYA_TOTAL_ENERGY_ATTR = 0x0211 SWITCH_EVENT = "switch_event" """Hiking Power Meter Attributes""" class TuyaPowerMeasurement(LocalDataCluster, ElectricalMeasurement):
class TuyaElectricalMeasurement(LocalDataCluster, Metering):
class HikingManufClusterDinPower(TuyaManufClusterAttributes):
class HikingPowerMeter(TuyaSwitch):
|
In the link I posted, they wrote a converter for z2m , and they posted the Dpid data, etc. I am still searching for any manual or tutorial to understand how quirks must be created,named and used... there is not much info out there....meanwhile I think I will change to z2m to test if the device works locally or not. I can send it back to the seller yet , so I must be sure it does before the return period ends.... |
It seems compatible with z2m : https://zigbee.blakadder.com/DAC2161C.html (the picture is the same) The Tuya reference is XOCA-DAC2161C BI (device name on IoT Tuya project) |
Yes sorry... I mean Tuya TS0601 TZE204_81yrt3lo, my device. It seems finally they are different. You can try asking the manufacturer...Did you find any manual or tutorial about quirk creation? |
I find this issue, I will try this quirk : #1768 |
It works with this quirk |
Sill not working for me... no sensors and quirk isn't applied... I am missing something about how to add quirks |
Hello @Srjosep |
That's what I did... |
Could you post your device signature ? |
Sure, this is what I get on log: "manufacturer": "_TZE204_81yrt3lo", |
And the endpoint ? |
This... "endpoints": { |
OK |
Is ts0601_din_power.py ? Mine looks like: MODELS_INFO: [ Maybe I've got the wrong file |
this file is used by ZHA so you cannot used it into the custom quirk
and
replace the first 5 lines by from zigpy.profiles import zha, zgp |
Working now, but only summation delivered. This is the quirk that is loaded fine from zhaquirks import Bus, LocalDataCluster import logging TUYA_TOTAL_ENERGY_ATTR = 0x0201 #total energy /100 0x0211 class TuyaManufClusterDinPower(TuyaManufClusterAttributes):
class TuyaPowerMeasurement(LocalDataCluster, ElectricalMeasurement):
class TuyaElectricalMeasurement(LocalDataCluster, Metering):
class TuyaPowerMeter(TuyaSwitch):
class TuyaPowerMeter_GPP(TuyaSwitch):
|
Don't use my quirk file because it isn't for your device. Copy the code below into your file (replace the code) """Tuya Din Power Meter.""" from zhaquirks import Bus, LocalDataCluster TUYA_TOTAL_ENERGY_ATTR = 0x0211 SWITCH_EVENT = "switch_event" """Hiking Power Meter Attributes""" class TuyaManufClusterDinPower(TuyaManufClusterAttributes):
class TuyaPowerMeasurement(LocalDataCluster, ElectricalMeasurement):
class TuyaElectricalMeasurement(LocalDataCluster, Metering):
class HikingManufClusterDinPower(TuyaManufClusterAttributes):
class TuyaPowerMeter(TuyaSwitch):
class HikingPowerMeter(TuyaSwitch):
|
Is this solved now? We should ideally keep issues open until the issue is fixed in zha-quirks/HA (without using custom quirks). |
No it isn't solve : I reopen this issue. |
Hi, I also acquired this device. Tried all above suggestions to modify existing TS0601 quirks but cannot get it to work. "manufacturer": "_TZE204_rhblgy0z", So, I did setup Rpi with ZIgbee2MQTT and voila, it works there. Not the ideal long term solution. This is the Zigbee2MQTT page https://www.zigbee2mqtt.io/devices/TS0601_din_3.html that works with the device. Will try to debug a little bit more. I found a lot of errors when no Quirk is applied [0x130A:1:0xef00] Unknown cluster command 2 b'\x00\x08\x04\x00\x00\x08\x01\x05\x01\x05\x00\x00\x00\x00' |
I found a partial solution, I have now implemeted the version #2553 (comment) with modification in class TuyaPowerMeter_GPP(TuyaSwitch): However, although this seems to fix the errors, it show the returned total energy in stead off the consumed energy. TUYA_TOTAL_ENERGY_ATTR = 0x0201 is pointing to returned energy. I have tried all kind of values, but can't find the missing Energy Consumed or Energy Total. |
Does anyone have a working quirk file for 'TS0601 _TZE204_81yrt3lo' (for ZHA)? |
See beelow, I put a working quirk file for 'TS0601 _TZE204_81yrt3lo' (for ZHA). When you add your device, sometimes it isn't working for the first time. I hope that's help you |
|
I don't want to complain but things were easier if people formatted their postings a bit better; this is python and damaging the indentation is making it quite useless. |
I bought an energy meter on Amazon having the following ManufacturerName: "_TZE204_rhblgy0z ". I installed one of the ZHA quirks above and initially got readings for Voltage, Current and Power. The device also transmits the consumed and received power (kWh) in a packet with attributeId 0x201. However, the conversion was incorrect. The first 4 bytes (0.148Kwh) contains the consumed energy, the next 4 bytes are unknown values (perhaps PF and freq?). The last 4 bytes (presumably) contains the generated energy (0 Kwh in my case).
I managed to fix this by overriding the 'handle_cluster_request' method which will now return the whole payload for these messages. Then I was able to parse the data in the '_update_attribute' method. This is probably not the right way. I did try to understand the 'ztypes' used in the 'attributes' dictionary. But i was unable to build a custom 'ztype' method or class that was able to parse the correct bytes from these payloads. The device also has a built-in switch. HA receives a message when I manually control the switch on the device itself. But the same problem occurs (reading wrong bytes). Below are some payload examples when controlling the relay: Switch OFF
Switch ON:
The first byte contains the state of the switch . I've no idea what the other bytes represent in this payload. The quirk below works for the majority. Readouts for PF and frequency are still missing and toggling the relay switch in HA does not work (yet). """Tuya Din Power Meter."""
from zigpy.profiles import zha, zgp
import zigpy.types as t
from typing import Any, Optional, Union
from zigpy.zcl import BaseAttributeDefs, foundation
from zigpy.zcl.clusters.general import Basic, Groups, Ota, Scenes, Time, GreenPowerProxy
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,
)
import logging
_LOGGER = logging.getLogger(__name__)
TUYA_TOTAL_ENERGY_ATTR = 0x0201 #total energy /100
TUYA_TOTAL_ENERGY_RCV_ATTR = 0x0211 #total energy /100
TUYA_CURRENT_ATTR = 0x0011 #0x0212
TUYA_POWER_ATTR = 0x0006 #0x0213
TUYA_VOLTAGE_ATTR = 0x0004 #0x0214
TUYA_DIN_SWITCH_ATTR = 0x0110 # First byte contains switch state on _TZE204_rhblgy0z.
SWITCH_EVENT = "switch_event"
class TuyaManufClusterDinPower(TuyaManufClusterAttributes):
"""Manufacturer Specific Cluster of the Tuya Power Meter device."""
#attributes = attrId: { id, type, is_manufacturer_specific } ?
# How to extract data payload using these types?
attributes = {
TUYA_DIN_SWITCH_ATTR: ("switch", t.Bool, True),
TUYA_TOTAL_ENERGY_ATTR: ("energy", t.uint64_t, True),
TUYA_POWER_ATTR: ("power", t.uint64_t, True), #t.uint16_t
}
#overriden method to retrieve the payload for consumend power and switch state.
def handle_cluster_request(
self,
hdr: foundation.ZCLHeader,
args: tuple,
*,
dst_addressing: Optional[
Union[t.Addressing.Group, t.Addressing.IEEE, t.Addressing.NWK]
] = None,
) -> None:
"""Handle cluster request."""
if hdr.command_id not in (0x0001, 0x0002):
return super().super().handle_cluster_request(
hdr, args, dst_addressing=dst_addressing
)
# Send default response because the MCU expects it
if not hdr.frame_control.disable_default_response:
self.send_default_rsp(hdr, status=foundation.Status.SUCCESS)
tuya_cmd = args[0].command_id
tuya_data = args[0].data
_LOGGER.warning(
"[0x%04x:%s:0x%04x] Received value %s "
"for attribute 0x%04x (command 0x%04x)",
self.endpoint.device.nwk,
self.endpoint.endpoint_id,
self.cluster_id,
repr(tuya_data[1:]),
tuya_cmd,
hdr.command_id,
)
if tuya_cmd not in self.attributes:
return
# I could not find the right 'type' for TUYA_TOTAL_ENERGY_ATTR & TUYA_POWER_ATTR. Dirty fix: Just pass the payload as byte array.and parse values.
# https://github.com/zigpy/zigpy/blob/dev/zigpy/types/basic.py
ztype = self.attributes[tuya_cmd].type
zvalue = ztype(tuya_data) if tuya_cmd == 0x0006 else tuya_data[1:]
self._update_attribute(tuya_cmd, zvalue)
def _update_attribute(self, attrid, value):
_LOGGER.warning("TUYA_DEBUG_ATTR (0x%04x)" % (attrid))
_LOGGER.warning(value)
if attrid == TUYA_TOTAL_ENERGY_ATTR:
value1 = int.from_bytes(value, byteorder='big', signed=False) >> 64
value2 = int.from_bytes(value, byteorder='big', signed=False) & 0xFFFFFFFF
self.endpoint.smartenergy_metering.energy_reported(value1)
self.endpoint.smartenergy_metering.energy_receive_reported(value2)
super()._update_attribute(TUYA_TOTAL_ENERGY_ATTR, value1)
super()._update_attribute(TUYA_TOTAL_ENERGY_RCV_ATTR, value2)
elif attrid == TUYA_POWER_ATTR:
_LOGGER.warning("TUYA_DEBUG_ATTR (0x%04x) value: %d (0x%x)" % (attrid, value, value))
self.endpoint.electrical_measurement.voltage_reported((value >> 48) & 0xffff)
self.endpoint.electrical_measurement.current_reported((value >> 24) & 0xffffff)
self.endpoint.electrical_measurement.power_reported(value & 0xffffff)
super()._update_attribute(TUYA_VOLTAGE_ATTR, (value >> 48) & 0xffff)
super()._update_attribute(TUYA_CURRENT_ATTR, (value >> 24) & 0xffffff)
super()._update_attribute(TUYA_POWER_ATTR, value & 0xffffff)
elif attrid == TUYA_DIN_SWITCH_ATTR:
_LOGGER.warning("TUYA_DEBUG_ATTR_Switch (0x%04x) value: %d (0x%x)" % (attrid, value[0],value[0]))
self.endpoint.device.switch_bus.listener_event(
SWITCH_EVENT, self.endpoint.endpoint_id, value[0]
)
else:
super()._update_attribute(attrid, value)
_LOGGER.warning("attrid: 0x%04x value: %d (0x%x)" % (attrid, value, 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
AC_VOLTAGE_MULTIPLIER = 0x0600
AC_VOLTAGE_DIVISOR = 0x0601
AC_CURRENT_MULTIPLIER = 0x0602
AC_CURRENT_DIVISOR = 0x0603
_CONSTANT_ATTRIBUTES = {AC_CURRENT_MULTIPLIER: 1, AC_CURRENT_DIVISOR: 1000, AC_VOLTAGE_MULTIPLIER: 1, AC_VOLTAGE_DIVISOR: 10}
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 current_reported(self, value):
"""Ampers reported."""
self._update_attribute(self.CURRENT_ID, value)
class TuyaElectricalMeasurement(LocalDataCluster, Metering):
"""Custom class for total energy measurement."""
cluster_id = Metering.cluster_id
CURRENT_SUMM_DELIVERED_ID = 0x0000
CURRENT_RECEIVED_ID = 0x0001
UNIT_OF_MEASURE_ID = 0x0300
MULTIPLIER_ID = 0x0301
DIVISOR_ID = 0x0302
POWER_WATT_ENUM = 0x0000
"""Setting unit of measurement."""
_CONSTANT_ATTRIBUTES = {UNIT_OF_MEASURE_ID: POWER_WATT_ENUM, DIVISOR_ID: 100}
def energy_reported(self, value):
"""Summation Energy reported."""
self._update_attribute(self.CURRENT_SUMM_DELIVERED_ID, value)
def energy_receive_reported(self, value):
"""Summation Energy Receive reported."""
self._update_attribute(self.CURRENT_RECEIVED_ID, value)
class TuyaPowerMeter(TuyaSwitch):
"""Tuya power meter device."""
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,
],
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
}
}
}
class TuyaPowerMeter_GPP(TuyaSwitch):
"""Tuya power meter device."""
signature = {
# "node_descriptor": "<NodeDescriptor byte1=1 byte2=64 mac_capability_flags=142 manufacturer_code=4417
# maximum_buffer_size=66 maximum_incoming_transfer_size=66 server_mask=10752
# maximum_outgoing_transfer_size=66 descriptor_capability_field=0>",
# device_version=1
# input_clusters=[0x0000, 0x0004, 0x0005, 0xef00]
# output_clusters=[0x000a, 0x0019]
MODELS_INFO: [
("_TZE204_rhblgy0z", "TS0601"),
],
ENDPOINTS: {
# <SimpleDescriptor endpoint=1 profile=260 device_type=51
# device_version=1
# input_clusters=[0, 4, 5, 61184]
# output_clusters=[10, 25]>
#Unknown cluster 0xEF00 - 61184
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,
#TuyaOnOff.cluster_id
],
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
},
242: {
# <SimpleDescriptor endpoint=242 profile=41440 device_type=61
# input_clusters=[]
# output_clusters=[21]
PROFILE_ID: 41440,
DEVICE_TYPE: 97,
INPUT_CLUSTERS: [],
OUTPUT_CLUSTERS: [GreenPowerProxy.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],
},
242: {
# <SimpleDescriptor endpoint=242 profile=41440 device_type=61
# input_clusters=[]
# output_clusters=[21]
PROFILE_ID: 41440,
DEVICE_TYPE: 97,
INPUT_CLUSTERS: [],
OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id],
},
}
}
|
Problem description
Is it possible to add this tuya device to ZHA devices : https://www.amazon.fr/dp/B0C7C71DRS?psc=1&ref=ppx_yo2ov_dt_b_product_details
It is a DIN power.
It seems similar to the tuya din_power quirk
Solution description
I would love if someone could add this device to the official quirk
Screenshots/Video
Screenshots/Video
[Paste/upload your media here]
Device signature
Device signature
Custom quirk
Custom quirk
The text was updated successfully, but these errors were encountered: