Varta Modbus - active bat control#3516
Draft
ndrsnhs wants to merge 6 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
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' |
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' | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Aktive Batteriesteuerung für Varta über Modbus