Skip to content

Commit 8810b7a

Browse files
ndrsnhsLKuemmel
andauthored
Victron bat control - add ve.bus id (#2960)
* adjustable vebus reg * Update packages/helpermodules/update_config.py --------- Co-authored-by: LKuemmel <76958050+LKuemmel@users.noreply.github.com>
1 parent 39b5a11 commit 8810b7a

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

packages/helpermodules/update_config.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,3 +2636,22 @@ def upgrade(topic: str, payload) -> None:
26362636
return {"openWB/optional/ep/flexible_tariff/provider": decode_payload(payload)}
26372637
self._loop_all_received_topics(upgrade)
26382638
self.__update_topic("openWB/system/datastore_version", 102)
2639+
2640+
def upgrade_datastore_103(self) -> None:
2641+
def upgrade(topic: str, payload) -> None:
2642+
if re.search("openWB/system/device/[0-9]+", topic) is not None:
2643+
payload = decode_payload(payload)
2644+
index = get_index(topic)
2645+
if payload.get("type") == "victron":
2646+
for component_topic, component_payload in self.all_received_topics.items():
2647+
if re.search(f"openWB/system/device/{index}/component/[0-9]+/config$",
2648+
component_topic) is not None:
2649+
config_payload = decode_payload(component_payload)
2650+
if (config_payload["type"] == "bat" and
2651+
config_payload["configuration"].get("vebus_id") is None):
2652+
config_payload["configuration"].update({
2653+
"vebus_id": 228,
2654+
})
2655+
return {component_topic: config_payload}
2656+
self._loop_all_received_topics(upgrade)
2657+
self.__update_topic("openWB/system/datastore_version", 103)

packages/modules/devices/victron/victron/bat.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def update(self) -> None:
5050

5151
def set_power_limit(self, power_limit: Optional[int]) -> None:
5252
modbus_id = self.component_config.configuration.modbus_id
53+
vebus_id = self.component_config.configuration.vebus_id
5354

5455
# Wenn Victron Dynamic ESS aktiv, erfolgt keine weitere Regelung in openWB
5556
dynamic_ess_mode = self.__tcp_client.read_holding_registers(5400, ModbusDataType.UINT_16, unit=modbus_id)
@@ -61,26 +62,27 @@ def set_power_limit(self, power_limit: Optional[int]) -> None:
6162
log.debug("Keine Batteriesteuerung, Selbstregelung durch Wechselrichter")
6263
if self.last_mode is not None:
6364
# ESS Mode 1 für Selbstregelung mit Phasenkompensation setzen
64-
self.__tcp_client.write_registers(39, [0], data_type=ModbusDataType.UINT_16, unit=228)
6565
self.__tcp_client.write_registers(2902, [1], data_type=ModbusDataType.UINT_16, unit=modbus_id)
66+
self.__tcp_client.write_registers(39, [0], data_type=ModbusDataType.UINT_16, unit=vebus_id)
6667
self.last_mode = None
6768
elif power_limit == 0:
6869
log.debug("Aktive Batteriesteuerung. Batterie wird auf Stop gesetzt und nicht entladen")
6970
if self.last_mode != 'stop':
7071
# ESS Mode 3 für externe Steuerung und keine Entladung
7172
self.__tcp_client.write_registers(2902, [3], data_type=ModbusDataType.UINT_16, unit=modbus_id)
72-
self.__tcp_client.write_registers(39, [1], data_type=ModbusDataType.UINT_16, unit=228)
73+
self.__tcp_client.write_registers(39, [1], data_type=ModbusDataType.UINT_16, unit=vebus_id)
7374
self.last_mode = 'stop'
7475
elif power_limit < 0:
7576
if self.last_mode != 'discharge':
7677
# ESS Mode 3 für externe Steuerung und auf L1 wird entladen
7778
self.__tcp_client.write_registers(2902, [3], data_type=ModbusDataType.UINT_16, unit=modbus_id)
78-
self.__tcp_client.write_registers(39, [0], data_type=ModbusDataType.UINT_16, unit=228)
79+
self.__tcp_client.write_registers(39, [0], data_type=ModbusDataType.UINT_16, unit=vebus_id)
7980
self.last_mode = 'discharge'
8081
# Die maximale Entladeleistung begrenzen auf 5000W
8182
power_value = int(min(power_limit, 5000))
8283
log.debug(f"Aktive Batteriesteuerung. Batterie wird mit {power_value} W entladen")
83-
self.__tcp_client.write_registers(37, [power_value & 0xFFFF], data_type=ModbusDataType.INT_16, unit=228)
84+
self.__tcp_client.write_registers(
85+
37, [power_value & 0xFFFF], data_type=ModbusDataType.INT_16, unit=vebus_id)
8486

8587
def power_limit_controllable(self) -> bool:
8688
return True

packages/modules/devices/victron/victron/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 VictronBatConfiguration:
27-
def __init__(self, modbus_id: int = 100):
27+
def __init__(self, modbus_id: int = 100, vebus_id: int = 228):
2828
self.modbus_id = modbus_id
29+
self.vebus_id = vebus_id
2930

3031

3132
class VictronBatSetup(ComponentSetup[VictronBatConfiguration]):

0 commit comments

Comments
 (0)