Skip to content

Commit 031b127

Browse files
zzysszzyepenet
andauthored
Add sensors for Tuya energy storage systems (xnyjcn) (#149237)
Co-authored-by: epenet <[email protected]>
1 parent df0cfd6 commit 031b127

File tree

4 files changed

+727
-0
lines changed

4 files changed

+727
-0
lines changed

homeassistant/components/tuya/const.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class DPCode(StrEnum):
124124
BASIC_WDR = "basic_wdr"
125125
BATTERY = "battery" # Used by non-standard contact sensor implementations
126126
BATTERY_PERCENTAGE = "battery_percentage" # Battery percentage
127+
BATTERY_POWER = "battery_power"
127128
BATTERY_STATE = "battery_state" # Battery state
128129
BATTERY_VALUE = "battery_value" # Battery value
129130
BRIGHT_CONTROLLER = "bright_controller"
@@ -184,11 +185,17 @@ class DPCode(StrEnum):
184185
COUNTDOWN_LEFT = "countdown_left"
185186
COUNTDOWN_SET = "countdown_set" # Countdown setting
186187
CRY_DETECTION_SWITCH = "cry_detection_switch"
188+
CUML_E_EXPORT_OFFGRID1 = "cuml_e_export_offgrid1"
189+
CUMULATIVE_ENERGY_CHARGED = "cumulative_energy_charged"
190+
CUMULATIVE_ENERGY_DISCHARGED = "cumulative_energy_discharged"
191+
CUMULATIVE_ENERGY_GENERATED_PV = "cumulative_energy_generated_pv"
192+
CUMULATIVE_ENERGY_OUTPUT_INV = "cumulative_energy_output_inv"
187193
CUP_NUMBER = "cup_number" # NUmber of cups
188194
CUR_CURRENT = "cur_current" # Actual current
189195
CUR_NEUTRAL = "cur_neutral" # Total reverse energy
190196
CUR_POWER = "cur_power" # Actual power
191197
CUR_VOLTAGE = "cur_voltage" # Actual voltage
198+
CURRENT_SOC = "current_soc"
192199
DECIBEL_SENSITIVITY = "decibel_sensitivity"
193200
DECIBEL_SWITCH = "decibel_switch"
194201
DEHUMIDITY_SET_ENUM = "dehumidify_set_enum"
@@ -240,6 +247,7 @@ class DPCode(StrEnum):
240247
HUMIDITY_SET = "humidity_set" # Humidity setting
241248
HUMIDITY_VALUE = "humidity_value" # Humidity
242249
INSTALLATION_HEIGHT = "installation_height"
250+
INVERTER_OUTPUT_POWER = "inverter_output_power"
243251
IPC_WORK_MODE = "ipc_work_mode"
244252
LED_TYPE_1 = "led_type_1"
245253
LED_TYPE_2 = "led_type_2"
@@ -305,6 +313,9 @@ class DPCode(StrEnum):
305313
PUMP = "pump"
306314
PUMP_RESET = "pump_reset" # Water pump reset
307315
PUMP_TIME = "pump_time" # Water pump duration
316+
PV_POWER_CHANNEL_1 = "pv_power_channel_1"
317+
PV_POWER_CHANNEL_2 = "pv_power_channel_2"
318+
PV_POWER_TOTAL = "pv_power_total"
308319
RAIN_24H = "rain_24h" # Total daily rainfall in mm
309320
RAIN_RATE = "rain_rate" # Rain intensity in mm/h
310321
RECORD_MODE = "record_mode"

homeassistant/components/tuya/sensor.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,79 @@ class TuyaSensorEntityDescription(SensorEntityDescription):
14131413
# Wireless Switch
14141414
# https://developer.tuya.com/en/docs/iot/s?id=Kbeoa9fkv6brp
14151415
"wxkg": BATTERY_SENSORS, # Pressure Sensor
1416+
# Micro Storage Inverter
1417+
# Energy storage and solar PV inverter system with monitoring capabilities
1418+
"xnyjcn": (
1419+
TuyaSensorEntityDescription(
1420+
key=DPCode.CURRENT_SOC,
1421+
translation_key="battery_soc",
1422+
device_class=SensorDeviceClass.BATTERY,
1423+
state_class=SensorStateClass.MEASUREMENT,
1424+
entity_category=EntityCategory.DIAGNOSTIC,
1425+
),
1426+
TuyaSensorEntityDescription(
1427+
key=DPCode.PV_POWER_TOTAL,
1428+
translation_key="total_pv_power",
1429+
device_class=SensorDeviceClass.POWER,
1430+
state_class=SensorStateClass.MEASUREMENT,
1431+
),
1432+
TuyaSensorEntityDescription(
1433+
key=DPCode.PV_POWER_CHANNEL_1,
1434+
translation_key="pv_channel_power",
1435+
translation_placeholders={"index": "1"},
1436+
device_class=SensorDeviceClass.POWER,
1437+
state_class=SensorStateClass.MEASUREMENT,
1438+
),
1439+
TuyaSensorEntityDescription(
1440+
key=DPCode.PV_POWER_CHANNEL_2,
1441+
translation_key="pv_channel_power",
1442+
translation_placeholders={"index": "2"},
1443+
device_class=SensorDeviceClass.POWER,
1444+
state_class=SensorStateClass.MEASUREMENT,
1445+
),
1446+
TuyaSensorEntityDescription(
1447+
key=DPCode.BATTERY_POWER,
1448+
translation_key="battery_power",
1449+
device_class=SensorDeviceClass.POWER,
1450+
state_class=SensorStateClass.MEASUREMENT,
1451+
),
1452+
TuyaSensorEntityDescription(
1453+
key=DPCode.INVERTER_OUTPUT_POWER,
1454+
translation_key="inverter_output_power",
1455+
device_class=SensorDeviceClass.POWER,
1456+
state_class=SensorStateClass.MEASUREMENT,
1457+
),
1458+
TuyaSensorEntityDescription(
1459+
key=DPCode.CUMULATIVE_ENERGY_GENERATED_PV,
1460+
translation_key="lifetime_pv_energy",
1461+
device_class=SensorDeviceClass.ENERGY,
1462+
state_class=SensorStateClass.TOTAL_INCREASING,
1463+
),
1464+
TuyaSensorEntityDescription(
1465+
key=DPCode.CUMULATIVE_ENERGY_OUTPUT_INV,
1466+
translation_key="lifetime_inverter_output_energy",
1467+
device_class=SensorDeviceClass.ENERGY,
1468+
state_class=SensorStateClass.TOTAL_INCREASING,
1469+
),
1470+
TuyaSensorEntityDescription(
1471+
key=DPCode.CUMULATIVE_ENERGY_DISCHARGED,
1472+
translation_key="lifetime_battery_discharge_energy",
1473+
device_class=SensorDeviceClass.ENERGY,
1474+
state_class=SensorStateClass.TOTAL_INCREASING,
1475+
),
1476+
TuyaSensorEntityDescription(
1477+
key=DPCode.CUMULATIVE_ENERGY_CHARGED,
1478+
translation_key="lifetime_battery_charge_energy",
1479+
device_class=SensorDeviceClass.ENERGY,
1480+
state_class=SensorStateClass.TOTAL_INCREASING,
1481+
),
1482+
TuyaSensorEntityDescription(
1483+
key=DPCode.CUML_E_EXPORT_OFFGRID1,
1484+
translation_key="lifetime_offgrid_port_energy",
1485+
device_class=SensorDeviceClass.ENERGY,
1486+
state_class=SensorStateClass.TOTAL_INCREASING,
1487+
),
1488+
),
14161489
# https://developer.tuya.com/en/docs/iot/categoryylcg?id=Kaiuz3kc2e4gm
14171490
"ylcg": (
14181491
TuyaSensorEntityDescription(

homeassistant/components/tuya/strings.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,36 @@
621621
"battery_state": {
622622
"name": "Battery state"
623623
},
624+
"battery_soc": {
625+
"name": "Battery SOC"
626+
},
627+
"battery_power": {
628+
"name": "Battery power"
629+
},
630+
"total_pv_power": {
631+
"name": "Total PV power"
632+
},
633+
"pv_channel_power": {
634+
"name": "PV channel {index} power"
635+
},
636+
"inverter_output_power": {
637+
"name": "Inverter output power"
638+
},
639+
"lifetime_pv_energy": {
640+
"name": "Lifetime PV energy"
641+
},
642+
"lifetime_inverter_output_energy": {
643+
"name": "Lifetime inverter output energy"
644+
},
645+
"lifetime_battery_discharge_energy": {
646+
"name": "Lifetime battery discharge energy"
647+
},
648+
"lifetime_battery_charge_energy": {
649+
"name": "Lifetime battery charge energy"
650+
},
651+
"lifetime_offgrid_port_energy": {
652+
"name": "Lifetime off-grid port energy"
653+
},
624654
"gas": {
625655
"name": "Gas"
626656
},

0 commit comments

Comments
 (0)