Self-learning overnight battery charge target for AlphaESS + Solar (Home Assistant automations)

I put together a small closed-loop system that automatically tunes how much my AlphaESS home battery charges overnight from the grid, based on what actually happens each night — the goal was simply to cut the monthly electricity bill without manually tweaking settings.

How it works:

  • Each evening, an automation blends the next day’s solar forecast (Solcast) and the weather outlook into a tiered overnight charge target (40-90% range).
    • Every morning it checks what actually happened: how low the battery got before sunrise, and how much was charged from the grid.
    • Based on that outcome, it nudges the charge target up or down for future similar days (step_up/step_down, currently 5%/3%) — so it slowly converges toward “just enough” instead of always erring on the safe (expensive) side.
    • A hard safety floor/ceiling (40-90% target, battery itself clamped 45-85%) makes sure it never risks running the battery flat before sunrise, no matter what the learning loop decides.

Happy to answer questions if anyone wants to adapt it for their own inverter/battery setup.

Great! How do you handle unusual days where Solcast is significantly wrong? It would be interesting to see whether the learning loop can distinguish forecast errors from genuinely unusual battery demand.how do you handle unusual days where Solcast is significantly wrong? It would be interesting to see whether the learning loop can distinguish forecast errors from genuinely unusual battery demand.