Skip to content
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

Add TS0601 3 phase meter #3571

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions zhaquirks/tuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,15 @@ def handle_get_data(self, command: TuyaCommand) -> foundation.Status:
dp_error = True
# return foundation.Status.UNSUPPORTED_ATTRIBUTE

_LOGGER.debug(
"[0x%04x:%s:0x%04x] Received value %s " "for attribute 0x%04x",
self.endpoint.device.nwk,
self.endpoint.endpoint_id,
self.cluster_id,
record.data.payload,
record.dp,
)

return (
foundation.Status.SUCCESS
if not dp_error
Expand Down
202 changes: 201 additions & 1 deletion zhaquirks/tuya/ts0601_din_power.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Tuya Din Power Meter."""

from zigpy.profiles import zha
from zigpy.quirks.v2 import SensorDeviceClass, SensorStateClass
from zigpy.quirks.v2.homeassistant import UnitOfEnergy
import zigpy.types as t
from zigpy.zcl.clusters.general import Basic, Groups, Ota, Scenes, Time
from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement
Expand All @@ -15,7 +17,13 @@
OUTPUT_CLUSTERS,
PROFILE_ID,
)
from zhaquirks.tuya import TuyaManufClusterAttributes, TuyaOnOff, TuyaSwitch
from zhaquirks.tuya import (
TuyaLocalCluster,
TuyaManufClusterAttributes,
TuyaOnOff,
TuyaSwitch,
)
from zhaquirks.tuya.builder import TuyaQuirkBuilder

TUYA_TOTAL_ENERGY_ATTR = 0x0211
TUYA_CURRENT_ATTR = 0x0212
Expand Down Expand Up @@ -233,6 +241,198 @@ def __init__(self, *args, **kwargs):
}


class Tuya3PhaseElectricalMeasurement(ElectricalMeasurement, TuyaLocalCluster):
"""Tuya Electrical Measurement cluster."""

_CONSTANT_ATTRIBUTES = {
ElectricalMeasurement.AttributeDefs.ac_current_divisor.id: 1000,
ElectricalMeasurement.AttributeDefs.ac_voltage_divisor.id: 10,
ElectricalMeasurement.AttributeDefs.ac_frequency_divisor.id: 100,
}


(
TuyaQuirkBuilder("_TZE204_ugekduaj", "TS0601")
.tuya_dp(
dp_id=0x65,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="ac_frequency",
)
# Energy consumed
.tuya_sensor(
dp_id=0x01,
attribute_name="energy_consumed",
type=t.uint32_t,
divisor=100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="total_energy",
fallback_name="Total energy",
)
.tuya_sensor(
dp_id=0x70,
attribute_name="energy_consumed_ph_a",
type=t.uint32_t,
divisor=100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy",
fallback_name="Energy",
)
.tuya_sensor(
dp_id=0x72,
attribute_name="energy_consumed_ph_b",
type=t.uint32_t,
divisor=100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy_2",
fallback_name="Energy 2",
)
.tuya_sensor(
dp_id=0x74,
attribute_name="energy_consumed_ph_c",
divisor=100,
type=t.uint32_t,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy_3",
fallback_name="Energy 3",
)
# Energy produced
.tuya_sensor(
dp_id=0x02,
attribute_name="energy_produced",
type=t.uint32_t,
divisor=100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="total_energy_produced",
fallback_name="Total energy produced",
)
.tuya_sensor(
dp_id=0x71,
attribute_name="energy_produced_ph_a",
type=t.uint32_t,
converter=lambda x: x / 100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy_produced",
fallback_name="Energy produced",
)
.tuya_sensor(
dp_id=0x73,
attribute_name="energy_produced_ph_b",
type=t.uint32_t,
divisor=100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy_produced_2",
fallback_name="Energy produced 2",
)
.tuya_sensor(
dp_id=0x75,
attribute_name="energy_produced_ph_c",
type=t.uint32_t,
divisor=100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy_produced_3",
fallback_name="Energy produced 3",
)
# Power
.tuya_dp(
dp_id=0x6F,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="total_active_power",
)
.tuya_dp(
dp_id=0x68,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="active_power",
)
.tuya_dp(
dp_id=0x6B,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="active_power_ph_b",
)
.tuya_dp(
dp_id=0x6E,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="active_power_ph_c",
)
# Voltage
.tuya_dp(
dp_id=0x66,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="rms_voltage",
)
.tuya_dp(
dp_id=0x69,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="rms_voltage_ph_b",
)
.tuya_dp(
dp_id=0x6C,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="rms_voltage_ph_c",
)
# Current
.tuya_dp(
dp_id=0x67,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="rms_current",
)
.tuya_dp(
dp_id=0x6A,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="rms_current_ph_b",
)
.tuya_dp(
dp_id=0x6D,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="rms_current_ph_c",
)
# Power factor
.tuya_sensor(
dp_id=0x0F,
attribute_name="power_factor",
type=t.uint8_t,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER_FACTOR,
# unit=PERCENTAGE, # ZHA fails to validate this one
translation_key="total_power_factor",
fallback_name="Total power factor",
)
.tuya_dp(
dp_id=0x76,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="power_factor",
)
.tuya_dp(
dp_id=0x77,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="power_factor_ph_b",
)
.tuya_dp(
dp_id=0x78,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="power_factor_ph_c",
)
.adds(Tuya3PhaseElectricalMeasurement)
.skip_configuration()
.add_to_registry()
)


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

Expand Down