Skip to content

Add ML energy consumption predictor (experimental)#34

Open
pookey wants to merge 2 commits intojohanzander:mainfrom
pookey:ml-prediction
Open

Add ML energy consumption predictor (experimental)#34
pookey wants to merge 2 commits intojohanzander:mainfrom
pookey:ml-prediction

Conversation

@pookey
Copy link
Copy Markdown
Contributor

@pookey pookey commented Mar 7, 2026

Summary

Adds an optional ml_prediction consumption strategy using XGBoost to predict 24h energy consumption at 15-minute resolution. Depends on #33 (configurable consumption strategies).

What's included

  • Complete ML module (ml/) with training, prediction, feature engineering, and standalone CLI
  • ML Report dashboard page showing model metrics, feature importance, and forecast comparison chart
  • Daily model retrain scheduler (23:00)
  • /api/ml-report endpoint for the dashboard
  • Docker base image switch from Alpine 3.19 to Debian Bookworm (required for xgboost/scikit-learn wheels)

Honest assessment

This is experimental. In my testing so far, the ML predictions are roughly on par with or slightly worse than the simpler influxdb_7d_avg strategy from #33. The model also:

  • Adds significant startup time (retrain on boot ~3-5s, weather forecast fetch ~1s)
  • Pulls in heavy dependencies: xgboost (~150MB), scikit-learn (~30MB), astral
  • Requires switching from Alpine to Debian base image
  • Needs weather entity and InfluxDB configured

That said, it's a fun playground for experimenting with consumption prediction, and the ML Report page gives good visibility into how well (or poorly) the model performs compared to baselines.

I'd completely understand if this isn't something that belongs in core. The influxdb_7d_avg strategy in #33 is more practical for production use.

Config example

home:
  consumption_strategy: "ml_prediction"
ml:
  location:
    latitude: 59.3293
    longitude: 18.0686
    timezone: "Europe/Stockholm"
  weather_entity: "weather.forecast_home"
  feature_sensors:
    outdoor_temperature: "sensor.outdoor_temperature"
  training:
    days_of_history: 30

Test plan

  • Verify ML model trains on boot when ml config is present
  • Verify ML Report page shows metrics, feature importance, and chart
  • Test ml_prediction strategy produces 96-period forecast
  • Verify fallback to fixed when ml config section is missing
  • Test daily retrain scheduler fires at 23:00
  • Verify system starts correctly when ml section is absent (no ML features loaded)

Add home.consumption_strategy setting with three modes:
- "sensor" (default): uses HA 48h average sensor as before
- "fixed": flat rate from config.yaml consumption value
- "influxdb_7d_avg": 7-day rolling average from InfluxDB power
  sensor data at 15-minute resolution

The influxdb_7d_avg strategy queries local_load_power sensor data
for the past 7 days, averages per 15-minute period, and produces
a 96-value consumption profile that reflects actual household
usage patterns including weekday/weekend variation.

Also adds home.timezone setting and prediction caching to avoid
redundant InfluxDB queries during logging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add ml_prediction consumption strategy using XGBoost to generate
96 quarter-hourly energy consumption forecasts. The model trains
on InfluxDB historical data with weather forecast features from
Home Assistant and retrains daily at 23:00.

Includes:
- ML module (ml/) with trainer, predictor, data_fetcher, config
- ML Report dashboard page showing model metrics, feature
  importance, and forecast comparison
- /api/ml-report endpoint
- Docker base image switch to Debian Bookworm for xgboost/sklearn
- Daily retrain scheduler in app.py

The ML predictor is experimental — the influxdb_7d_avg strategy
is recommended for production use.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@johanzander
Copy link
Copy Markdown
Owner

Been thinking about this. I've been thinking about adding some ML for energy consumption prediction but never prioritized it because the 48h average sensor works good enough for me. I also have a heat pump and EV charger that makes prediction on a more granular level difficult I believe. But nevertheless would be great to get this working and for me to learn about ML.
That said it probably makes more sense to have it outside the BESS manager. Main reason is that I have another project (https://github.com/johanzander/Theria) that would benefit from this as well. They are both HA AddOns, and I have a HA template that these are built upon: https://github.com/johanzander/ha-add-on-template. Mostly useful if one wants a python backend and node frontend, so maybe not that relevant for the energy consumption predictor.

But what do you think, would you be open to create a separate HA AddOn for this? then that could serve as another configurable consumption strategy option...

@pookey
Copy link
Copy Markdown
Contributor Author

pookey commented Mar 12, 2026

. I've been thinking about adding some ML for energy consumption prediction but never prioritized it because the 48h average sensor works good enough for me.

So far, it's been trash and after 8 days of training data, the 'weekly average' is working better for me (the other PR - that's probably good for merge BTW).

I think the ML stuff currently falls into the 'cool experiment, but probably not useful' category!

I hadn't seen Theria) - and I was considering doing something really similar myself! Maybe I need to hop over onto that project too and have a play! Does it support a single temperature zone?

@johanzander
Copy link
Copy Markdown
Owner

The Theria project is in a really early experiemental stage and I ran into real physical constraint wrt. my heating system which made progressing any optimization kind of useless. And there is no or little intelligence yet, it only gathers / visualizes temperature for a set of configurable zones. so im not sure you will find anything useful there, but Im sure with Claude Code you could build something useful on top of it...

@johanzander
Copy link
Copy Markdown
Owner

the other PR - that's probably good for merge BTW - here you mean #33?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants