Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2229,3 +2229,20 @@ def get_new_phases_to_use(topic) -> int:
return topics
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 83)

def upgrade_datastore_83(self) -> None:
def upgrade(topic: str, payload) -> None:
if re.search("openWB/system/device/[0-9]+", topic) is not None:
payload = decode_payload(payload)
index = get_index(topic)
if payload.get("type") == "solaredge":
for component_topic, component_payload in self.all_received_topics.items():
if re.search(f"openWB/system/device/{index}/component/[0-9]+/config",
component_topic) is not None:
config_payload = decode_payload(component_payload)
if config_payload["configuration"].get("battery_index") is None:
config_payload["configuration"].update({
"battery_index": 1,
})
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 84)
28 changes: 26 additions & 2 deletions packages/modules/devices/solaredge/solaredge/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,36 @@ def read_state(self):

def get_values(self) -> Tuple[float, float]:
unit = self.component_config.configuration.modbus_id
# Use 1 as fallback if battery_index is not set
battery_index = getattr(self.component_config.configuration, "battery_index", 1)

# Define base registers for Battery 1 in hex
base_soc_reg = 0xE184 # Battery 1 SoC
base_power_reg = 0xE174 # Battery 1 Power
offset = 0x100 # 256 bytes in hex

# Adjust registers based on battery_index
if battery_index == 1:
soc_reg = base_soc_reg
power_reg = base_power_reg
elif battery_index == 2:
soc_reg = base_soc_reg + offset # 0xE284
power_reg = base_power_reg + offset # 0xE274
else:
raise ValueError(f"Invalid battery_index: {battery_index}. Must be 1 or 2.")

# Read SoC and Power from the appropriate registers
soc = self.__tcp_client.read_holding_registers(
62852, ModbusDataType.FLOAT_32, wordorder=Endian.Little, unit=unit)
soc_reg, ModbusDataType.FLOAT_32, wordorder=Endian.Little, unit=unit
)
power = self.__tcp_client.read_holding_registers(
62836, ModbusDataType.FLOAT_32, wordorder=Endian.Little, unit=unit)
power_reg, ModbusDataType.FLOAT_32, wordorder=Endian.Little, unit=unit
)

# Handle unsupported FLOAT32 case
if power == FLOAT32_UNSUPPORTED:
power = 0

return power, soc

def get_imported_exported(self, power: float) -> Tuple[float, float]:
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/solaredge/solaredge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def __init__(self,


class SolaredgeBatConfiguration:
def __init__(self, modbus_id: int = 1):
def __init__(self, modbus_id: int = 1, battery_index: int = 1):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bei bestehenden SolarEdge-Speichern fehlt die Einstellung battery_index, diese muss in der Konfiguration noch ergänzt werden. Analog zu hier:

def upgrade_datastore_68(self) -> None:

Außerdem in Z. 54 die DATASTORE_VERSION um eins hochzählen und deine Funktion ans Ende der Datei setzen und die Versionszahlen analog zu den anderen Funktionen hochzählen. Beim Starten wird die DATASTORE_VERSION geprüft und wenn diese nicht aktuell ist, die Funktionen ausgeführt und so die Konfiguration geupdatet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Es fehlt noch eine neue Methode in der update_config.py, die bei bestehenden Speichern den battery_index ergänzt.

self.modbus_id = modbus_id
self.battery_index = battery_index


class SolaredgeBatSetup(ComponentSetup[SolaredgeBatConfiguration]):
Expand Down