Skip to content

Commit 8ddb00d

Browse files
[ADD] Integration Battery Index for SolarEdge Batteries (#2236)
* [ADD] Integration Battery Index for SolarEdge Batteries https://forum.openwb.de/viewtopic.php?t=9875 * [ADD] BatteryIndex for SolarEdge Invertors with more than one battery attached * [ADD] Integration Battery Index for SolarEdge Batteries Using new registers and offset * Update packages/modules/devices/solaredge/solaredge/bat.py Co-authored-by: LKuemmel <76958050+LKuemmel@users.noreply.github.com> * Update bat.py Fix missing batter_index * Added helper --------- Co-authored-by: LKuemmel <76958050+LKuemmel@users.noreply.github.com>
1 parent 41d2322 commit 8ddb00d

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

packages/helpermodules/update_config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,3 +2229,20 @@ def get_new_phases_to_use(topic) -> int:
22292229
return topics
22302230
self._loop_all_received_topics(upgrade)
22312231
self.__update_topic("openWB/system/datastore_version", 83)
2232+
2233+
def upgrade_datastore_83(self) -> None:
2234+
def upgrade(topic: str, payload) -> None:
2235+
if re.search("openWB/system/device/[0-9]+", topic) is not None:
2236+
payload = decode_payload(payload)
2237+
index = get_index(topic)
2238+
if payload.get("type") == "solaredge":
2239+
for component_topic, component_payload in self.all_received_topics.items():
2240+
if re.search(f"openWB/system/device/{index}/component/[0-9]+/config",
2241+
component_topic) is not None:
2242+
config_payload = decode_payload(component_payload)
2243+
if config_payload["configuration"].get("battery_index") is None:
2244+
config_payload["configuration"].update({
2245+
"battery_index": 1,
2246+
})
2247+
self._loop_all_received_topics(upgrade)
2248+
self.__update_topic("openWB/system/datastore_version", 84)

packages/modules/devices/solaredge/solaredge/bat.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,36 @@ def read_state(self):
5151

5252
def get_values(self) -> Tuple[float, float]:
5353
unit = self.component_config.configuration.modbus_id
54+
# Use 1 as fallback if battery_index is not set
55+
battery_index = getattr(self.component_config.configuration, "battery_index", 1)
56+
57+
# Define base registers for Battery 1 in hex
58+
base_soc_reg = 0xE184 # Battery 1 SoC
59+
base_power_reg = 0xE174 # Battery 1 Power
60+
offset = 0x100 # 256 bytes in hex
61+
62+
# Adjust registers based on battery_index
63+
if battery_index == 1:
64+
soc_reg = base_soc_reg
65+
power_reg = base_power_reg
66+
elif battery_index == 2:
67+
soc_reg = base_soc_reg + offset # 0xE284
68+
power_reg = base_power_reg + offset # 0xE274
69+
else:
70+
raise ValueError(f"Invalid battery_index: {battery_index}. Must be 1 or 2.")
71+
72+
# Read SoC and Power from the appropriate registers
5473
soc = self.__tcp_client.read_holding_registers(
55-
62852, ModbusDataType.FLOAT_32, wordorder=Endian.Little, unit=unit)
74+
soc_reg, ModbusDataType.FLOAT_32, wordorder=Endian.Little, unit=unit
75+
)
5676
power = self.__tcp_client.read_holding_registers(
57-
62836, ModbusDataType.FLOAT_32, wordorder=Endian.Little, unit=unit)
77+
power_reg, ModbusDataType.FLOAT_32, wordorder=Endian.Little, unit=unit
78+
)
79+
80+
# Handle unsupported FLOAT32 case
5881
if power == FLOAT32_UNSUPPORTED:
5982
power = 0
83+
6084
return power, soc
6185

6286
def get_imported_exported(self, power: float) -> Tuple[float, float]:

packages/modules/devices/solaredge/solaredge/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def __init__(self,
2424

2525

2626
class SolaredgeBatConfiguration:
27-
def __init__(self, modbus_id: int = 1):
27+
def __init__(self, modbus_id: int = 1, battery_index: int = 1):
2828
self.modbus_id = modbus_id
29+
self.battery_index = battery_index
2930

3031

3132
class SolaredgeBatSetup(ComponentSetup[SolaredgeBatConfiguration]):

0 commit comments

Comments
 (0)