EV Solar Charging Without Calculating Solar Surplus — A Closed-Loop PID Approach Using Your Battery

Hi everyone!

This is an open-source Home Assistant integration for automatically adjusting EV charging based on available solar energy.

The main idea is simple:

Instead of calculating how much solar power is available for the EV, the controller uses the home battery as the feedback signal.

The idea

A PV inverter can provide the current PV production, but this does not tell us how much additional power is actually available for the EV.

In a hybrid system, the inverter normally uses available PV power to supply the house and charge the battery. This makes battery charge/discharge power a useful indicator of the current energy balance.

For example, with a target of 500 W battery charging:

  • 800 W charging → increase EV current

  • 500 W charging → maintain EV current

  • 300 W charging → reduce EV current

  • Battery discharging → reduce EV current further

The controller continuously adjusts the EV charging current using PID control.

No PV production calculation is required.

Battery discharge mode

The battery target can also be negative.

For example:

Target = −500 W

The controller increases the EV load until the battery is discharging at approximately 500 W.

The hybrid inverter then sees the battery discharge and, in the tested setup, responds by using more available PV power to charge the battery.

This allows the EV charging power to follow the available PV power without knowing in advance how much the solar panels can produce.

The exact behavior depends on the inverter’s operating mode and configuration.

Inverter configuration

The hybrid inverter needs to be configured so that the battery can supply the house/load when required.

The system can, for example, operate in Zero Export mode so that energy is not exported to the grid.

If the inverter is configured differently, its operating mode and export settings may need to be adjusted for the battery-control strategy to work as intended.

Grid Limiter

The Grid Limiter is a separate safety mechanism.

It is designed to prevent the controller from accidentally increasing EV charging enough to cause excessive grid consumption.

This can happen when:

  • a large household load suddenly turns on;

  • a cloud causes PV production to drop;

  • the battery reaches its discharge limit;

  • the battery becomes fully discharged.

The battery feedback may take some time to reflect these changes while the PID is still trying to maintain its target.

The Grid Limiter monitors grid power and restricts EV charging if grid import exceeds the configured limit.

PID and system delays

The inverter and EV charger have their own response times.

The integration provides:

  • anti-windup

  • derivative-on-measurement

  • output limiting

  • output rate limiting

  • manual/automatic modes

Output rate limiting can prevent the charging current from changing too aggressively.

PID parameters should be tuned according to the response time of the particular inverter and EV charger.

Battery cycling

Using the battery as feedback means that battery power will naturally move somewhat between charging and discharging as solar conditions and household loads change.

A relatively large target provides more operating margin and reduces unnecessary small oscillations.

For example, a target around 1–1.5 kW can be useful when dealing with normal cloud and household-load fluctuations, depending on the installation.

100% SoC and positive charging targets

There is currently one limitation when using a positive battery charging target.

For example, if the target is +500 W and the battery reaches 100% SoC, the inverter may stop charging the battery or reduce the charging power significantly. The controller can then no longer maintain the requested positive charging target.

This is not an issue with a negative battery target.

For example, setting −500 W allows the battery to discharge again, so the controller can continue using battery power as the feedback signal.

The positive-target behavior will be improved in a future version by progressively reducing the charging target as the battery approaches 100% SoC.

What Home Assistant needs

The integration requires:

  • Battery charge/discharge power — PID feedback

  • EV charger current or power — PID output

  • Grid power — optional Grid Limiter

The PV production sensor is not required for the control loop.

Tested setup

The controller has been tested with:

  • Deye 12 kW hybrid inverter

  • Duosida EV charger

Both are integrated into Home Assistant.

The controller is generic and can work with other equipment as long as Home Assistant provides the required numeric entities.

It can also be used for other closed-loop applications such as controlling heater power, inverter limits or other numeric loads.

GitHub: