KOSTAL: Proportional home battery power control for the optimizer
Feature request: KOSTAL Plenticore Proportional home battery power control for the optimizer
With the experimental optimizer enabled, evcc can already control the home battery, but the control is currently discrete: charging, preventing charging, or blocking the battery.
It would be beneficial to support continuous battery charging power setpoints, allowing the optimizer to determine the optimal charging power for each time step instead of only selecting a discrete battery state.
Motivation
The optimizer already calculates the desired charging and discharging power of the home battery. However, the current control interface cannot fully translate this plan into actual inverter behavior when only discrete commands are available.
For example, with 5 kW of available PV surplus, the optimizer might calculate that charging the home battery at 3 kW and exporting the remaining 2 kW is economically optimal.
With proportional control, evcc could apply the optimizer’s calculated charging power directly, rather than simply enabling or disabling battery charging.
The proportion should be calculated by the optimizer based on the forecast, electricity prices, feed-in tariff, battery state of charge and other constraints. It should not be a fixed percentage configured separately by the user.
Example: KOSTAL PLENTICORE plus G2
The KOSTAL PLENTICORE plus G2 supports external battery power control via Modbus TCP.
According to the official KOSTAL Modbus interface specification, the following registers are available for external battery management:
| Register (decimal) | Hex address | Description | Format | Access |
|---|---|---|---|---|
| 1026 | 0x402 | Battery charge power (AC), absolute setpoint | Float32, W | Read/write |
| 1030 | 0x406 | Battery charge power (AC), relative setpoint | Float32, % | Read/write |
| 1034 | 0x40A | Battery charge power (DC), absolute setpoint | Float32, W | Read/write |
| 1036 | 0x40C | Battery charge power (DC), relative setpoint | Float32, % | Read/write |
| 1038 | 0x40E | Maximum battery charge power limit | Float32, W | Read/write |
| 1076 | 0x434 | Maximum charge power available from the battery | Float32, W | Read-only |
The absolute DC charging power setpoint at register 1034 (0x40A) appears to be a suitable starting point for this use case. The exact choice of AC or DC setpoint should be validated against the inverter integration and its existing control implementation.
The registers use two consecutive Modbus registers for each Float32 value. Writing the setpoint uses Modbus function code 0x10 (Write Multiple Registers).
Official reference: KOSTAL Modbus TCP & SunSpec interface specification.
Suggested implementation
- Extend the battery control interface to support a desired charging/discharging power in watts, in addition to the existing discrete commands.
- Let the optimizer calculate the target battery power for each time step.
- Pass this setpoint to the respective battery/inverter integration.
- Let the integration apply device-specific limits, SoC restrictions and supported control modes.
- Preserve the existing discrete commands as a fallback for devices that do not support proportional power control.
Expected benefits
- More accurate execution of the optimizer’s charging schedule.
- Better distribution of PV surplus between home battery charging and grid export.
- Improved feed-in peak management.
- Less unnecessary switching between charging and blocking states.
- Better use of battery power limits and dynamic electricity prices.
Would it make sense to extend the battery control interface with a continuous power setpoint, allowing compatible integrations such as KOSTAL to apply the optimizer’s desired charging power directly?
Feature request: Proportional home battery power control for the optimizer
With the experimental optimizer enabled, evcc can already control the home battery, but the control is currently discrete: charging, preventing charging, or blocking the battery.
It would be beneficial to support continuous battery charging power setpoints, allowing the optimizer to determine the optimal charging power for each time step instead of only selecting a discrete battery state.
Motivation
The optimizer already calculates the desired charging and discharging power of the home battery. However, the current control interface cannot fully translate this plan into actual inverter behavior when only discrete commands are available.
For example, with 5 kW of available PV surplus, the optimizer might calculate that charging the home battery at 3 kW and exporting the remaining 2 kW is economically optimal.
With proportional control, evcc could apply the optimizer’s calculated charging power directly, rather than simply enabling or disabling battery charging.
The proportion should be calculated by the optimizer based on the forecast, electricity prices, feed-in tariff, battery state of charge and other constraints. It should not be a fixed percentage configured separately by the user.
Example: KOSTAL PLENTICORE plus G2
The KOSTAL PLENTICORE plus G2 supports external battery power control via Modbus TCP.
According to the official KOSTAL Modbus interface specification, the following registers are available for external battery management:
Register (decimal) Hex address Description Format Access 1026 0x402 Battery charge power (AC), absolute setpoint Float32, W Read/write 1030 0x406 Battery charge power (AC), relative setpoint Float32, % Read/write 1034 0x40A Battery charge power (DC), absolute setpoint Float32, W Read/write 1036 0x40C Battery charge power (DC), relative setpoint Float32, % Read/write 1038 0x40E Maximum battery charge power limit Float32, W Read/write 1076 0x434 Maximum charge power available from the battery Float32, W Read-only
The absolute DC charging power setpoint at register 1034 (0x40A) appears to be a suitable starting point for this use case. The exact choice of AC or DC setpoint should be validated against the inverter integration and its existing control implementation.
The registers use two consecutive Modbus registers for each Float32 value. Writing the setpoint uses Modbus function code 0x10 (Write Multiple Registers).
Official reference: KOSTAL Modbus TCP & SunSpec interface specification.
Suggested implementation
- Extend the battery control interface to support a desired charging/discharging power in watts, in addition to the existing discrete commands.
- Let the optimizer calculate the target battery power for each time step.
- Pass this setpoint to the respective battery/inverter integration.
- Let the integration apply device-specific limits, SoC restrictions and supported control modes.
- Preserve the existing discrete commands as a fallback for devices that do not support proportional power control.
Expected benefits
- More accurate execution of the optimizer’s charging schedule.
- Better distribution of PV surplus between home battery charging and grid export.
- Improved feed-in peak management.
- Less unnecessary switching between charging and blocking states.
- Better use of battery power limits and dynamic electricity prices.
Would it make sense to extend the battery control interface with a continuous power setpoint, allowing compatible integrations such as KOSTAL to apply the optimizer’s desired charging power directly?
Thanks for the proposal. Current state:
- The Kostal Plenticore G2 template (
templates/definition/meter/kostal-plenticore-gen2.yaml) already writes register 1034 (DC charge setpoint, absolute W) for thechargeanddischargebattery modes, but with a fixed configured value (maxchargepower/maxdischargepower). - The battery control interface (
api/batterymode.go,BatteryController.SetBatteryModeinapi/api.go) only knows discrete modes (normal,hold,charge,holdcharge,discharge). The optimizer's computed battery power is mapped onto these modes incore/site_optimizer.go; no power value is passed through.
Supporting a continuous setpoint would need a new optional capability in api (e.g. a battery power setpoint in W), the optimizer passing its planned power to it, and the Kostal template exposing it via register 1034. That is an API design change, so it needs a maintainer decision first.
🤖 Generated with Claude Code
Thanks for clarifying the current implementation. This confirms that the KOSTAL integration already supports writing the absolute DC charge power setpoint to register 1034, but the optimizer can currently only select discrete battery modes.
I think the key improvement would be to introduce an optional, continuous battery power setpoint in the battery control API.
The optimizer already calculates the desired battery power. Instead of mapping that result to discrete modes such as charge, hold or discharge, it could pass the calculated setpoint in watts to integrations that support it.
For the KOSTAL PLENTICORE G2, the integration could then write the requested power to register 1034, subject to the existing device limits and safety constraints.
This would allow the optimizer to determine the optimal split between battery charging and grid export dynamically, based on forecasts, tariffs, battery SoC and other constraints, without introducing a device-specific percentage setting.
Ideally, this would be an optional capability so that existing integrations and discrete battery modes remain backward-compatible.
Would the maintainers consider this API extension as a possible next step for the experimental optimizer?
This is not related to Kostal devices but adresses a missing interface. Perhaps the title is misleading.
evcc avoids to write battery power setpoints and actually limits (beside max/zero in forced charge/hold).
There is no need to write values as limits/setpoints for the optimizer doing it's job. atm andig states the changes have no priority.
This kind of feature has potential to optimize delayed battery surplus charge and reduce grid peaks more granular. It has also downsides because the limits set are forecast based and likely to miss the optimal solution resulting in higher costs. Personally I am doing some experiments on it.
The optimizer does a very good job already and I am looking forward on optimization of integration, edge cases and planning.
It would be beneficial to support continuous battery charging power setpoints, allowing the optimizer to determine the optimal charging power for each time step instead of only selecting a discrete battery state.
That's in the backlog, but not a priority: https://github.com/evcc-io/evcc/issues/36065.