From 2e9982a39a79082fe4629b12f6ee03646a3d5c82 Mon Sep 17 00:00:00 2001 From: TonyMathiesen <95135900+TonyMathiesen@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:07:42 +0200 Subject: [PATCH 1/7] Change splitInBlocks logic in sensor.py --- custom_components/solax_modbus/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/solax_modbus/sensor.py b/custom_components/solax_modbus/sensor.py index 39b5ff17..c2f6971e 100644 --- a/custom_components/solax_modbus/sensor.py +++ b/custom_components/solax_modbus/sensor.py @@ -39,7 +39,7 @@ def splitInBlocks( descriptions, block_size, auto_block_ignore_readerror ): curblockregs = [] for reg in descriptions: descr = descriptions[reg] - if (not type(descr) is dict) and (descr.newblock or ((reg - start) > block_size)): + if (descr.newblock or (not type(descr) is dict)) and ((reg - start) > block_size): if ((end - start) > 0): _LOGGER.debug(f"Starting new block at 0x{reg:x} ") if ( (auto_block_ignore_readerror == True) or (auto_block_ignore_readerror == False) ) and not descr.newblock: # automatically created block From 2224ac9a2653fdc10b8dc254cfd12b1f5498a182 Mon Sep 17 00:00:00 2001 From: TonyMathiesen <95135900+TonyMathiesen@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:12:10 +0200 Subject: [PATCH 2/7] Update plugin_growatt.py --- .../solax_modbus/plugin_growatt.py | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/custom_components/solax_modbus/plugin_growatt.py b/custom_components/solax_modbus/plugin_growatt.py index 15c911ca..e3c8e725 100644 --- a/custom_components/solax_modbus/plugin_growatt.py +++ b/custom_components/solax_modbus/plugin_growatt.py @@ -3840,24 +3840,25 @@ def value_function_combined_battery_power(initval, descr, datadict): # TL-X TL-XH # ##### -# GrowattModbusSensorEntityDescription( -# name = "Inverter State", -# key = "inverter_state", -# register = 3000, -# register_type = REG_INPUT, -# unit = REGISTER_U8H, #currently not working in the integration -# scale = { 0: "Waiting", 3: "Fault", 4: "Flash", 5: "PV Bat Online", 6: "Bat Online", }, -# allowedtypes = GEN4, -# ), -# GrowattModbusSensorEntityDescription( -# name = "Run Mode", -# key = "run_mode", -# register = 3000, -# register_type = REG_INPUT, -# unit = REGISTER_U8L, #currently not working in the integration -# scale = { 0: "Standby", 1: "Normal", 3: "Fault", 4: "Flash", }, -# allowedtypes = GEN4, -# ), + GrowattModbusSensorEntityDescription( + name = "Inverter State", + key = "inverter_state", + newblock = true, + register = 3000, + register_type = REG_INPUT, + unit = REGISTER_U8H, #currently not working in the integration + scale = { 0: "Waiting", 3: "Fault", 4: "Flash", 5: "PV Bat Online", 6: "Bat Online", }, + allowedtypes = GEN4, + ), + GrowattModbusSensorEntityDescription( + name = "Run Mode", + key = "run_mode", + register = 3000, + register_type = REG_INPUT, + unit = REGISTER_U8L, #currently not working in the integration + scale = { 0: "Standby", 1: "Normal", 3: "Fault", 4: "Flash", }, + allowedtypes = GEN4, + ), GrowattModbusSensorEntityDescription( name = "Total PV Power", key = "total_pv_power", From 5caeb714dea369cde1e70d37f6d620af0219e727 Mon Sep 17 00:00:00 2001 From: TonyMathiesen <95135900+TonyMathiesen@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:40:21 +0200 Subject: [PATCH 3/7] Update plugin_growatt.py --- custom_components/solax_modbus/plugin_growatt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/solax_modbus/plugin_growatt.py b/custom_components/solax_modbus/plugin_growatt.py index e3c8e725..4cd08089 100644 --- a/custom_components/solax_modbus/plugin_growatt.py +++ b/custom_components/solax_modbus/plugin_growatt.py @@ -1029,14 +1029,14 @@ def value_function_combined_battery_power(initval, descr, datadict): key = "active_power_limit", register = 3, allowedtypes = ALL_GEN_GROUP, - internal = True, + internal = ), GrowattModbusSensorEntityDescription( key = "reactive_power_limit", register = 4, unit = REGISTER_S16, allowedtypes = ALL_GEN_GROUP, - internal = True, + internal = ), GrowattModbusSensorEntityDescription( name = "Firmware Version", @@ -3843,7 +3843,7 @@ def value_function_combined_battery_power(initval, descr, datadict): GrowattModbusSensorEntityDescription( name = "Inverter State", key = "inverter_state", - newblock = true, + newblock = True, register = 3000, register_type = REG_INPUT, unit = REGISTER_U8H, #currently not working in the integration From 2dcdba6b3d0f77d2efab7790141403c851831256 Mon Sep 17 00:00:00 2001 From: TonyMathiesen <95135900+TonyMathiesen@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:12:26 +0200 Subject: [PATCH 4/7] Update plugin_growatt.py --- .../solax_modbus/plugin_growatt.py | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/custom_components/solax_modbus/plugin_growatt.py b/custom_components/solax_modbus/plugin_growatt.py index 4cd08089..b3b6dfc9 100644 --- a/custom_components/solax_modbus/plugin_growatt.py +++ b/custom_components/solax_modbus/plugin_growatt.py @@ -113,6 +113,29 @@ def value_function_today_s_solar_energy(initval, descr, datadict): def value_function_combined_battery_power(initval, descr, datadict): return datadict.get('battery_charge_power', 0) - datadict.get('battery_discharge_power',0) +def value_function_inverter_state(initval, descr, datadict): + inverter_state = datadict.get('register_3000', 0) + inverter_state = inverter_state >> 8 # Remove the lower 8 bits by right-shifting by 8 bits + status_dict = { + 0: "Waiting", + 3: "Fault", + 4: "Flash", + 5: "PV Bat Online", + 6: "Bat Online" + } + return status_dict.get(inverter_state) + +def value_function_run_mode(initval, descr, datadict): + run_mode = datadict.get('register_3000', 0) + run_mode = run_mode & 0xFF # Mask out the upper 8 bits, keeping only the lower 8 bits + run_mode_dict = { + 0: "Standby", + 1: "Normal", + 3: "Fault", + 4: "Flash" + } + return run_mode_dict.get(run_mode) + # ================================= Button Declarations ============================================================ BUTTON_TYPES = [ @@ -3841,22 +3864,22 @@ def value_function_combined_battery_power(initval, descr, datadict): # ##### GrowattModbusSensorEntityDescription( - name = "Inverter State", - key = "inverter_state", - newblock = True, + key = "register_3000", register = 3000, register_type = REG_INPUT, - unit = REGISTER_U8H, #currently not working in the integration - scale = { 0: "Waiting", 3: "Fault", 4: "Flash", 5: "PV Bat Online", 6: "Bat Online", }, + allowedtypes = GEN4, + internal = True, + ), + GrowattModbusSensorEntityDescription( + name = "Inverter State", + key = "inverter_state", + value_function = value_function_inverter_state, allowedtypes = GEN4, ), GrowattModbusSensorEntityDescription( name = "Run Mode", key = "run_mode", - register = 3000, - register_type = REG_INPUT, - unit = REGISTER_U8L, #currently not working in the integration - scale = { 0: "Standby", 1: "Normal", 3: "Fault", 4: "Flash", }, + value_function = value_function_run_mode, allowedtypes = GEN4, ), GrowattModbusSensorEntityDescription( From c4d059dbc3f0ad410590d04da7de94b2f66c7782 Mon Sep 17 00:00:00 2001 From: TonyMathiesen <95135900+TonyMathiesen@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:02:45 +0200 Subject: [PATCH 5/7] Update plugin_growatt.py --- custom_components/solax_modbus/plugin_growatt.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom_components/solax_modbus/plugin_growatt.py b/custom_components/solax_modbus/plugin_growatt.py index b3b6dfc9..9b854f4d 100644 --- a/custom_components/solax_modbus/plugin_growatt.py +++ b/custom_components/solax_modbus/plugin_growatt.py @@ -3875,12 +3875,14 @@ def value_function_run_mode(initval, descr, datadict): key = "inverter_state", value_function = value_function_inverter_state, allowedtypes = GEN4, + entity_category = EntityCategory.DIAGNOSTIC, ), GrowattModbusSensorEntityDescription( name = "Run Mode", key = "run_mode", value_function = value_function_run_mode, allowedtypes = GEN4, + entity_category = EntityCategory.DIAGNOSTIC, ), GrowattModbusSensorEntityDescription( name = "Total PV Power", From 201fd1f3f177e01b3dc9ee587895efc0cf71ef86 Mon Sep 17 00:00:00 2001 From: TonyMathiesen <95135900+TonyMathiesen@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:03:14 +0200 Subject: [PATCH 6/7] Update sensor.py --- custom_components/solax_modbus/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/solax_modbus/sensor.py b/custom_components/solax_modbus/sensor.py index c2f6971e..39b5ff17 100644 --- a/custom_components/solax_modbus/sensor.py +++ b/custom_components/solax_modbus/sensor.py @@ -39,7 +39,7 @@ def splitInBlocks( descriptions, block_size, auto_block_ignore_readerror ): curblockregs = [] for reg in descriptions: descr = descriptions[reg] - if (descr.newblock or (not type(descr) is dict)) and ((reg - start) > block_size): + if (not type(descr) is dict) and (descr.newblock or ((reg - start) > block_size)): if ((end - start) > 0): _LOGGER.debug(f"Starting new block at 0x{reg:x} ") if ( (auto_block_ignore_readerror == True) or (auto_block_ignore_readerror == False) ) and not descr.newblock: # automatically created block From 5a3bf732c81196fd5c530a404fb239d38bed3b8b Mon Sep 17 00:00:00 2001 From: TonyMathiesen <95135900+TonyMathiesen@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:06:32 +0200 Subject: [PATCH 7/7] Update plugin_growatt.py --- custom_components/solax_modbus/plugin_growatt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/solax_modbus/plugin_growatt.py b/custom_components/solax_modbus/plugin_growatt.py index 9b854f4d..24947f9a 100644 --- a/custom_components/solax_modbus/plugin_growatt.py +++ b/custom_components/solax_modbus/plugin_growatt.py @@ -1052,14 +1052,14 @@ def value_function_run_mode(initval, descr, datadict): key = "active_power_limit", register = 3, allowedtypes = ALL_GEN_GROUP, - internal = + internal = True, ), GrowattModbusSensorEntityDescription( key = "reactive_power_limit", register = 4, unit = REGISTER_S16, allowedtypes = ALL_GEN_GROUP, - internal = + internal = True, ), GrowattModbusSensorEntityDescription( name = "Firmware Version",