Skip to content

Commit fc6de7c

Browse files
Merge pull request #620 from WillCodeForCats/619-detect-power-loss-grid-is-out
Add Grid Power Available binary sensor
2 parents 8f28a63 + 8296b22 commit fc6de7c

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

custom_components/solaredge_modbus_multi/binary_sensor.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ async def async_setup_entry(
3030
if hub.option_detect_extras and inverter.advanced_power_control:
3131
entities.append(AdvPowerControlEnabled(inverter, config_entry, coordinator))
3232

33+
if hub.option_detect_extras:
34+
entities.append(GridStatusOnOff(inverter, config_entry, coordinator))
35+
3336
if entities:
3437
async_add_entities(entities)
3538

@@ -92,3 +95,31 @@ def name(self) -> str:
9295
@property
9396
def is_on(self) -> bool:
9497
return self._platform.decoded_model["AdvPwrCtrlEn"] == 0x1
98+
99+
100+
class GridStatusOnOff(SolarEdgeBinarySensorBase):
101+
"""Grid Status On Off. This is undocumented from discussions."""
102+
103+
icon = "mdi:transmission-tower"
104+
105+
@property
106+
def available(self) -> bool:
107+
return (
108+
super().available and "I_Grid_Status" in self._platform.decoded_model.keys()
109+
)
110+
111+
@property
112+
def unique_id(self) -> str:
113+
return f"{self._platform.uid_base}_grid_status_on_off"
114+
115+
@property
116+
def name(self) -> str:
117+
return "Grid Status"
118+
119+
@property
120+
def entity_registry_enabled_default(self) -> bool:
121+
return "I_Grid_Status" in self._platform.decoded_model.keys()
122+
123+
@property
124+
def is_on(self) -> bool:
125+
return not self._platform.decoded_model["I_Grid_Status"]

custom_components/solaredge_modbus_multi/hub.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ def __init__(self, device_id: int, hub: SolarEdgeModbusMultiHub) -> None:
753753
self.global_power_control = None
754754
self.advanced_power_control = None
755755
self.site_limit_control = None
756+
self._grid_status = None
756757

757758
async def init_device(self) -> None:
758759
"""Set up data about the device from modbus."""
@@ -1300,6 +1301,45 @@ async def read_modbus_data(self) -> None:
13001301
f"No response from inverter ID {self.inverter_unit_id}"
13011302
)
13021303

1304+
""" Grid On/Off Status """
1305+
if self.hub.option_detect_extras is True and self._grid_status is not False:
1306+
try:
1307+
inverter_data = await self.hub.modbus_read_holding_registers(
1308+
unit=self.inverter_unit_id, address=40113, rcount=2
1309+
)
1310+
1311+
decoder = BinaryPayloadDecoder.fromRegisters(
1312+
inverter_data.registers,
1313+
byteorder=Endian.BIG,
1314+
wordorder=Endian.LITTLE,
1315+
)
1316+
1317+
self.decoded_model.update(
1318+
OrderedDict(
1319+
[
1320+
("I_Grid_Status", decoder.decode_32bit_uint()),
1321+
]
1322+
)
1323+
)
1324+
self._grid_status = True
1325+
1326+
except ModbusIllegalAddress:
1327+
try:
1328+
del self.decoded_model["I_Grid_Status"]
1329+
except KeyError:
1330+
pass
1331+
1332+
self._grid_status = False
1333+
1334+
_LOGGER.debug(
1335+
(f"I{self.inverter_unit_id}: " "Grid On/Off NOT available")
1336+
)
1337+
1338+
except ModbusIOError:
1339+
raise ModbusReadError(
1340+
f"No response from inverter ID {self.inverter_unit_id}"
1341+
)
1342+
13031343
for name, value in iter(self.decoded_model.items()):
13041344
if isinstance(value, float):
13051345
display_value = float_to_hex(value)

custom_components/solaredge_modbus_multi/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"issue_tracker": "https://github.com/WillCodeForCats/solaredge-modbus-multi/issues",
1111
"loggers": ["custom_components.solaredge_modbus_multi"],
1212
"requirements": ["pymodbus>=3.6.6"],
13-
"version": "2.4.16"
13+
"version": "2.4.17-pre.3"
1414
}

0 commit comments

Comments
 (0)