From 32a5f2e008853d318508e6a9f1ada36db3e6cbfb Mon Sep 17 00:00:00 2001 From: David Rapan Date: Mon, 15 Jul 2024 19:27:56 +0200 Subject: [PATCH] refactor: Pseudo enums reworked as true enums - In the context of the HA refactor: Naming: Load UPS entities prefix from UPS fix: Extended Power losses to include all inputs fix: 'deye_string' inverter profile file formatting --- custom_components/solarman/api.py | 2 +- custom_components/solarman/const.py | 2 +- .../inverter_definitions/deye_hybrid.yaml | 101 +++-- .../inverter_definitions/deye_sg01hp3.yaml | 170 +++++--- .../inverter_definitions/deye_sg04lp3.yaml | 168 +++++--- .../inverter_definitions/deye_string.yaml | 392 +++++++++--------- .../deye_sun-12k-sg04lp3.yaml | 168 +++++--- custom_components/solarman/parser.py | 10 +- custom_components/solarman/sensor.py | 4 + 9 files changed, 578 insertions(+), 439 deletions(-) diff --git a/custom_components/solarman/api.py b/custom_components/solarman/api.py index 5846e8d..43cba78 100644 --- a/custom_components/solarman/api.py +++ b/custom_components/solarman/api.py @@ -163,7 +163,7 @@ async def async_get(self, runtime = 0): requests_count = len(requests) result = 0 - _LOGGER.debug(f"Scheduling {requests_count} query requests. #{runtime}") + _LOGGER.debug(f"Scheduling {requests_count} query requests. #{runtime}") try: for request in requests: diff --git a/custom_components/solarman/const.py b/custom_components/solarman/const.py index 927c3f4..e8e44ba 100644 --- a/custom_components/solarman/const.py +++ b/custom_components/solarman/const.py @@ -43,7 +43,7 @@ TIMINGS_COORDINATOR_TIMEOUT = TIMINGS_INTERVAL * 6 TIMINGS_SOCKET_TIMEOUT = TIMINGS_INTERVAL * 3 - 1 TIMINGS_QUERY_INTERVAL_DEFAULT = 60 -TIMINGS_QUERY_EXCEPT_SLEEP = 4 +TIMINGS_QUERY_EXCEPT_SLEEP = 2 REGISTERS_MIN_SPAN_DEFAULT = 25 REGISTERS_DIGITS_DEFAULT = 6 diff --git a/custom_components/solarman/inverter_definitions/deye_hybrid.yaml b/custom_components/solarman/inverter_definitions/deye_hybrid.yaml index 684251b..c949743 100644 --- a/custom_components/solarman/inverter_definitions/deye_hybrid.yaml +++ b/custom_components/solarman/inverter_definitions/deye_hybrid.yaml @@ -14,7 +14,7 @@ requests: mb_functioncode: 0x03 parameters: - - group: solar + - group: PV items: - name: "PV1 Power" class: "power" @@ -23,7 +23,7 @@ parameters: scale: 1 rule: 1 registers: [0x00BA] - icon: "mdi:solar-power" + icon: "mdi:solar-power-variant" - name: "PV2 Power" class: "power" @@ -32,7 +32,7 @@ parameters: scale: 1 rule: 1 registers: [0x00BB] - icon: "mdi:solar-power" + icon: "mdi:solar-power-variant" - name: "PV1 Voltage" class: "voltage" @@ -41,7 +41,7 @@ parameters: scale: 0.1 rule: 1 registers: [0x006D] - icon: "mdi:solar-power" + icon: "mdi:solar-power-variant" - name: "PV2 Voltage" class: "voltage" @@ -50,7 +50,7 @@ parameters: scale: 0.1 rule: 1 registers: [0x006F] - icon: "mdi:solar-power" + icon: "mdi:solar-power-variant" - name: "PV1 Current" class: "current" @@ -58,7 +58,7 @@ parameters: scale: 0.1 rule: 1 registers: [0x006E] - icon: "mdi:solar-power" + icon: "mdi:solar-power-variant" - name: "PV2 Current" class: "current" @@ -67,7 +67,7 @@ parameters: scale: 0.1 rule: 1 registers: [0x0070] - icon: "mdi:solar-power" + icon: "mdi:solar-power-variant" - name: "Daily Production" class: "energy" @@ -135,13 +135,13 @@ parameters: icon: "mdi:battery-minus" - name: "Battery Status" - class: "" - state_class: "measurement" + class: "enum" + state_class: "" uom: "" scale: 1 rule: 1 registers: [0x00BD] - isstr: true + options: ["Charge", "Stand-by", "Discharge"] lookup: - key: 0 value: "Charge" @@ -158,7 +158,6 @@ parameters: scale: 1 rule: 2 registers: [0x00BE] - icon: "mdi:battery" - name: "Battery Voltage" class: "voltage" @@ -167,7 +166,6 @@ parameters: scale: 0.01 rule: 1 registers: [0x00B7] - icon: "mdi:battery" - name: "Battery SOC" class: "battery" @@ -176,7 +174,6 @@ parameters: scale: 1 rule: 1 registers: [0x00B8] - icon: "mdi:battery" - name: "Battery Current" class: "current" @@ -185,7 +182,6 @@ parameters: scale: 0.01 rule: 2 registers: [0x00BF] - icon: "mdi:battery" - name: "Battery Temperature" class: "temperature" @@ -195,7 +191,6 @@ parameters: rule: 1 offset: 1000 registers: [0x00B6] - icon: "mdi:battery" - group: Grid items: @@ -224,7 +219,8 @@ parameters: scale: 0.01 rule: 1 registers: [0x00A0] - icon: "mdi:current-ac" + icon: "mdi:transmission-tower" + - name: "Grid Voltage L2" class: "voltage" state_class: "measurement" @@ -241,7 +237,7 @@ parameters: scale: 0.01 rule: 1 registers: [0x00A1] - icon: "mdi:current-ac" + icon: "mdi:transmission-tower" - name: "Internal CT L1 Power" class: "power" @@ -333,7 +329,6 @@ parameters: scale: 1 rule: 1 registers: [0x00B2] - icon: "mdi:lightning-bolt-outline" - name: "Load L1 Power" class: "power" @@ -342,7 +337,6 @@ parameters: scale: 1 rule: 1 registers: [0x00B0] - icon: "mdi:lightning-bolt-outline" - name: "Load L2 Power" class: "power" @@ -351,7 +345,6 @@ parameters: scale: 1 rule: 1 registers: [0x00B1] - icon: "mdi:lightning-bolt-outline" - name: "Load Voltage" class: "voltage" @@ -360,7 +353,6 @@ parameters: scale: 0.1 rule: 1 registers: [0x009D] - icon: "mdi:lightning-bolt-outline" - name: "Daily Load Consumption" class: "energy" @@ -369,7 +361,6 @@ parameters: scale: 0.1 rule: 1 registers: [0x0054] - icon: "mdi:lightning-bolt-outline" - name: "Total Load Consumption" class: "energy" @@ -378,43 +369,47 @@ parameters: scale: 0.1 rule: 3 registers: [0x0055, 0x0056] - icon: "mdi:lightning-bolt-outline" - name: "SmartLoad Enable Status" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x00C3] - isstr: true + options: ["OFF", "ON"] lookup: - key: 0 value: "OFF" - key: 1 value: "ON" - icon: "mdi:lightning-bolt-outline" + icon: "mdi:lightning-bolt-circle" - group: Inverter items: - name: "Running Status" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x003B] - isstr: true + range: + min: 0 + max: 5 + options: ["Standby", "Self-test", "Normal", "Alarm", "Fault"] lookup: - - key: 0 - value: "Stand-by" - - key: 1 - value: "Self-checking" - - key: 2 + - key: 0x0000 + value: "Standby" + - key: 0x0001 + value: "Self-test" + - key: 0x0002 value: "Normal" - - key: 3 - value: "FAULT" - icon: "mdi:home-lightning-bolt" + - key: 0x0003 + value: "Alarm" + - key: 0x0004 + value: "Fault" + icon: "mdi:information" - name: "Total Power" class: "power" @@ -423,7 +418,6 @@ parameters: scale: 1 rule: 2 registers: [0x00AF] - icon: "mdi:home-lightning-bolt" - name: "Grid Frequency" class: "frequency" @@ -432,7 +426,6 @@ parameters: scale: 0.01 rule: 1 registers: [0x004F] - icon: "mdi:sine-wave" - name: "Current L1" class: "current" @@ -441,7 +434,6 @@ parameters: scale: 0.01 rule: 2 registers: [0x00A4] - icon: "mdi:home-lightning-bolt" - name: "Current L2" class: "current" @@ -449,7 +441,6 @@ parameters: scale: 0.01 rule: 2 registers: [0x00A5] - icon: "mdi:home-lightning-bolt" - name: "Inverter L1 Power" class: "power" @@ -458,7 +449,6 @@ parameters: scale: 1 rule: 2 registers: [0x00AD] - icon: "mdi:home-lightning-bolt" - name: "Inverter L2 Power" class: "power" @@ -467,7 +457,6 @@ parameters: scale: 1 rule: 2 registers: [0x00AE] - icon: "mdi:home-lightning-bolt" - name: "Load Frequency" class: "" @@ -476,7 +465,6 @@ parameters: scale: 0.01 rule: 1 registers: [0x00C0] - icon: "mdi:sine-wave" - name: "DC Temperature" class: "temperature" @@ -486,7 +474,6 @@ parameters: rule: 2 offset: 1000 registers: [0x005A] - icon: "mdi:thermometer" - name: "AC Temperature" class: "temperature" @@ -496,7 +483,6 @@ parameters: rule: 2 offset: 1000 registers: [0x005B] - icon: "mdi:thermometer" - name: "Inverter ID" class: "" @@ -526,13 +512,13 @@ parameters: isstr: true - name: "Grid-connected Status" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x00C2] - isstr: true + options: ["Off-Grid", "On-Grid"] lookup: - key: 0 value: "Off-Grid" @@ -540,13 +526,13 @@ parameters: value: "On-Grid" - name: "Gen-connected Status" - class: "" - uom: "" + class: "enum" state_class: "" + uom: "" scale: 1 rule: 1 registers: [0x00A6] - isstr: true + options: ["none", "On"] lookup: - key: 0 value: "none" @@ -562,13 +548,20 @@ parameters: registers: [0x00A6] - name: "Work Mode" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 3 registers: [0x00F4, 0x00F7] - isstr: true + options: + [ + "Selling First", + "Zero-Export to Load&Solar Sell", + "Zero-Export to Home&Solar Sell", + "Zero-Export to Load", + "Zero-Export to Home", + ] lookup: - key: 0 value: "Selling First" @@ -817,7 +810,7 @@ parameters: icon: "mdi:checkbox-marked-outline" - name: "Time of use" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 @@ -825,7 +818,7 @@ parameters: mask: 1 registers: [0x00F8] icon: "mdi:checkbox-marked-outline" - isstr: true + options: ["Disable", "Enable"] lookup: - key: 0 value: "Disable" diff --git a/custom_components/solarman/inverter_definitions/deye_sg01hp3.yaml b/custom_components/solarman/inverter_definitions/deye_sg01hp3.yaml index c25d069..2739fdf 100644 --- a/custom_components/solarman/inverter_definitions/deye_sg01hp3.yaml +++ b/custom_components/solarman/inverter_definitions/deye_sg01hp3.yaml @@ -12,14 +12,23 @@ parameters: # Device - Type of the Device - name: "Device" update_interval: 300 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0000] icon: "mdi:information" - isstr: true + options: + [ + "String Inverter", + "Single-Phase Hybrid Inverter", + "Microinverter", + "LV 3-Phase Hybrid Inverter", + "HV 3-Phase Hybrid Inverter", + "HV 3-Phase Inverter 6-15kw", + "HV 3-Phase Inverter 20-50kw" + ] lookup: - key: 0x0200 value: "String Inverter" @@ -58,14 +67,14 @@ parameters: - name: "Device Protocol Version" attribute: update_interval: 300 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0002] icon: "mdi:information" - isstr: true + options: ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5"] lookup: - key: 0x0100 value: "1.0" @@ -108,14 +117,14 @@ parameters: items: - name: "Battery Control Mode" attribute: - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0062] icon: "mdi:battery" - isstr: true + options: ["Lead-Battery, four-stage charging method", "Lithium"] lookup: - key: 0x0000 value: "Lead-Battery, four-stage charging method" @@ -275,14 +284,14 @@ parameters: - name: "Battery Grid Charging" attribute: - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0082] icon: "mdi:battery" - isstr: true + options: ["Disabled", "Enabled"] lookup: - key: 0x0000 value: "Disabled" @@ -290,14 +299,14 @@ parameters: value: "Enabled" - name: "SmartLoad Mode" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0085] icon: "mdi:lightning-bolt-circle" - isstr: true + options: ["Generator", "Output", "Microinverter"] lookup: - key: 0x0000 value: "Generator" @@ -331,14 +340,14 @@ parameters: max: 100 - name: "SmartLoad State" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0228] icon: "mdi:lightning-bolt-circle" - isstr: true + options: ["Off", "On"] lookup: - key: 0x0001 value: "Off" @@ -354,6 +363,8 @@ parameters: value: "Off" - key: 0x000D value: "On" + - key: "default" + value: "On" - group: BMS items: @@ -456,20 +467,21 @@ parameters: icon: "mdi:battery" - name: "BMS Alarm" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x00DC] icon: "mdi:battery-alert" - isstr: true - lookup_default: "Active" + options: ["Inactive", "Active"] lookup: - key: 0 value: "Inactive" - key: 1 value: "Active" + - key: "default" + value: "Active" - name: "BMS Fault Location" class: "" @@ -499,14 +511,27 @@ parameters: - name: "BMS Type" attribute: - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x00DF] icon: "mdi:battery" - isstr: true + options: + [ + "PYLON", + "Tianbangda", + "KOK", + "Keith", + "Toppai", + "Peneng 485", + "Jeris 485", + "Sunwoda 485", + "Xinrui 485", + "Tianbangda 485", + "Shenggao Electric CAN", + ] lookup: - key: 0x0000 value: "PYLON" @@ -515,7 +540,7 @@ parameters: - key: 0x0002 value: "KOK" - key: 0x0003 - value: "keith" + value: "Keith" - key: 0x0004 value: "Toppai" - key: 0x0005 @@ -536,7 +561,7 @@ parameters: # Device - Operating (Running) status - name: "Device Status" update_interval: 30 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 @@ -546,7 +571,7 @@ parameters: range: min: 0 max: 5 - isstr: true + options: ["Standby", "Self-test", "Normal", "Alarm", "Fault"] lookup: - key: 0x0000 value: "Standby" @@ -767,14 +792,14 @@ parameters: # Device - Power on/off status - name: "Device Power Status" update_interval: 30 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0227] icon: "mdi:information" - isstr: true + options: ["Off", "On"] lookup: - key: 0x0000 value: "Off" @@ -784,15 +809,24 @@ parameters: # Device - AC Relay status - name: "Device Relay Status" update_interval: 30 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0228] icon: "mdi:information" - isstr: true - lookup_default: "Power Supply" + options: + [ + "Inverter", + "Grid", + "Inverter-Grid", + "Generator", + "Inverter-Gen", + "Grid-Generator", + "Inv-Grid-Gen", + "Power Supply" + ] lookup: - key: 0x0001 value: "Inverter" @@ -808,17 +842,20 @@ parameters: value: "Grid-Generator" - key: 0x000D value: "Inv-Grid-Gen" + - key: "default" + value: "Power Supply" # Device - AC Grid state - name: "Device State" - class: "" + update_interval: 30 + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0228] icon: "mdi:information" - isstr: true + options: ["Off-grid", "On-grid"] lookup: - key: 0x0001 value: "Off-grid" @@ -838,15 +875,22 @@ parameters: # Device - Alarm message (word 1 & 2) [0, 65535] - name: "Device Alert" update_interval: 30 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 3 registers: [0x0229, 0x022A] icon: "mdi:alert-circle" - isstr: true - lookup_default: "Error" + options: + [ + "Ok", + "Fan failure", + "Grid error", + "Battery loss", + "Parallel communication quality", + "Error" + ] lookup: - key: 0x0000 value: "Ok" @@ -858,6 +902,8 @@ parameters: value: "Battery loss" - key: 0x8000 value: "Parallel communication quality" + - key: "default" + value: "Error" # Device - Fault message (word 1, 2, 3 & 4) [0, 65535] - name: "Device Fault" @@ -1312,14 +1358,14 @@ parameters: rule: 4 registers: [0x027C, 0x02B6] - # Inverter - Includes consumption of the device itself aswell power losses of AC/DC conversions + # Inverter - Includes consumption of the inverter device itself as well AC/DC conversion losses - name: "Power losses" class: "power" state_class: "measurement" uom: "W" rule: 1 digits: 0 - registers: [0x024E, 0x02A0, 0x02A1, 0x027C, 0x02B6] + registers: [0x024E, 0x02A0, 0x02A1, 0x02A2, 0x02A3, 0x027C, 0x02B6] sensors: - signed: scale: 10 @@ -1328,6 +1374,10 @@ parameters: registers: [0x02A0] - scale: 10 registers: [0x02A1] + - scale: 10 + registers: [0x02A2] + - scale: 10 + registers: [0x02A3] - subtract: signed: registers: [0x027C, 0x02B6] @@ -1342,10 +1392,10 @@ parameters: rule: 1 registers: [0x027E] - - group: Upload + - group: UPS items: - # UPS output - The power of phase A is U16bit (low 16 bits) + U16bit (high 16 bits) - - name: "UPS L1 Power" + # Load UPS output - The power of phase A is U16bit (low 16 bits) + U16bit (high 16 bits) + - name: "Load UPS L1 Power" realtime: class: "power" state_class: "measurement" @@ -1355,8 +1405,8 @@ parameters: registers: [0x0280, 0x02B8] icon: "mdi:home-lightning-bolt" - # UPS output - The power of phase B is U16bit (low 16 bits) + U16bit (high 16 bits) - - name: "UPS L2 Power" + # Load UPS output - The power of phase B is U16bit (low 16 bits) + U16bit (high 16 bits) + - name: "Load UPS L2 Power" realtime: class: "power" state_class: "measurement" @@ -1366,8 +1416,8 @@ parameters: registers: [0x0281, 0x02B9] icon: "mdi:home-lightning-bolt" - # UPS output - The power of phase C is U16bit (low 16 bits) + U16bit (high 16 bits) - - name: "UPS L3 Power" + # Load UPS output - The power of phase C is U16bit (low 16 bits) + U16bit (high 16 bits) + - name: "Load UPS L3 Power" realtime: class: "power" state_class: "measurement" @@ -1377,8 +1427,8 @@ parameters: registers: [0x0282, 0x02BA] icon: "mdi:home-lightning-bolt" - # UPS output - The power is U16bit (low 16 bits) + U16bit (high 16 bits) - - name: "UPS Power" + # Load UPS output - The power is U16bit (low 16 bits) + U16bit (high 16 bits) + - name: "Load UPS Power" realtime: class: "power" state_class: "measurement" @@ -1388,6 +1438,8 @@ parameters: registers: [0x0283, 0x02BB] icon: "mdi:home-lightning-bolt" + - group: Load + items: # Load output - The voltage of phase A - name: "Load L1 Voltage" class: "voltage" @@ -1422,7 +1474,7 @@ parameters: state_class: "measurement" uom: "W" scale: 1 - rule: 2 + rule: 4 registers: [0x028A, 0x0290] # Load - The power of phase A is S16bit (low 16 bits) + S16bit (high 16 bits) @@ -1432,7 +1484,7 @@ parameters: state_class: "measurement" uom: "W" scale: 1 - rule: 2 + rule: 4 registers: [0x028B, 0x0291] # Load - The power of phase A is S16bit (low 16 bits) + S16bit (high 16 bits) @@ -1442,7 +1494,7 @@ parameters: state_class: "measurement" uom: "W" scale: 1 - rule: 2 + rule: 4 registers: [0x028C, 0x0292] # Load - The Power is S16bit (low 16 bits) + S16bit (high 16 bits) @@ -1452,7 +1504,7 @@ parameters: state_class: "measurement" uom: "W" scale: 1 - rule: 2 + rule: 4 registers: [0x028D, 0x0293] - group: SmartLoad/Generator @@ -1524,9 +1576,9 @@ parameters: rule: 2 registers: [0x029B, 0x029F] - - group: Photovoltaic + - group: PV items: - # Photovoltaic - The combined power of Input 1 & 2 & 3 & 4 (L:1W, H:10W) + # PV - The combined power of Input 1 & 2 & 3 & 4 (L:1W, H:10W) - name: "PV Power" realtime: class: "power" @@ -1546,7 +1598,7 @@ parameters: registers: [0x02A3] icon: "mdi:solar-power-variant" - # Photovoltaic - The power of Input 1 (L:1W, H:10W) + # PV - The power of Input 1 (L:1W, H:10W) - name: "PV1 Power" realtime: class: "power" @@ -1557,7 +1609,7 @@ parameters: registers: [0x02A0] icon: "mdi:solar-power-variant" - # Photovoltaic - The power of Input 2 (L:1W, H:10W) + # PV - The power of Input 2 (L:1W, H:10W) - name: "PV2 Power" realtime: class: "power" @@ -1568,7 +1620,7 @@ parameters: registers: [0x02A1] icon: "mdi:solar-power-variant" - # Photovoltaic - The power of Input 3 (L:1W, H:10W) + # PV - The power of Input 3 (L:1W, H:10W) - name: "PV3 Power" disabled: realtime: @@ -1580,7 +1632,7 @@ parameters: registers: [0x02A2] icon: "mdi:solar-power-variant" - # Photovoltaic - The power of Input 4 (L:1W, H:10W) + # PV - The power of Input 4 (L:1W, H:10W) - name: "PV4 Power" disabled: realtime: @@ -1592,7 +1644,7 @@ parameters: registers: [0x02A3] icon: "mdi:solar-power-variant" - # Photovoltaic - The voltage of Input 1 + # PV - The voltage of Input 1 - name: "PV1 Voltage" realtime: class: "voltage" @@ -1606,7 +1658,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The current of Input 1 + # PV - The current of Input 1 - name: "PV1 Current" realtime: class: "current" @@ -1620,7 +1672,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The voltage of Input 2 + # PV - The voltage of Input 2 - name: "PV2 Voltage" realtime: class: "voltage" @@ -1634,7 +1686,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The current of Input 2 + # PV - The current of Input 2 - name: "PV2 Current" realtime: class: "current" @@ -1648,7 +1700,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The voltage of Input 3 + # PV - The voltage of Input 3 - name: "PV3 Voltage" disabled: realtime: @@ -1663,7 +1715,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The current of Input 3 + # PV - The current of Input 3 - name: "PV3 Current" disabled: realtime: @@ -1678,7 +1730,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The voltage of Input 4 + # PV - The voltage of Input 4 - name: "PV4 Voltage" disabled: realtime: @@ -1693,7 +1745,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The current of Input 4 + # PV - The current of Input 4 - name: "PV4 Current" disabled: realtime: diff --git a/custom_components/solarman/inverter_definitions/deye_sg04lp3.yaml b/custom_components/solarman/inverter_definitions/deye_sg04lp3.yaml index 9a65866..97c8ce2 100644 --- a/custom_components/solarman/inverter_definitions/deye_sg04lp3.yaml +++ b/custom_components/solarman/inverter_definitions/deye_sg04lp3.yaml @@ -18,14 +18,23 @@ parameters: # Device - Type of the Device - name: "Device" update_interval: 300 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0000] icon: "mdi:information" - isstr: true + options: + [ + "String Inverter", + "Single-Phase Hybrid Inverter", + "Microinverter", + "LV 3-Phase Hybrid Inverter", + "HV 3-Phase Hybrid Inverter", + "HV 3-Phase Inverter 6-15kw", + "HV 3-Phase Inverter 20-50kw" + ] lookup: - key: 0x0200 value: "String Inverter" @@ -64,14 +73,14 @@ parameters: - name: "Device Protocol Version" attribute: update_interval: 300 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0002] icon: "mdi:information" - isstr: true + options: ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5"] lookup: - key: 0x0100 value: "1.0" @@ -114,14 +123,14 @@ parameters: items: - name: "Battery Control Mode" attribute: - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0062] icon: "mdi:battery" - isstr: true + options: ["Lead-Battery, four-stage charging method", "Lithium"] lookup: - key: 0x0000 value: "Lead-Battery, four-stage charging method" @@ -280,14 +289,14 @@ parameters: - name: "Battery Grid Charging" attribute: - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0082] icon: "mdi:battery" - isstr: true + options: ["Disabled", "Enabled"] lookup: - key: 0x0000 value: "Disabled" @@ -295,14 +304,14 @@ parameters: value: "Enabled" - name: "SmartLoad Mode" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0085] icon: "mdi:lightning-bolt-circle" - isstr: true + options: ["Generator", "Output", "Microinverter"] lookup: - key: 0x0000 value: "Generator" @@ -336,14 +345,14 @@ parameters: max: 100 - name: "SmartLoad State" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0228] icon: "mdi:lightning-bolt-circle" - isstr: true + options: ["Off", "On"] lookup: - key: 0x0001 value: "Off" @@ -359,6 +368,8 @@ parameters: value: "Off" - key: 0x000D value: "On" + - key: "default" + value: "On" - group: BMS items: @@ -461,20 +472,21 @@ parameters: icon: "mdi:battery" - name: "BMS Alarm" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x00DC] icon: "mdi:battery-alert" - isstr: true - lookup_default: "Active" + options: ["Inactive", "Active"] lookup: - key: 0 value: "Inactive" - key: 1 value: "Active" + - key: "default" + value: "Active" - name: "BMS Fault Location" class: "" @@ -504,14 +516,27 @@ parameters: - name: "BMS Type" attribute: - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x00DF] icon: "mdi:battery" - isstr: true + options: + [ + "PYLON", + "Tianbangda", + "KOK", + "Keith", + "Toppai", + "Peneng 485", + "Jeris 485", + "Sunwoda 485", + "Xinrui 485", + "Tianbangda 485", + "Shenggao Electric CAN", + ] lookup: - key: 0x0000 value: "PYLON" @@ -520,7 +545,7 @@ parameters: - key: 0x0002 value: "KOK" - key: 0x0003 - value: "keith" + value: "Keith" - key: 0x0004 value: "Toppai" - key: 0x0005 @@ -541,7 +566,7 @@ parameters: # Device - Operating (Running) status - name: "Device Status" update_interval: 30 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 @@ -551,7 +576,7 @@ parameters: range: min: 0 max: 5 - isstr: true + options: ["Standby", "Self-test", "Normal", "Alarm", "Fault"] lookup: - key: 0x0000 value: "Standby" @@ -766,14 +791,14 @@ parameters: # Device - Power on/off status - name: "Device Power Status" update_interval: 30 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0227] icon: "mdi:information" - isstr: true + options: ["Off", "On"] lookup: - key: 0x0000 value: "Off" @@ -783,15 +808,24 @@ parameters: # Device - AC Relay status - name: "Device Relay Status" update_interval: 30 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0228] icon: "mdi:information" - isstr: true - lookup_default: "Power Supply" + options: + [ + "Inverter", + "Grid", + "Inverter-Grid", + "Generator", + "Inverter-Gen", + "Grid-Generator", + "Inv-Grid-Gen", + "Power Supply" + ] lookup: - key: 0x0001 value: "Inverter" @@ -807,17 +841,20 @@ parameters: value: "Grid-Generator" - key: 0x000D value: "Inv-Grid-Gen" + - key: "default" + value: "Power Supply" # Device - AC Grid state - name: "Device State" - class: "" + update_interval: 30 + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0228] icon: "mdi:information" - isstr: true + options: ["Off-grid", "On-grid"] lookup: - key: 0x0001 value: "Off-grid" @@ -837,15 +874,22 @@ parameters: # Device - Alarm message (word 1 & 2) [0, 65535] - name: "Device Alert" update_interval: 30 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 3 registers: [0x0229, 0x022A] icon: "mdi:alert-circle" - isstr: true - lookup_default: "Error" + options: + [ + "Ok", + "Fan failure", + "Grid error", + "Battery loss", + "Parallel communication quality", + "Error" + ] lookup: - key: 0x0000 value: "Ok" @@ -857,6 +901,8 @@ parameters: value: "Battery loss" - key: 0x8000 value: "Parallel communication quality" + - key: "default" + value: "Error" # Device - Fault message (word 1, 2, 3 & 4) [0, 65535] - name: "Device Fault" @@ -1284,19 +1330,21 @@ parameters: rule: 4 registers: [0x027C, 0x02B6] - # Inverter - Includes consumption of the device itself aswell power losses of AC/DC conversions + # Inverter - Includes consumption of the inverter device itself as well AC/DC conversion losses - name: "Power losses" class: "power" state_class: "measurement" uom: "W" rule: 1 digits: 0 - registers: [0x024E, 0x02A0, 0x02A1, 0x027C, 0x02B6] + registers: [0x024E, 0x02A0, 0x02A1, 0x02A2, 0x02A3, 0x027C, 0x02B6] sensors: - signed: registers: [0x024E] - registers: [0x02A0] - registers: [0x02A1] + - registers: [0x02A2] + - registers: [0x02A3] - subtract: signed: registers: [0x027C, 0x02B6] @@ -1311,10 +1359,10 @@ parameters: rule: 1 registers: [0x027E] - - group: Upload + - group: UPS items: - # UPS output - The power of phase A is U16bit (low 16 bits) + U16bit (high 16 bits) - - name: "UPS L1 Power" + # Load UPS output - The power of phase A is U16bit (low 16 bits) + U16bit (high 16 bits) + - name: "Load UPS L1 Power" realtime: class: "power" state_class: "measurement" @@ -1324,8 +1372,8 @@ parameters: registers: [0x0280, 0x02B8] icon: "mdi:home-lightning-bolt" - # UPS output - The power of phase B is U16bit (low 16 bits) + U16bit (high 16 bits) - - name: "UPS L2 Power" + # Load UPS output - The power of phase B is U16bit (low 16 bits) + U16bit (high 16 bits) + - name: "Load UPS L2 Power" realtime: class: "power" state_class: "measurement" @@ -1335,8 +1383,8 @@ parameters: registers: [0x0281, 0x02B9] icon: "mdi:home-lightning-bolt" - # UPS output - The power of phase C is U16bit (low 16 bits) + U16bit (high 16 bits) - - name: "UPS L3 Power" + # Load UPS output - The power of phase C is U16bit (low 16 bits) + U16bit (high 16 bits) + - name: "Load UPS L3 Power" realtime: class: "power" state_class: "measurement" @@ -1346,8 +1394,8 @@ parameters: registers: [0x0282, 0x02BA] icon: "mdi:home-lightning-bolt" - # UPS output - The power is U16bit (low 16 bits) + U16bit (high 16 bits) - - name: "UPS Power" + # Load UPS output - The power is U16bit (low 16 bits) + U16bit (high 16 bits) + - name: "Load UPS Power" realtime: class: "power" state_class: "measurement" @@ -1357,6 +1405,8 @@ parameters: registers: [0x0283, 0x02BB] icon: "mdi:home-lightning-bolt" + - group: Load + items: # Load output - The voltage of phase A - name: "Load L1 Voltage" class: "voltage" @@ -1391,7 +1441,7 @@ parameters: state_class: "measurement" uom: "W" scale: 1 - rule: 2 + rule: 4 registers: [0x028A, 0x0290] # Load - The power of phase A is S16bit (low 16 bits) + S16bit (high 16 bits) @@ -1401,7 +1451,7 @@ parameters: state_class: "measurement" uom: "W" scale: 1 - rule: 2 + rule: 4 registers: [0x028B, 0x0291] # Load - The power of phase A is S16bit (low 16 bits) + S16bit (high 16 bits) @@ -1411,7 +1461,7 @@ parameters: state_class: "measurement" uom: "W" scale: 1 - rule: 2 + rule: 4 registers: [0x028C, 0x0292] # Load - The Power is S16bit (low 16 bits) + S16bit (high 16 bits) @@ -1421,7 +1471,7 @@ parameters: state_class: "measurement" uom: "W" scale: 1 - rule: 2 + rule: 4 registers: [0x028D, 0x0293] - group: SmartLoad/Generator @@ -1493,9 +1543,9 @@ parameters: rule: 2 registers: [0x029B, 0x029F] - - group: Photovoltaic + - group: PV items: - # Photovoltaic - The combined power of Input 1 & 2 & 3 & 4 (L:1W, H:10W) + # PV - The combined power of Input 1 & 2 & 3 & 4 (L:1W, H:10W) - name: "PV Power" realtime: class: "power" @@ -1511,7 +1561,7 @@ parameters: - registers: [0x02A3] icon: "mdi:solar-power-variant" - # Photovoltaic - The power of Input 1 (L:1W, H:10W) + # PV - The power of Input 1 (L:1W, H:10W) - name: "PV1 Power" realtime: class: "power" @@ -1522,7 +1572,7 @@ parameters: registers: [0x02A0] icon: "mdi:solar-power-variant" - # Photovoltaic - The power of Input 2 (L:1W, H:10W) + # PV - The power of Input 2 (L:1W, H:10W) - name: "PV2 Power" realtime: class: "power" @@ -1533,7 +1583,7 @@ parameters: registers: [0x02A1] icon: "mdi:solar-power-variant" - # Photovoltaic - The power of Input 3 (L:1W, H:10W) + # PV - The power of Input 3 (L:1W, H:10W) - name: "PV3 Power" disabled: realtime: @@ -1545,7 +1595,7 @@ parameters: registers: [0x02A2] icon: "mdi:solar-power-variant" - # Photovoltaic - The power of Input 4 (L:1W, H:10W) + # PV - The power of Input 4 (L:1W, H:10W) - name: "PV4 Power" disabled: realtime: @@ -1557,7 +1607,7 @@ parameters: registers: [0x02A3] icon: "mdi:solar-power-variant" - # Photovoltaic - The voltage of Input 1 + # PV - The voltage of Input 1 - name: "PV1 Voltage" realtime: class: "voltage" @@ -1571,7 +1621,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The current of Input 1 + # PV - The current of Input 1 - name: "PV1 Current" realtime: class: "current" @@ -1585,7 +1635,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The voltage of Input 2 + # PV - The voltage of Input 2 - name: "PV2 Voltage" realtime: class: "voltage" @@ -1599,7 +1649,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The current of Input 2 + # PV - The current of Input 2 - name: "PV2 Current" realtime: class: "current" @@ -1613,7 +1663,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The voltage of Input 3 + # PV - The voltage of Input 3 - name: "PV3 Voltage" disabled: realtime: @@ -1628,7 +1678,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The current of Input 3 + # PV - The current of Input 3 - name: "PV3 Current" disabled: realtime: @@ -1643,7 +1693,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The voltage of Input 4 + # PV - The voltage of Input 4 - name: "PV4 Voltage" disabled: realtime: @@ -1658,7 +1708,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The current of Input 4 + # PV - The current of Input 4 - name: "PV4 Current" disabled: realtime: diff --git a/custom_components/solarman/inverter_definitions/deye_string.yaml b/custom_components/solarman/inverter_definitions/deye_string.yaml index 566d94f..64b78cc 100644 --- a/custom_components/solarman/inverter_definitions/deye_string.yaml +++ b/custom_components/solarman/inverter_definitions/deye_string.yaml @@ -1,206 +1,196 @@ - requests: - start: 0x0003 - end: 0x0070 + end: 0x0070 mb_functioncode: 0x03 parameters: - - group: solar - items: - - name: "PV1 Voltage" - class: "voltage" - state_class: "measurement" - uom: "V" - scale: 0.1 - rule: 1 - registers: [0x006D] - icon: 'mdi:solar-power' - - - name: "PV2 Voltage" - class: "voltage" - state_class: "measurement" - uom: "V" - scale: 0.1 - rule: 1 - registers: [0x006F] - icon: 'mdi:solar-power' - - - name: "PV1 Current" - class: "current" - uom: "A" - scale: 0.1 - rule: 1 - registers: [0x006E] - icon: 'mdi:solar-power' - - - name: "PV2 Current" - class: "current" - state_class: "measurement" - uom: "A" - scale: 0.1 - rule: 1 - registers: [0x0070] - icon: 'mdi:solar-power' - - - name: "Daily Production" - class: "energy" - state_class: "total" - uom: "kWh" - scale: 0.1 - rule: 1 - registers: [0x003C] - icon: 'mdi:solar-power' - - - name: "Total Production" - class: "energy" - state_class: "total_increasing" - uom: "kWh" - scale: 0.1 - rule: 3 - registers: [0x003F,0x0040] - icon: 'mdi:solar-power' - validation: - min: 0.1 - invalidate_all: - - - - - group: Grid - items: - - name: "Grid Voltage L-L(A)" - class: "voltage" - state_class: "measurement" - uom: "V" - scale: 0.1 - rule: 1 - registers: [0x0049] - icon: 'mdi:transmission-tower' - - - name: "Grid Voltage L-L(B))" - class: "voltage" - state_class: "measurement" - uom: "V" - scale: 0.1 - rule: 1 - registers: [0x004A] - icon: 'mdi:transmission-tower' - - - name: "Grid Voltage L-L(C)" - class: "voltage" - state_class: "measurement" - uom: "V" - scale: 0.1 - rule: 1 - registers: [0x004B] - icon: 'mdi:transmission-tower' - - - name: "Grid Current A" - class: "current" - state_class: "measurement" - uom: "A" - scale: 0.1 - rule: 2 - registers: [0x004C] - icon: 'mdi:home-lightning-bolt' - - - name: "Grid Current B" - class: "current" - state_class: "measurement" - uom: "A" - scale: 0.1 - rule: 2 - registers: [0x004D] - icon: 'mdi:home-lightning-bolt' - - - name: "Grid Current C" - class: "current" - state_class: "measurement" - uom: "A" - scale: 0.1 - rule: 2 - registers: [0x004E] - icon: 'mdi:home-lightning-bolt' - - - name: "Grid Frequency" - class: "frequency" - state_class: "measurement" - uom: "Hz" - scale: 0.01 - rule: 1 - registers: [0x004F] - icon: 'mdi:home-lightning-bolt' - - - group: Inverter - items: - - name: "Running Status" - class: "" - state_class: "" - uom: "" - scale: 1 - rule: 1 - registers: [0x003B] - isstr: true - lookup: - - key: 0 - value: "Stand-by" - - key: 1 - value: "Self-checking" - - key: 2 - value: "Normal" - - key: 3 - value: "FAULT" - icon: 'mdi:home-lightning-bolt' - - - name: "Total Output AC Power" - class: "power" - state_class: "measurement" - uom: "W" - scale: 0.1 - rule: 3 - registers: [0x0050,0x0051] - icon: 'mdi:home-lightning-bolt' - - - name: "Input Active Power" - class: "power" - state_class: "measurement" - uom: "W" - scale: 0.1 - rule: 3 - registers: [0x0052, 0x0053] - icon: 'mdi:home-lightning-bolt' - - - name: "Output Apparent Power" - class: "apparent_power" - state_class: "measurement" - uom: "VA" - scale: 0.1 - rule: 3 - registers: [0x0054, 0x0055] - icon: 'mdi:home-lightning-bolt' - - - name: "Output Active Power" - class: "energy" - state_class: "measurement" - uom: "W" - scale: 0.1 - rule: 3 - registers: [0x0056, 0x0057] - icon: 'mdi:home-lightning-bolt' - - - name: "Output Reactive Power" - class: "reactive_power" - state_class: "measurement" - uom: "VAR" - rule: 3 - scale: 0.1 - registers: [0x0058, 0x0059] - icon: 'mdi:home-lightning-bolt' - - - name: "Inverter ID" - class: "" - state_class: "" - uom: "" - scale: 1 - rule: 5 - registers: [0x0003,0x0004,0x0005,0x0006,0x0007] - isstr: true + - group: PV + items: + - name: "PV1 Voltage" + class: "voltage" + state_class: "measurement" + uom: "V" + scale: 0.1 + rule: 1 + registers: [0x006D] + icon: "mdi:solar-power-variant" + + - name: "PV2 Voltage" + class: "voltage" + state_class: "measurement" + uom: "V" + scale: 0.1 + rule: 1 + registers: [0x006F] + icon: "mdi:solar-power-variant" + + - name: "PV1 Current" + class: "current" + uom: "A" + scale: 0.1 + rule: 1 + registers: [0x006E] + icon: "mdi:solar-power-variant" + + - name: "PV2 Current" + class: "current" + state_class: "measurement" + uom: "A" + scale: 0.1 + rule: 1 + registers: [0x0070] + icon: "mdi:solar-power-variant" + + - name: "Daily Production" + class: "energy" + state_class: "total" + uom: "kWh" + scale: 0.1 + rule: 1 + registers: [0x003C] + icon: "mdi:solar-power" + + - name: "Total Production" + class: "energy" + state_class: "total_increasing" + uom: "kWh" + scale: 0.1 + rule: 3 + registers: [0x003F, 0x0040] + icon: "mdi:solar-power" + validation: + min: 0.1 + invalidate_all: + + - group: Grid + items: + - name: "Grid Voltage L-L(A)" + class: "voltage" + state_class: "measurement" + uom: "V" + scale: 0.1 + rule: 1 + registers: [0x0049] + + - name: "Grid Voltage L-L(B))" + class: "voltage" + state_class: "measurement" + uom: "V" + scale: 0.1 + rule: 1 + registers: [0x004A] + + - name: "Grid Voltage L-L(C)" + class: "voltage" + state_class: "measurement" + uom: "V" + scale: 0.1 + rule: 1 + registers: [0x004B] + + - name: "Grid Current A" + class: "current" + state_class: "measurement" + uom: "A" + scale: 0.1 + rule: 2 + registers: [0x004C] + + - name: "Grid Current B" + class: "current" + state_class: "measurement" + uom: "A" + scale: 0.1 + rule: 2 + registers: [0x004D] + + - name: "Grid Current C" + class: "current" + state_class: "measurement" + uom: "A" + scale: 0.1 + rule: 2 + registers: [0x004E] + + - name: "Grid Frequency" + class: "frequency" + state_class: "measurement" + uom: "Hz" + scale: 0.01 + rule: 1 + registers: [0x004F] + + - group: Inverter + items: + - name: "Running Status" + class: "enum" + state_class: "" + uom: "" + scale: 1 + rule: 1 + registers: [0x003B] + icon: "mdi:information" + range: + min: 0 + max: 5 + options: ["Standby", "Self-test", "Normal", "Alarm", "Fault"] + lookup: + - key: 0x0000 + value: "Standby" + - key: 0x0001 + value: "Self-test" + - key: 0x0002 + value: "Normal" + - key: 0x0003 + value: "Alarm" + - key: 0x0004 + value: "Fault" + + - name: "Total Output AC Power" + class: "power" + state_class: "measurement" + uom: "W" + scale: 0.1 + rule: 3 + registers: [0x0050, 0x0051] + + - name: "Input Active Power" + class: "power" + state_class: "measurement" + uom: "W" + scale: 0.1 + rule: 3 + registers: [0x0052, 0x0053] + + - name: "Output Apparent Power" + class: "apparent_power" + state_class: "measurement" + uom: "VA" + scale: 0.1 + rule: 3 + registers: [0x0054, 0x0055] + + - name: "Output Active Power" + class: "energy" + state_class: "measurement" + uom: "W" + scale: 0.1 + rule: 3 + registers: [0x0056, 0x0057] + + - name: "Output Reactive Power" + class: "reactive_power" + state_class: "measurement" + uom: "VAR" + rule: 3 + scale: 0.1 + registers: [0x0058, 0x0059] + + - name: "Inverter ID" + class: "" + state_class: "" + uom: "" + scale: 1 + rule: 5 + registers: [0x0003, 0x0004, 0x0005, 0x0006, 0x0007] + isstr: true diff --git a/custom_components/solarman/inverter_definitions/deye_sun-12k-sg04lp3.yaml b/custom_components/solarman/inverter_definitions/deye_sun-12k-sg04lp3.yaml index 467b31d..52839ec 100644 --- a/custom_components/solarman/inverter_definitions/deye_sun-12k-sg04lp3.yaml +++ b/custom_components/solarman/inverter_definitions/deye_sun-12k-sg04lp3.yaml @@ -20,14 +20,23 @@ parameters: # Device - Type of the Device - name: "Device" update_interval: 300 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0000] icon: "mdi:information" - isstr: true + options: + [ + "String Inverter", + "Single-Phase Hybrid Inverter", + "Microinverter", + "LV 3-Phase Hybrid Inverter", + "HV 3-Phase Hybrid Inverter", + "HV 3-Phase Inverter 6-15kw", + "HV 3-Phase Inverter 20-50kw" + ] lookup: - key: 0x0200 value: "String Inverter" @@ -66,14 +75,14 @@ parameters: - name: "Device Protocol Version" attribute: update_interval: 300 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0002] icon: "mdi:information" - isstr: true + options: ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5"] lookup: - key: 0x0100 value: "1.0" @@ -116,14 +125,14 @@ parameters: items: - name: "Battery Control Mode" attribute: - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0062] icon: "mdi:battery" - isstr: true + options: ["Lead-Battery, four-stage charging method", "Lithium"] lookup: - key: 0x0000 value: "Lead-Battery, four-stage charging method" @@ -283,14 +292,14 @@ parameters: - name: "Battery Grid Charging" attribute: - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0082] icon: "mdi:battery" - isstr: true + options: ["Disabled", "Enabled"] lookup: - key: 0x0000 value: "Disabled" @@ -298,14 +307,14 @@ parameters: value: "Enabled" - name: "SmartLoad Mode" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0085] icon: "mdi:lightning-bolt-circle" - isstr: true + options: ["Generator", "Output", "Microinverter"] lookup: - key: 0x0000 value: "Generator" @@ -339,14 +348,14 @@ parameters: max: 100 - name: "SmartLoad State" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0228] icon: "mdi:lightning-bolt-circle" - isstr: true + options: ["Off", "On"] lookup: - key: 0x0001 value: "Off" @@ -362,6 +371,8 @@ parameters: value: "Off" - key: 0x000D value: "On" + - key: "default" + value: "On" - group: BMS items: @@ -464,20 +475,21 @@ parameters: icon: "mdi:battery" - name: "BMS Alarm" - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x00DC] icon: "mdi:battery-alert" - isstr: true - lookup_default: "Active" + options: ["Inactive", "Active"] lookup: - key: 0 value: "Inactive" - key: 1 value: "Active" + - key: "default" + value: "Active" - name: "BMS Fault Location" class: "" @@ -507,14 +519,27 @@ parameters: - name: "BMS Type" attribute: - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x00DF] icon: "mdi:battery" - isstr: true + options: + [ + "PYLON", + "Tianbangda", + "KOK", + "Keith", + "Toppai", + "Peneng 485", + "Jeris 485", + "Sunwoda 485", + "Xinrui 485", + "Tianbangda 485", + "Shenggao Electric CAN", + ] lookup: - key: 0x0000 value: "PYLON" @@ -523,7 +548,7 @@ parameters: - key: 0x0002 value: "KOK" - key: 0x0003 - value: "keith" + value: "Keith" - key: 0x0004 value: "Toppai" - key: 0x0005 @@ -544,7 +569,7 @@ parameters: # Device - Operating (Running) status - name: "Device Status" update_interval: 30 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 @@ -554,7 +579,7 @@ parameters: range: min: 0 max: 5 - isstr: true + options: ["Standby", "Self-test", "Normal", "Alarm", "Fault"] lookup: - key: 0x0000 value: "Standby" @@ -799,14 +824,14 @@ parameters: # Device - Power on/off status - name: "Device Power Status" update_interval: 30 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0227] icon: "mdi:information" - isstr: true + options: ["Off", "On"] lookup: - key: 0x0000 value: "Off" @@ -816,15 +841,24 @@ parameters: # Device - AC Relay status - name: "Device Relay Status" update_interval: 30 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0228] icon: "mdi:information" - isstr: true - lookup_default: "Power Supply" + options: + [ + "Inverter", + "Grid", + "Inverter-Grid", + "Generator", + "Inverter-Gen", + "Grid-Generator", + "Inv-Grid-Gen", + "Power Supply" + ] lookup: - key: 0x0001 value: "Inverter" @@ -840,17 +874,20 @@ parameters: value: "Grid-Generator" - key: 0x000D value: "Inv-Grid-Gen" + - key: "default" + value: "Power Supply" # Device - AC Grid state - name: "Device State" - class: "" + update_interval: 30 + class: "enum" state_class: "" uom: "" scale: 1 rule: 1 registers: [0x0228] icon: "mdi:information" - isstr: true + options: ["Off-grid", "On-grid"] lookup: - key: 0x0001 value: "Off-grid" @@ -870,15 +907,22 @@ parameters: # Device - Alarm message (word 1 & 2) [0, 65535] - name: "Device Alert" update_interval: 30 - class: "" + class: "enum" state_class: "" uom: "" scale: 1 rule: 3 registers: [0x0229, 0x022A] icon: "mdi:alert-circle" - isstr: true - lookup_default: "Error" + options: + [ + "Ok", + "Fan failure", + "Grid error", + "Battery loss", + "Parallel communication quality", + "Error" + ] lookup: - key: 0x0000 value: "Ok" @@ -890,6 +934,8 @@ parameters: value: "Battery loss" - key: 0x8000 value: "Parallel communication quality" + - key: "default" + value: "Error" # Device - Fault message (word 1, 2, 3 & 4) [0, 65535] - name: "Device Fault" @@ -1347,19 +1393,21 @@ parameters: rule: 4 registers: [0x027C, 0x02B6] - # Inverter - Includes consumption of the device itself aswell power losses of AC/DC conversions + # Inverter - Includes consumption of the inverter device itself as well AC/DC conversion losses - name: "Power losses" class: "power" state_class: "measurement" uom: "W" rule: 1 digits: 0 - registers: [0x024E, 0x02A0, 0x02A1, 0x027C, 0x02B6] + registers: [0x024E, 0x02A0, 0x02A1, 0x02A2, 0x02A3, 0x027C, 0x02B6] sensors: - signed: registers: [0x024E] - registers: [0x02A0] - registers: [0x02A1] + - registers: [0x02A2] + - registers: [0x02A3] - subtract: signed: registers: [0x027C, 0x02B6] @@ -1374,10 +1422,10 @@ parameters: rule: 1 registers: [0x027E] - - group: Upload + - group: UPS items: - # UPS output - The power of phase A is U16bit (low 16 bits) + U16bit (high 16 bits) - - name: "UPS L1 Power" + # Load UPS output - The power of phase A is U16bit (low 16 bits) + U16bit (high 16 bits) + - name: "Load UPS L1 Power" realtime: class: "power" state_class: "measurement" @@ -1387,8 +1435,8 @@ parameters: registers: [0x0280, 0x02B8] icon: "mdi:home-lightning-bolt" - # UPS output - The power of phase B is U16bit (low 16 bits) + U16bit (high 16 bits) - - name: "UPS L2 Power" + # Load UPS output - The power of phase B is U16bit (low 16 bits) + U16bit (high 16 bits) + - name: "Load UPS L2 Power" realtime: class: "power" state_class: "measurement" @@ -1398,8 +1446,8 @@ parameters: registers: [0x0281, 0x02B9] icon: "mdi:home-lightning-bolt" - # UPS output - The power of phase C is U16bit (low 16 bits) + U16bit (high 16 bits) - - name: "UPS L3 Power" + # Load UPS output - The power of phase C is U16bit (low 16 bits) + U16bit (high 16 bits) + - name: "Load UPS L3 Power" realtime: class: "power" state_class: "measurement" @@ -1409,8 +1457,8 @@ parameters: registers: [0x0282, 0x02BA] icon: "mdi:home-lightning-bolt" - # UPS output - The power is U16bit (low 16 bits) + U16bit (high 16 bits) - - name: "UPS Power" + # Load UPS output - The power is U16bit (low 16 bits) + U16bit (high 16 bits) + - name: "Load UPS Power" realtime: class: "power" state_class: "measurement" @@ -1420,6 +1468,8 @@ parameters: registers: [0x0283, 0x02BB] icon: "mdi:home-lightning-bolt" + - group: Load + items: # Load output - The voltage of phase A - name: "Load L1 Voltage" class: "voltage" @@ -1454,7 +1504,7 @@ parameters: state_class: "measurement" uom: "W" scale: 1 - rule: 2 + rule: 4 registers: [0x028A, 0x0290] # Load - The power of phase A is S16bit (low 16 bits) + S16bit (high 16 bits) @@ -1464,7 +1514,7 @@ parameters: state_class: "measurement" uom: "W" scale: 1 - rule: 2 + rule: 4 registers: [0x028B, 0x0291] # Load - The power of phase A is S16bit (low 16 bits) + S16bit (high 16 bits) @@ -1474,7 +1524,7 @@ parameters: state_class: "measurement" uom: "W" scale: 1 - rule: 2 + rule: 4 registers: [0x028C, 0x0292] # Load - The Power is S16bit (low 16 bits) + S16bit (high 16 bits) @@ -1484,7 +1534,7 @@ parameters: state_class: "measurement" uom: "W" scale: 1 - rule: 2 + rule: 4 registers: [0x028D, 0x0293] - group: SmartLoad/Generator @@ -1556,9 +1606,9 @@ parameters: rule: 2 registers: [0x029B, 0x029F] - - group: Photovoltaic + - group: PV items: - # Photovoltaic - The combined power of Input 1 & 2 & 3 & 4 (L:1W, H:10W) + # PV - The combined power of Input 1 & 2 & 3 & 4 (L:1W, H:10W) - name: "PV Power" realtime: class: "power" @@ -1574,7 +1624,7 @@ parameters: - registers: [0x02A3] icon: "mdi:solar-power-variant" - # Photovoltaic - The power of Input 1 (L:1W, H:10W) + # PV - The power of Input 1 (L:1W, H:10W) - name: "PV1 Power" realtime: class: "power" @@ -1585,7 +1635,7 @@ parameters: registers: [0x02A0] icon: "mdi:solar-power-variant" - # Photovoltaic - The power of Input 2 (L:1W, H:10W) + # PV - The power of Input 2 (L:1W, H:10W) - name: "PV2 Power" realtime: class: "power" @@ -1596,7 +1646,7 @@ parameters: registers: [0x02A1] icon: "mdi:solar-power-variant" - # Photovoltaic - The power of Input 3 (L:1W, H:10W) + # PV - The power of Input 3 (L:1W, H:10W) - name: "PV3 Power" disabled: realtime: @@ -1608,7 +1658,7 @@ parameters: registers: [0x02A2] icon: "mdi:solar-power-variant" - # Photovoltaic - The power of Input 4 (L:1W, H:10W) + # PV - The power of Input 4 (L:1W, H:10W) - name: "PV4 Power" disabled: realtime: @@ -1620,7 +1670,7 @@ parameters: registers: [0x02A3] icon: "mdi:solar-power-variant" - # Photovoltaic - The voltage of Input 1 + # PV - The voltage of Input 1 - name: "PV1 Voltage" realtime: class: "voltage" @@ -1634,7 +1684,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The current of Input 1 + # PV - The current of Input 1 - name: "PV1 Current" realtime: class: "current" @@ -1648,7 +1698,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The voltage of Input 2 + # PV - The voltage of Input 2 - name: "PV2 Voltage" realtime: class: "voltage" @@ -1662,7 +1712,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The current of Input 2 + # PV - The current of Input 2 - name: "PV2 Current" realtime: class: "current" @@ -1676,7 +1726,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The voltage of Input 3 + # PV - The voltage of Input 3 - name: "PV3 Voltage" disabled: realtime: @@ -1691,7 +1741,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The current of Input 3 + # PV - The current of Input 3 - name: "PV3 Current" disabled: realtime: @@ -1706,7 +1756,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The voltage of Input 4 + # PV - The voltage of Input 4 - name: "PV4 Voltage" disabled: realtime: @@ -1721,7 +1771,7 @@ parameters: min: 0 max: 65535 - # Photovoltaic - The current of Input 4 + # PV - The current of Input 4 - name: "PV4 Current" disabled: realtime: diff --git a/custom_components/solarman/parser.py b/custom_components/solarman/parser.py index ed3b547..58d26dc 100644 --- a/custom_components/solarman/parser.py +++ b/custom_components/solarman/parser.py @@ -107,12 +107,12 @@ def in_range(self, value, definition): return True - def lookup_value(self, value, definition): - for o in definition["lookup"]: - if (o["key"] == value): + def lookup_value(self, value, keyvaluepairs): + for o in keyvaluepairs: + if o["key"] == value or o["key"] == "default": return o["value"] - return value if not "lookup_default" in definition else f"{definition["lookup_default"]} [{value}]" + return keyvaluepairs[0]["value"] def do_validate(self, key, value, rule): if "min" in rule: @@ -243,7 +243,7 @@ def try_parse_unsigned(self, rawData, definition, start, length): if found: if "lookup" in definition: - self.set_state(key, self.lookup_value(value, definition)) + self.set_state(key, self.lookup_value(value, definition["lookup"])) self._result[key]["value"] = int(value) else: if "validation" in definition: diff --git a/custom_components/solarman/sensor.py b/custom_components/solarman/sensor.py index a2fbf80..6032032 100644 --- a/custom_components/solarman/sensor.py +++ b/custom_components/solarman/sensor.py @@ -215,5 +215,9 @@ def __init__(self, coordinator, sensor, battery_life_cycle_rating): if "unit_of_measurement" in sensor and (unit_of_measurement := sensor["unit_of_measurement"]): self._attr_unit_of_measurement = unit_of_measurement + if "options" in sensor and (options := sensor["options"]): + self._attr_options = options + self._attr_extra_state_attributes = self._attr_extra_state_attributes | { "options": options } + if "name" in sensor and sensor["name"] == "Battery": self._attr_extra_state_attributes = self._attr_extra_state_attributes | { "Life Cycle Rating": battery_life_cycle_rating } \ No newline at end of file