Skip to content

Commit f9898ee

Browse files
authored
Add Tuya/Zemismart 3 phase power meter variants (#4057)
1 parent b98b0d5 commit f9898ee

File tree

1 file changed

+196
-1
lines changed

1 file changed

+196
-1
lines changed

zhaquirks/tuya/ts0601_power.py

Lines changed: 196 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
from collections.abc import ByteString
44

5-
from zigpy.quirks.v2 import SensorDeviceClass, SensorStateClass
5+
from zigpy.quirks.v2 import EntityType, SensorDeviceClass, SensorStateClass
66
from zigpy.quirks.v2.homeassistant import (
7+
PERCENTAGE,
78
UnitOfElectricCurrent,
89
UnitOfEnergy,
910
UnitOfPower,
11+
UnitOfTime,
1012
)
1113
import zigpy.types as t
1214
from zigpy.zcl.clusters.general import LevelControl, OnOff
@@ -216,3 +218,196 @@ class Tuya3PhaseElectricalMeasurement(ElectricalMeasurement, TuyaLocalCluster):
216218
.skip_configuration()
217219
.add_to_registry()
218220
)
221+
222+
(
223+
TuyaQuirkBuilder("_TZE200_dikb3dp6", "TS0601")
224+
.applies_to("_TZE204_dikb3dp6", "TS0601")
225+
.applies_to("_TZE284_dikb3dp6", "TS0601")
226+
.tuya_sensor(
227+
dp_id=1,
228+
attribute_name="energy",
229+
type=t.int32s,
230+
divisor=100,
231+
state_class=SensorStateClass.TOTAL_INCREASING,
232+
device_class=SensorDeviceClass.ENERGY,
233+
unit=UnitOfEnergy.KILO_WATT_HOUR,
234+
fallback_name="Total energy",
235+
)
236+
.tuya_sensor(
237+
dp_id=23,
238+
attribute_name="energy_produced",
239+
type=t.uint32_t,
240+
divisor=100,
241+
state_class=SensorStateClass.TOTAL_INCREASING,
242+
device_class=SensorDeviceClass.ENERGY,
243+
unit=UnitOfEnergy.KILO_WATT_HOUR,
244+
translation_key="energy_produced",
245+
fallback_name="Energy produced",
246+
)
247+
.tuya_dp(
248+
dp_id=29,
249+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
250+
attribute_name="total_active_power",
251+
)
252+
.tuya_dp(
253+
dp_id=32,
254+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
255+
attribute_name="ac_frequency",
256+
converter=lambda x: x / 100,
257+
)
258+
.tuya_sensor(
259+
dp_id=50,
260+
attribute_name="power_factor",
261+
type=t.uint8_t,
262+
state_class=SensorStateClass.MEASUREMENT,
263+
device_class=SensorDeviceClass.POWER_FACTOR,
264+
unit=PERCENTAGE,
265+
translation_key="total_power_factor",
266+
fallback_name="Total power factor",
267+
)
268+
.tuya_number(
269+
dp_id=102,
270+
attribute_name="update_frequency",
271+
type=t.uint16_t,
272+
device_class=SensorDeviceClass.DURATION,
273+
unit=UnitOfTime.SECONDS,
274+
min_value=5,
275+
max_value=3600,
276+
step=1,
277+
entity_type=EntityType.CONFIG,
278+
translation_key="update_frequency",
279+
fallback_name="Update frequency",
280+
)
281+
# Phase A
282+
.tuya_dp(
283+
dp_id=103,
284+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
285+
attribute_name="rms_voltage",
286+
)
287+
.tuya_dp(
288+
dp_id=104,
289+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
290+
attribute_name="rms_current",
291+
)
292+
.tuya_dp(
293+
dp_id=105,
294+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
295+
attribute_name="active_power",
296+
)
297+
.tuya_dp(
298+
dp_id=108,
299+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
300+
attribute_name="power_factor",
301+
)
302+
.tuya_sensor(
303+
dp_id=109,
304+
attribute_name="energy_consumed_ph_a",
305+
type=t.uint32_t,
306+
divisor=100,
307+
state_class=SensorStateClass.TOTAL_INCREASING,
308+
device_class=SensorDeviceClass.ENERGY,
309+
unit=UnitOfEnergy.KILO_WATT_HOUR,
310+
translation_key="energy_ph_a",
311+
fallback_name="Energy phase A",
312+
)
313+
.tuya_sensor(
314+
dp_id=110,
315+
attribute_name="energy_produced_ph_a",
316+
type=t.uint32_t,
317+
divisor=100,
318+
state_class=SensorStateClass.TOTAL_INCREASING,
319+
device_class=SensorDeviceClass.ENERGY,
320+
unit=UnitOfEnergy.KILO_WATT_HOUR,
321+
translation_key="energy_produced_ph_a",
322+
fallback_name="Energy produced phase A",
323+
)
324+
# Phase B
325+
.tuya_dp(
326+
dp_id=112,
327+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
328+
attribute_name="rms_voltage_ph_b",
329+
)
330+
.tuya_dp(
331+
dp_id=113,
332+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
333+
attribute_name="rms_current_ph_b",
334+
)
335+
.tuya_dp(
336+
dp_id=114,
337+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
338+
attribute_name="active_power_ph_b",
339+
)
340+
.tuya_dp(
341+
dp_id=117,
342+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
343+
attribute_name="power_factor_ph_b",
344+
)
345+
.tuya_sensor(
346+
dp_id=118,
347+
attribute_name="energy_consumed_ph_b",
348+
type=t.uint32_t,
349+
divisor=100,
350+
state_class=SensorStateClass.TOTAL_INCREASING,
351+
device_class=SensorDeviceClass.ENERGY,
352+
unit=UnitOfEnergy.KILO_WATT_HOUR,
353+
translation_key="energy_ph_b",
354+
fallback_name="Energy phase B",
355+
)
356+
.tuya_sensor(
357+
dp_id=119,
358+
attribute_name="energy_produced_ph_b",
359+
type=t.uint32_t,
360+
divisor=100,
361+
state_class=SensorStateClass.TOTAL_INCREASING,
362+
device_class=SensorDeviceClass.ENERGY,
363+
unit=UnitOfEnergy.KILO_WATT_HOUR,
364+
translation_key="energy_produced_ph_b",
365+
fallback_name="Energy produced phase B",
366+
)
367+
# Phase C
368+
.tuya_dp(
369+
dp_id=121,
370+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
371+
attribute_name="rms_voltage_ph_c",
372+
)
373+
.tuya_dp(
374+
dp_id=122,
375+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
376+
attribute_name="rms_current_ph_c",
377+
)
378+
.tuya_dp(
379+
dp_id=123,
380+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
381+
attribute_name="active_power_ph_c",
382+
)
383+
.tuya_dp(
384+
dp_id=126,
385+
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
386+
attribute_name="power_factor_ph_c",
387+
)
388+
.tuya_sensor(
389+
dp_id=127,
390+
attribute_name="energy_consumed_ph_c",
391+
divisor=100,
392+
type=t.uint32_t,
393+
state_class=SensorStateClass.TOTAL_INCREASING,
394+
device_class=SensorDeviceClass.ENERGY,
395+
unit=UnitOfEnergy.KILO_WATT_HOUR,
396+
translation_key="energy_ph_c",
397+
fallback_name="Energy phase C",
398+
)
399+
.tuya_sensor(
400+
dp_id=128,
401+
attribute_name="energy_produced_ph_c",
402+
type=t.uint32_t,
403+
divisor=100,
404+
state_class=SensorStateClass.TOTAL_INCREASING,
405+
device_class=SensorDeviceClass.ENERGY,
406+
unit=UnitOfEnergy.KILO_WATT_HOUR,
407+
translation_key="energy_produced_ph_c",
408+
fallback_name="Energy produced phase C",
409+
)
410+
.adds(Tuya3PhaseElectricalMeasurement)
411+
.skip_configuration()
412+
.add_to_registry()
413+
)

0 commit comments

Comments
 (0)