HA Energy Optimizer - ML-Powered (Scikit-Learn) & InfluxDB Integration

Hey everyone! :waving_hand:

After running this on my own setup for a year I finally cleaned it up and published it. Would love to get feedback from the community before I consider pushing it to HACS.


What problem does it solve?

If you have solar panels + a battery, you face the same daily question:

“How much should I charge the battery from cheap night electricity so I don’t have to buy expensive peak electricity tomorrow — but without over-charging and wasting the solar I’ll generate during the day?”

Most people set a fixed percentage. Energy Optimizer calculates the exact right answer every day, accounting for tomorrow’s solar forecast (terrain-corrected), your heat pump load, outdoor temperature, and current tariff.


Key features

:battery: Smart valley charging — calculates the exact SOC target for tomorrow’s peak demand. No fixed percentages, no guessing.

:sun: Solar terrain correction — if a hill or building systematically blocks your afternoon sun, HA’s Forecast.Solar over-predicts every day. The add-on learns the correction factor from your real production history automatically.

:brain: scikit-learn ML model — a GradientBoostingRegressor trained on up to 90 days of your own sensor history. Features are built dynamically from whatever sensors you actually have — if a sensor is missing, it’s simply excluded. Trains nightly, fully local.

:high_voltage: Animated energy flow diagram — real-time SVG showing exactly where your watts are going at any moment (solar → house, battery → house, grid → battery, etc.), updated every 30 seconds.

:thermometer: Heat pump control — raises/lowers setpoints based on tariff period, surplus solar, and outdoor temperature. Multi-zone supported.

:person_swimming: Pool pump + cleaner — runs during solar surplus or valley tariff to hit daily/weekly runtime targets. Pool cleaner auto-starts with the pump and stops after 15 min.

:gear: Custom loads — add any switch.* entity (irrigation pump, water heater, anything) and choose its scheduling window: valley only / solar surplus / both / custom hours.

:bar_chart: Savings tracking — counterfactual method: what would the grid meter have read without the battery? Priced at your tariff. Honest accounting — suboptimal decisions show up as small negative savings.


Setup Wizard — no YAML editing required

An 8-step wizard walks you through everything:

Data → Location → Grid → Solar → Battery → Loads → Tariff → Done

It auto-discovers your HA entities using keyword + device class + unit scoring and shows a data quality thermometer so you know upfront whether you have enough history for good predictions.


:locked: 100% local — no cloud, no telemetry, no accounts

Everything runs inside the Docker container on your own hardware. Your energy data, sensor readings, and ML model never leave your home network. The only communication is with your local HA instance and, optionally, a local InfluxDB instance.


What hardware does it support?

Designed around Huawei Luna2000 but works with any battery that exposes HA entities for SOC, charge/discharge power, and working mode. The wizard handles entity discovery for any brand.

Controlled appliances: heat pump (any climate entity or ebusd setpoints), pool pump, pool cleaner, dishwasher, washing machine, dryer, EV charger (Wallbox/OCPP/Zappi), and custom switch loads.


Installation

Settings → Add-ons → Add-on store → ⋮ → Repositories → paste:

https://github.com/hirofairlane/ha-energy-optimizer

Then open the Wizard tab and follow the steps. InfluxDB add-on is recommended (90 days of history = much better ML) but not required — it falls back to HA Recorder.


What I’d love feedback on

This is my first public add-on. I’ve tested it on my own installation but every setup is different. Specifically I’m curious about:

  • Does the wizard entity discovery work well for non-Huawei batteries?
  • Are there tariff structures I’m missing? (Currently defaults to Spain 2.0TD but fully editable)
  • What other load types would be useful?
  • Anything that breaks on your setup

GitHub (code, issues, docs): GitHub - hirofairlane/ha-energy-optimizer: Energy Optimizer - Add-on para Home Assistant · GitHub

All feedback welcome — open an issue, reply here, or both. Thanks! :folded_hands:

1 Like

This is exactly what I’m looking for, any chance to get this as docker container?

It is already a Docker container — Home Assistant add-ons run as isolated Docker containers managed by the supervisor. Packaging it as a standalone container would actually make things harder, since it relies heavily on the HA API for entity states, service calls, and ingress. Running it inside HA gives you all of that for free, with no extra networking or auth setup.

If you have HA OS or Supervised, installation is just adding the repository URL in the add-on store. Please let me know if you want further information.

That’s the point, I’m running HA as separate docker container…