Skip to content

Varta Modbus - active bat control#3516

Draft
ndrsnhs wants to merge 6 commits into
openWB:masterfrom
ndrsnhs:varta-active-bat-control
Draft

Varta Modbus - active bat control#3516
ndrsnhs wants to merge 6 commits into
openWB:masterfrom
ndrsnhs:varta-active-bat-control

Conversation

@ndrsnhs

@ndrsnhs ndrsnhs commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Aktive Batteriesteuerung für Varta über Modbus

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds active battery control support for Varta batteries via Modbus by extending the Varta Modbus battery component with a set_power_limit() implementation and related state/logging changes.

Changes:

  • Add set_power_limit() / power_limit_controllable() to enable active control via Modbus register writes.
  • Adjust battery state update to include imported/exported energy counters via SimCounter.
  • Introduce module-level logging for debugging control mode transitions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +54 to +55
log.debug(f'last_mode: {self.last_mode}')

Comment on lines +52 to +56
def set_power_limit(self, power_limit: Optional[int]) -> None:
unit=self.__modbus_id
log.debug(f'last_mode: {self.last_mode}')

if power_limit is None:
self.store.set(bat_state)

def set_power_limit(self, power_limit: Optional[int]) -> None:
unit=self.__modbus_id
Comment on lines +39 to +43
def update(self) -> None:
self.set_state(self.get_state())

def get_state(self) -> BatState:
soc = self.client.read_holding_registers(1068, ModbusDataType.INT_16, unit=self.__modbus_id)
power = self.client.read_holding_registers(1066, ModbusDataType.INT_16, unit=self.__modbus_id)
self.peak_filter.check_values(power)
return BatState(
imported, exported = self.sim_counter.sim_count(power)
Comment on lines +62 to +68
self.__tcp_client.write_register(1074, -4000, data_type=ModbusDataType.INT_16, unit=unit)
self.last_mode = None
else:
log.debug("Aktive Batteriesteuerung. Batterie wird auf Stop gesetzt und nicht entladen. "
"Leistungsübergabe und aktive Ladung nicht möglich.")
self.__tcp_client.write_register(1074, 0, data_type=ModbusDataType.INT_16, unit=unit)
self.last_mode = 'stop'

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment on lines +63 to +67
# hier muss die maximale Entladeleistung des Systems gesetzt werden
# Wir nehmen default -4000W an. Nach 120s setzt sich das Register
# automatisch zurück
self.client.write_register(1074, -4000, data_type=ModbusDataType.INT_16, unit=unit)
self.last_mode = None
Comment on lines +56 to +73
def set_power_limit(self, power_limit: Optional[int]) -> None:
unit = self.__modbus_id
log.debug(f'last_mode: {self.last_mode}')

if power_limit is None:
log.debug("Keine Batteriesteuerung, Selbstregelung durch Wechselrichter")
if self.last_mode is not None:
# hier muss die maximale Entladeleistung des Systems gesetzt werden
# Wir nehmen default -4000W an. Nach 120s setzt sich das Register
# automatisch zurück
self.client.write_register(1074, -4000, data_type=ModbusDataType.INT_16, unit=unit)
self.last_mode = None
else:
log.debug("Aktive Batteriesteuerung. Batterie wird auf Stop gesetzt und nicht entladen. "
"Leistungsübergabe und aktive Ladung nicht möglich.")
self.client.write_register(1074, 0, data_type=ModbusDataType.INT_16, unit=unit)
self.last_mode = 'stop'

@ndrsnhs ndrsnhs marked this pull request as draft June 10, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants