From b63f5ce5271c7615359bc0fc6d3cf8c365716f2f Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 7 Jul 2024 10:06:49 -0700 Subject: [PATCH 01/14] Grid Status On Off binary sensor --- .../solaredge_modbus_multi/binary_sensor.py | 31 ++++++++++++++ .../solaredge_modbus_multi/hub.py | 41 +++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/custom_components/solaredge_modbus_multi/binary_sensor.py b/custom_components/solaredge_modbus_multi/binary_sensor.py index 89f18378..c8401fa7 100644 --- a/custom_components/solaredge_modbus_multi/binary_sensor.py +++ b/custom_components/solaredge_modbus_multi/binary_sensor.py @@ -30,6 +30,9 @@ async def async_setup_entry( if hub.option_detect_extras and inverter.advanced_power_control: entities.append(AdvPowerControlEnabled(inverter, config_entry, coordinator)) + if hub.option_detect_extras: + entities.append(GridStatusOnOff(inverter, config_entry, coordinator)) + if entities: async_add_entities(entities) @@ -92,3 +95,31 @@ def name(self) -> str: @property def is_on(self) -> bool: return self._platform.decoded_model["AdvPwrCtrlEn"] == 0x1 + + +class GridStatusOnOff(SolarEdgeBinarySensorBase): + """Grid Status On Off. This is undocumented from discussions.""" + + icon = "mdi:transmission-tower" + + @property + def available(self) -> bool: + return ( + super().available and "grid_on_off" in self._platform.decoded_model.keys() + ) + + @property + def unique_id(self) -> str: + return f"{self._platform.uid_base}_grid_status_on_off" + + @property + def name(self) -> str: + return "Grid Power Available" + + @property + def entity_registry_enabled_default(self) -> bool: + return "grid_on_off" in self._platform.decoded_model.keys() + + @property + def is_on(self) -> bool: + return self._platform.decoded_model["grid_on_off"] diff --git a/custom_components/solaredge_modbus_multi/hub.py b/custom_components/solaredge_modbus_multi/hub.py index e19f6b1c..00b4427b 100644 --- a/custom_components/solaredge_modbus_multi/hub.py +++ b/custom_components/solaredge_modbus_multi/hub.py @@ -753,6 +753,7 @@ def __init__(self, device_id: int, hub: SolarEdgeModbusMultiHub) -> None: self.global_power_control = None self.advanced_power_control = None self.site_limit_control = None + self._grid_on_off = None async def init_device(self) -> None: """Set up data about the device from modbus.""" @@ -1300,6 +1301,46 @@ async def read_modbus_data(self) -> None: f"No response from inverter ID {self.inverter_unit_id}" ) + """ Grid On/Off Status """ + if self.hub.option_detect_extras is True and self._grid_on_off is not False: + # 42162 as a Uint32 is the correct register to indicate ON/OFF grid. + try: + inverter_data = await self.hub.modbus_read_holding_registers( + unit=self.inverter_unit_id, address=42162, rcount=2 + ) + + decoder = BinaryPayloadDecoder.fromRegisters( + inverter_data.registers, + byteorder=Endian.BIG, + wordorder=Endian.LITTLE, + ) + + self.decoded_model.update( + OrderedDict( + [ + ("grid_on_off", decoder.decode_32bit_uint()), + ] + ) + ) + self._grid_status = True + + except ModbusIllegalAddress: + try: + del self.decoded_model["grid_on_off"] + except KeyError: + pass + + self._grid_status = False + + _LOGGER.debug( + (f"I{self.inverter_unit_id}: " "Grid On/Off NOT available") + ) + + except ModbusIOError: + raise ModbusReadError( + f"No response from inverter ID {self.inverter_unit_id}" + ) + for name, value in iter(self.decoded_model.items()): if isinstance(value, float): display_value = float_to_hex(value) From 70368f9b5b4fd78ced04db16165999e794c3f333 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 7 Jul 2024 10:09:53 -0700 Subject: [PATCH 02/14] Bump version for pre-release --- custom_components/solaredge_modbus_multi/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/solaredge_modbus_multi/manifest.json b/custom_components/solaredge_modbus_multi/manifest.json index 80783116..7756ec65 100644 --- a/custom_components/solaredge_modbus_multi/manifest.json +++ b/custom_components/solaredge_modbus_multi/manifest.json @@ -10,5 +10,5 @@ "issue_tracker": "https://github.com/WillCodeForCats/solaredge-modbus-multi/issues", "loggers": ["custom_components.solaredge_modbus_multi"], "requirements": ["pymodbus>=3.6.6"], - "version": "2.4.16" + "version": "2.4.17-pre.1" } From 4f5f4d975564c198a2c0f3a3a08d772ff5c3376f Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 7 Jul 2024 11:11:21 -0700 Subject: [PATCH 03/14] Change grid on/off address --- custom_components/solaredge_modbus_multi/hub.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/custom_components/solaredge_modbus_multi/hub.py b/custom_components/solaredge_modbus_multi/hub.py index 00b4427b..812585a3 100644 --- a/custom_components/solaredge_modbus_multi/hub.py +++ b/custom_components/solaredge_modbus_multi/hub.py @@ -1303,10 +1303,9 @@ async def read_modbus_data(self) -> None: """ Grid On/Off Status """ if self.hub.option_detect_extras is True and self._grid_on_off is not False: - # 42162 as a Uint32 is the correct register to indicate ON/OFF grid. try: inverter_data = await self.hub.modbus_read_holding_registers( - unit=self.inverter_unit_id, address=42162, rcount=2 + unit=self.inverter_unit_id, address=40113, rcount=2 ) decoder = BinaryPayloadDecoder.fromRegisters( From 79356fbdbd4c24d200283bdca3316f7b32a5b372 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 7 Jul 2024 11:11:44 -0700 Subject: [PATCH 04/14] Bump version for pre-release --- custom_components/solaredge_modbus_multi/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/solaredge_modbus_multi/manifest.json b/custom_components/solaredge_modbus_multi/manifest.json index 7756ec65..3266db4f 100644 --- a/custom_components/solaredge_modbus_multi/manifest.json +++ b/custom_components/solaredge_modbus_multi/manifest.json @@ -10,5 +10,5 @@ "issue_tracker": "https://github.com/WillCodeForCats/solaredge-modbus-multi/issues", "loggers": ["custom_components.solaredge_modbus_multi"], "requirements": ["pymodbus>=3.6.6"], - "version": "2.4.17-pre.1" + "version": "2.4.17-pre.2" } From 7ed1f7cca3b6fb4bf1552a00a7fa0b1cbed528b1 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 7 Jul 2024 12:22:39 -0700 Subject: [PATCH 05/14] Invert sensor return 0 = on (grid available) 1 = off (grid NOT available) --- custom_components/solaredge_modbus_multi/binary_sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/solaredge_modbus_multi/binary_sensor.py b/custom_components/solaredge_modbus_multi/binary_sensor.py index c8401fa7..d643ee59 100644 --- a/custom_components/solaredge_modbus_multi/binary_sensor.py +++ b/custom_components/solaredge_modbus_multi/binary_sensor.py @@ -122,4 +122,4 @@ def entity_registry_enabled_default(self) -> bool: @property def is_on(self) -> bool: - return self._platform.decoded_model["grid_on_off"] + return not self._platform.decoded_model["grid_on_off"] From 26d0e837523e2417ebce3be09574e8a729b02cf8 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 7 Jul 2024 12:24:40 -0700 Subject: [PATCH 06/14] Bump version for pre-release --- custom_components/solaredge_modbus_multi/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/solaredge_modbus_multi/manifest.json b/custom_components/solaredge_modbus_multi/manifest.json index 3266db4f..06aeef88 100644 --- a/custom_components/solaredge_modbus_multi/manifest.json +++ b/custom_components/solaredge_modbus_multi/manifest.json @@ -10,5 +10,5 @@ "issue_tracker": "https://github.com/WillCodeForCats/solaredge-modbus-multi/issues", "loggers": ["custom_components.solaredge_modbus_multi"], "requirements": ["pymodbus>=3.6.6"], - "version": "2.4.17-pre.2" + "version": "2.4.17-pre.3" } From 34385a134d52e4d97c3090b09d879b18d8253a58 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 7 Jul 2024 12:27:53 -0700 Subject: [PATCH 07/14] Shorter name for sensor --- custom_components/solaredge_modbus_multi/binary_sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/solaredge_modbus_multi/binary_sensor.py b/custom_components/solaredge_modbus_multi/binary_sensor.py index d643ee59..0dba2ba0 100644 --- a/custom_components/solaredge_modbus_multi/binary_sensor.py +++ b/custom_components/solaredge_modbus_multi/binary_sensor.py @@ -114,7 +114,7 @@ def unique_id(self) -> str: @property def name(self) -> str: - return "Grid Power Available" + return "Grid Power" @property def entity_registry_enabled_default(self) -> bool: From f5a7459d5f347dfeb78a839c79d7bc171e50c680 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 7 Jul 2024 17:01:46 -0700 Subject: [PATCH 08/14] I_Grid_Status --- custom_components/solaredge_modbus_multi/binary_sensor.py | 6 +++--- custom_components/solaredge_modbus_multi/hub.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/custom_components/solaredge_modbus_multi/binary_sensor.py b/custom_components/solaredge_modbus_multi/binary_sensor.py index 0dba2ba0..c4b3cb7e 100644 --- a/custom_components/solaredge_modbus_multi/binary_sensor.py +++ b/custom_components/solaredge_modbus_multi/binary_sensor.py @@ -105,7 +105,7 @@ class GridStatusOnOff(SolarEdgeBinarySensorBase): @property def available(self) -> bool: return ( - super().available and "grid_on_off" in self._platform.decoded_model.keys() + super().available and "I_Grid_Status" in self._platform.decoded_model.keys() ) @property @@ -118,8 +118,8 @@ def name(self) -> str: @property def entity_registry_enabled_default(self) -> bool: - return "grid_on_off" in self._platform.decoded_model.keys() + return "I_Grid_Status" in self._platform.decoded_model.keys() @property def is_on(self) -> bool: - return not self._platform.decoded_model["grid_on_off"] + return not self._platform.decoded_model["I_Grid_Status"] diff --git a/custom_components/solaredge_modbus_multi/hub.py b/custom_components/solaredge_modbus_multi/hub.py index 812585a3..a0f4b6a1 100644 --- a/custom_components/solaredge_modbus_multi/hub.py +++ b/custom_components/solaredge_modbus_multi/hub.py @@ -1317,7 +1317,7 @@ async def read_modbus_data(self) -> None: self.decoded_model.update( OrderedDict( [ - ("grid_on_off", decoder.decode_32bit_uint()), + ("I_Grid_Status", decoder.decode_32bit_uint()), ] ) ) @@ -1325,7 +1325,7 @@ async def read_modbus_data(self) -> None: except ModbusIllegalAddress: try: - del self.decoded_model["grid_on_off"] + del self.decoded_model["I_Grid_Status"] except KeyError: pass From bb3a9d91558a873fed59e211920204afc058611f Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 7 Jul 2024 17:02:28 -0700 Subject: [PATCH 09/14] Update hub.py --- custom_components/solaredge_modbus_multi/hub.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/solaredge_modbus_multi/hub.py b/custom_components/solaredge_modbus_multi/hub.py index a0f4b6a1..d2235146 100644 --- a/custom_components/solaredge_modbus_multi/hub.py +++ b/custom_components/solaredge_modbus_multi/hub.py @@ -753,7 +753,7 @@ def __init__(self, device_id: int, hub: SolarEdgeModbusMultiHub) -> None: self.global_power_control = None self.advanced_power_control = None self.site_limit_control = None - self._grid_on_off = None + self._grid_status = None async def init_device(self) -> None: """Set up data about the device from modbus.""" @@ -1302,7 +1302,7 @@ async def read_modbus_data(self) -> None: ) """ Grid On/Off Status """ - if self.hub.option_detect_extras is True and self._grid_on_off is not False: + if self.hub.option_detect_extras is True and self._grid_status is not False: try: inverter_data = await self.hub.modbus_read_holding_registers( unit=self.inverter_unit_id, address=40113, rcount=2 From 8296b2292e8f58073155a322e17abc7b5b246d03 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 7 Jul 2024 17:03:48 -0700 Subject: [PATCH 10/14] Update binary_sensor.py --- custom_components/solaredge_modbus_multi/binary_sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/solaredge_modbus_multi/binary_sensor.py b/custom_components/solaredge_modbus_multi/binary_sensor.py index c4b3cb7e..8079ad3f 100644 --- a/custom_components/solaredge_modbus_multi/binary_sensor.py +++ b/custom_components/solaredge_modbus_multi/binary_sensor.py @@ -114,7 +114,7 @@ def unique_id(self) -> str: @property def name(self) -> str: - return "Grid Power" + return "Grid Status" @property def entity_registry_enabled_default(self) -> bool: From 159d2515e23af81253c9f32a6f16907bdb14eeaf Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 14 Jul 2024 07:17:07 -0700 Subject: [PATCH 11/14] Bump version for release --- custom_components/solaredge_modbus_multi/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/solaredge_modbus_multi/manifest.json b/custom_components/solaredge_modbus_multi/manifest.json index 06aeef88..12a2f2e1 100644 --- a/custom_components/solaredge_modbus_multi/manifest.json +++ b/custom_components/solaredge_modbus_multi/manifest.json @@ -10,5 +10,5 @@ "issue_tracker": "https://github.com/WillCodeForCats/solaredge-modbus-multi/issues", "loggers": ["custom_components.solaredge_modbus_multi"], "requirements": ["pymodbus>=3.6.6"], - "version": "2.4.17-pre.3" + "version": "2.4.17" } From 2383bbcbc57157ebb1f363dea7cc65e85526f81b Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 14 Jul 2024 16:07:53 -0700 Subject: [PATCH 12/14] Add POWER class to grid status binary sensor --- custom_components/solaredge_modbus_multi/binary_sensor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/custom_components/solaredge_modbus_multi/binary_sensor.py b/custom_components/solaredge_modbus_multi/binary_sensor.py index 8079ad3f..5985680a 100644 --- a/custom_components/solaredge_modbus_multi/binary_sensor.py +++ b/custom_components/solaredge_modbus_multi/binary_sensor.py @@ -4,7 +4,10 @@ import logging -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + BinarySensorDeviceClass, + BinarySensorEntity, +) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import EntityCategory @@ -100,6 +103,7 @@ def is_on(self) -> bool: class GridStatusOnOff(SolarEdgeBinarySensorBase): """Grid Status On Off. This is undocumented from discussions.""" + device_class = BinarySensorDeviceClass.POWER icon = "mdi:transmission-tower" @property From 161f46df733d3b56c9e8d31ea364844ceb428059 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 14 Jul 2024 16:32:20 -0700 Subject: [PATCH 13/14] Bump version for release --- custom_components/solaredge_modbus_multi/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/solaredge_modbus_multi/manifest.json b/custom_components/solaredge_modbus_multi/manifest.json index 12a2f2e1..2f6fbea3 100644 --- a/custom_components/solaredge_modbus_multi/manifest.json +++ b/custom_components/solaredge_modbus_multi/manifest.json @@ -10,5 +10,5 @@ "issue_tracker": "https://github.com/WillCodeForCats/solaredge-modbus-multi/issues", "loggers": ["custom_components.solaredge_modbus_multi"], "requirements": ["pymodbus>=3.6.6"], - "version": "2.4.17" + "version": "2.4.18" } From 1f94f26c9ba9a859bad562bdea9c93bfc4065692 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 21 Jul 2024 10:56:56 -0700 Subject: [PATCH 14/14] Always read grid status --- custom_components/solaredge_modbus_multi/hub.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/solaredge_modbus_multi/hub.py b/custom_components/solaredge_modbus_multi/hub.py index d2235146..b9038e8e 100644 --- a/custom_components/solaredge_modbus_multi/hub.py +++ b/custom_components/solaredge_modbus_multi/hub.py @@ -1302,7 +1302,7 @@ async def read_modbus_data(self) -> None: ) """ Grid On/Off Status """ - if self.hub.option_detect_extras is True and self._grid_status is not False: + if self._grid_status is not False: try: inverter_data = await self.hub.modbus_read_holding_registers( unit=self.inverter_unit_id, address=40113, rcount=2