Skip to content

Commit 124e7cf

Browse files
authored
Add support for tuya ywcgq category (liquid level) (#150096)
Thanks @joostlek / @frenck
1 parent 260ea9a commit 124e7cf

File tree

9 files changed

+1031
-18
lines changed

9 files changed

+1031
-18
lines changed

homeassistant/components/tuya/const.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class DPCode(StrEnum):
222222
HUMIDITY_OUTDOOR_3 = "humidity_outdoor_3" # Outdoor humidity
223223
HUMIDITY_SET = "humidity_set" # Humidity setting
224224
HUMIDITY_VALUE = "humidity_value" # Humidity
225+
INSTALLATION_HEIGHT = "installation_height"
225226
IPC_WORK_MODE = "ipc_work_mode"
226227
LED_TYPE_1 = "led_type_1"
227228
LED_TYPE_2 = "led_type_2"
@@ -232,12 +233,18 @@ class DPCode(StrEnum):
232233
LEVEL_CURRENT = "level_current"
233234
LIGHT = "light" # Light
234235
LIGHT_MODE = "light_mode"
236+
LIQUID_DEPTH = "liquid_depth"
237+
LIQUID_DEPTH_MAX = "liquid_depth_max"
238+
LIQUID_LEVEL_PERCENT = "liquid_level_percent"
239+
LIQUID_STATE = "liquid_state"
235240
LOCK = "lock" # Lock / Child lock
236241
MASTER_MODE = "master_mode" # alarm mode
237242
MASTER_STATE = "master_state" # alarm state
238243
MACH_OPERATE = "mach_operate"
239244
MANUAL_FEED = "manual_feed"
240245
MATERIAL = "material" # Material
246+
MAX_SET = "max_set"
247+
MINI_SET = "mini_set"
241248
MODE = "mode" # Working mode / Mode
242249
MOODLIGHTING = "moodlighting" # Mood light
243250
MOTION_RECORD = "motion_record"

homeassistant/components/tuya/number.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,32 @@
339339
entity_category=EntityCategory.CONFIG,
340340
),
341341
),
342+
# Tank Level Sensor
343+
# Note: Undocumented
344+
"ywcgq": (
345+
NumberEntityDescription(
346+
key=DPCode.MAX_SET,
347+
translation_key="alarm_maximum",
348+
entity_category=EntityCategory.CONFIG,
349+
),
350+
NumberEntityDescription(
351+
key=DPCode.MINI_SET,
352+
translation_key="alarm_minimum",
353+
entity_category=EntityCategory.CONFIG,
354+
),
355+
NumberEntityDescription(
356+
key=DPCode.INSTALLATION_HEIGHT,
357+
translation_key="installation_height",
358+
device_class=NumberDeviceClass.DISTANCE,
359+
entity_category=EntityCategory.CONFIG,
360+
),
361+
NumberEntityDescription(
362+
key=DPCode.LIQUID_DEPTH_MAX,
363+
translation_key="maximum_liquid_depth",
364+
device_class=NumberDeviceClass.DISTANCE,
365+
entity_category=EntityCategory.CONFIG,
366+
),
367+
),
342368
# Vibration Sensor
343369
# https://developer.tuya.com/en/docs/iot/categoryzd?id=Kaiuz3a5vrzno
344370
"zd": (

homeassistant/components/tuya/sensor.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,25 @@ class TuyaSensorEntityDescription(SensorEntityDescription):
13011301
),
13021302
*BATTERY_SENSORS,
13031303
),
1304+
# Tank Level Sensor
1305+
# Note: Undocumented
1306+
"ywcgq": (
1307+
TuyaSensorEntityDescription(
1308+
key=DPCode.LIQUID_STATE,
1309+
translation_key="liquid_state",
1310+
),
1311+
TuyaSensorEntityDescription(
1312+
key=DPCode.LIQUID_DEPTH,
1313+
translation_key="depth",
1314+
device_class=SensorDeviceClass.DISTANCE,
1315+
state_class=SensorStateClass.MEASUREMENT,
1316+
),
1317+
TuyaSensorEntityDescription(
1318+
key=DPCode.LIQUID_LEVEL_PERCENT,
1319+
translation_key="liquid_level",
1320+
state_class=SensorStateClass.MEASUREMENT,
1321+
),
1322+
),
13041323
# Vibration Sensor
13051324
# https://developer.tuya.com/en/docs/iot/categoryzd?id=Kaiuz3a5vrzno
13061325
"zd": BATTERY_SENSORS,

homeassistant/components/tuya/strings.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,18 @@
213213
},
214214
"siren_duration": {
215215
"name": "Siren duration"
216+
},
217+
"alarm_maximum": {
218+
"name": "Alarm maximum"
219+
},
220+
"alarm_minimum": {
221+
"name": "Alarm minimum"
222+
},
223+
"installation_height": {
224+
"name": "Installation height"
225+
},
226+
"maximum_liquid_depth": {
227+
"name": "Maximum liquid depth"
216228
}
217229
},
218230
"select": {
@@ -711,6 +723,20 @@
711723
"charging": "[%key:common::state::charging%]",
712724
"charge_done": "Charge done"
713725
}
726+
},
727+
"liquid_state": {
728+
"name": "Liquid state",
729+
"state": {
730+
"normal": "[%key:common::state::normal%]",
731+
"lower_alarm": "[%key:common::state::low%]",
732+
"upper_alarm": "[%key:common::state::high%]"
733+
}
734+
},
735+
"liquid_depth": {
736+
"name": "Liquid depth"
737+
},
738+
"liquid_level": {
739+
"name": "Liquid level"
714740
}
715741
},
716742
"switch": {

tests/components/tuya/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,15 @@
434434
Platform.BINARY_SENSOR,
435435
Platform.SENSOR,
436436
],
437+
"ywcgq_h8lvyoahr6s6aybf": [
438+
# https://github.com/home-assistant/core/issues/145932
439+
Platform.NUMBER,
440+
Platform.SENSOR,
441+
],
437442
"ywcgq_wtzwyhkev3b4ubns": [
438-
# https://community.home-assistant.io/t/something-is-wrong-with-tuya-tank-level-sensors-with-the-new-official-integration/689321
439-
# not (yet) supported
443+
# https://github.com/home-assistant/core/issues/103818
444+
Platform.NUMBER,
445+
Platform.SENSOR,
440446
],
441447
"zndb_ze8faryrxr0glqnn": [
442448
# https://github.com/home-assistant/core/issues/138372
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"endpoint": "https://apigw.tuyaeu.com",
3+
"terminal_id": "REDACTED",
4+
"mqtt_connected": true,
5+
"disabled_by": null,
6+
"disabled_polling": false,
7+
"id": "bf3d16d38b17d7034ddxd4",
8+
"name": "Rainwater Tank Level",
9+
"category": "ywcgq",
10+
"product_id": "h8lvyoahr6s6aybf",
11+
"product_name": "Tank A Level",
12+
"online": true,
13+
"sub": false,
14+
"time_zone": "+01:00",
15+
"active_time": "2025-05-31T09:55:19+00:00",
16+
"create_time": "2025-05-31T09:55:19+00:00",
17+
"update_time": "2025-05-31T09:55:19+00:00",
18+
"function": {
19+
"max_set": {
20+
"type": "Integer",
21+
"value": {
22+
"unit": "%",
23+
"min": 0,
24+
"max": 100,
25+
"scale": 0,
26+
"step": 1
27+
}
28+
},
29+
"mini_set": {
30+
"type": "Integer",
31+
"value": {
32+
"unit": "%",
33+
"min": 0,
34+
"max": 100,
35+
"scale": 0,
36+
"step": 1
37+
}
38+
},
39+
"upper_switch": {
40+
"type": "Boolean",
41+
"value": {}
42+
},
43+
"installation_height": {
44+
"type": "Integer",
45+
"value": {
46+
"unit": "m",
47+
"min": 100,
48+
"max": 3000,
49+
"scale": 3,
50+
"step": 1
51+
}
52+
},
53+
"liquid_depth_max": {
54+
"type": "Integer",
55+
"value": {
56+
"unit": "m",
57+
"min": 100,
58+
"max": 2700,
59+
"scale": 3,
60+
"step": 1
61+
}
62+
}
63+
},
64+
"status_range": {
65+
"liquid_state": {
66+
"type": "Enum",
67+
"value": {
68+
"range": ["normal", "lower_alarm", "upper_alarm"]
69+
}
70+
},
71+
"liquid_depth": {
72+
"type": "Integer",
73+
"value": {
74+
"unit": "m",
75+
"min": 0,
76+
"max": 10000,
77+
"scale": 3,
78+
"step": 1
79+
}
80+
},
81+
"max_set": {
82+
"type": "Integer",
83+
"value": {
84+
"unit": "%",
85+
"min": 0,
86+
"max": 100,
87+
"scale": 0,
88+
"step": 1
89+
}
90+
},
91+
"mini_set": {
92+
"type": "Integer",
93+
"value": {
94+
"unit": "%",
95+
"min": 0,
96+
"max": 100,
97+
"scale": 0,
98+
"step": 1
99+
}
100+
},
101+
"upper_switch": {
102+
"type": "Boolean",
103+
"value": {}
104+
},
105+
"installation_height": {
106+
"type": "Integer",
107+
"value": {
108+
"unit": "m",
109+
"min": 100,
110+
"max": 3000,
111+
"scale": 3,
112+
"step": 1
113+
}
114+
},
115+
"liquid_depth_max": {
116+
"type": "Integer",
117+
"value": {
118+
"unit": "m",
119+
"min": 100,
120+
"max": 2700,
121+
"scale": 3,
122+
"step": 1
123+
}
124+
},
125+
"liquid_level_percent": {
126+
"type": "Integer",
127+
"value": {
128+
"unit": "%",
129+
"min": 0,
130+
"max": 100,
131+
"scale": 0,
132+
"step": 1
133+
}
134+
}
135+
},
136+
"status": {
137+
"liquid_state": "normal",
138+
"liquid_depth": 455,
139+
"max_set": 90,
140+
"mini_set": 10,
141+
"upper_switch": false,
142+
"installation_height": 1350,
143+
"liquid_depth_max": 100,
144+
"liquid_level_percent": 36
145+
},
146+
"set_up": false,
147+
"support_local": true
148+
}

tests/components/tuya/fixtures/ywcgq_wtzwyhkev3b4ubns.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
{
2-
"endpoint": "https://apigw.tuyaeu.com",
3-
"terminal_id": "REDACTED",
2+
"endpoint": "https://openapi.tuyaus.com",
3+
"auth_type": 0,
4+
"country_code": "1",
5+
"app_type": "tuyaSmart",
46
"mqtt_connected": true,
57
"disabled_by": null,
68
"disabled_polling": false,
7-
"id": "bf27a4********368f4w",
8-
"name": "Nivel del tanque A",
9+
"name": "House Water Level",
10+
"model": "EPT_Ultrasonic level sensor",
911
"category": "ywcgq",
1012
"product_id": "wtzwyhkev3b4ubns",
1113
"product_name": "Tank A Level",
1214
"online": true,
1315
"sub": false,
14-
"time_zone": "+01:00",
15-
"active_time": "2024-01-05T10:22:24+00:00",
16-
"create_time": "2024-01-05T10:22:24+00:00",
17-
"update_time": "2024-01-05T10:22:24+00:00",
16+
"time_zone": "-06:00",
17+
"active_time": "2023-11-02T22:48:03+00:00",
18+
"create_time": "2023-11-02T22:48:03+00:00",
19+
"update_time": "2023-11-09T13:32:38+00:00",
1820
"function": {
1921
"max_set": {
2022
"type": "Integer",
@@ -126,14 +128,13 @@
126128
}
127129
},
128130
"status": {
129-
"liquid_state": "normal",
130-
"liquid_depth": 77,
131+
"liquid_state": "upper_alarm",
132+
"liquid_depth": 42,
131133
"max_set": 100,
132-
"mini_set": 10,
133-
"installation_height": 980,
134-
"liquid_depth_max": 140,
135-
"liquid_level_percent": 97
134+
"mini_set": 0,
135+
"installation_height": 560,
136+
"liquid_depth_max": 100,
137+
"liquid_level_percent": 100
136138
},
137-
"set_up": false,
138-
"support_local": true
139+
"terminal_id": "REDACTED"
139140
}

0 commit comments

Comments
 (0)