You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4e169b1
Browse filesBrowse the repository at this point in the historyBrowse files
feat: configure ML retraining interval in apps.yaml (#5433)
Keep the two-hour default and support daily retraining with a 1-48 hour range.
Preserve startup training and prediction cadence.
Refs #5072.
Co-authored-by: Anonymous <anonymous@example.invalid>
self.log("ML Component: Initial training is required, delaying until component has started")
757
758
returnTrue
758
759
elifshould_train:
759
-
self.log("ML Component: Starting fine-tune training (2h interval), model age is {} hours".format(retrain_age_seconds/3600.0))
760
+
self.log("ML Component: Starting fine-tune training ({:g}h interval), model age is {} hours".format(self.ml_retrain_interval_seconds/3600.0, retrain_age_seconds/3600.0))
760
761
elifshould_fetch:
761
762
# If not training either then no need to print anything
762
763
self.log("ML Component: No training needed, model age is {} hours".format(dp2(retrain_age_seconds/3600.0)))
Copy file name to clipboardExpand all lines: docs/components.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1797,7 +1797,7 @@ This provides more accurate load predictions than simple averaging, especially f
1797
1797
- Optionally incorporates PV generation and temperature forecast data
1798
1798
- Trains a multi-layer neural network on your historical patterns
1799
1799
- Makes autoregressive predictions for 48 hours ahead in 5-minute intervals
1800
-
- Fine-tunes periodically (every 2 hours) to adapt to changing patterns
1800
+
- Fine-tunes periodically (every 2 hours by default) to adapt to changing patterns
1801
1801
- Validates predictions and falls back gracefully if accuracy is poor
1802
1802
- Publishes predictions to `sensor.predbat_load_ml_forecast`
1803
1803
@@ -1813,6 +1813,7 @@ For a detailed explanation of how the neural network works and comprehensive con
1813
1813
| `load_ml_source` | Boolean | No | false | `load_ml_source` | Set to `true` to use ML predictions in Predbat battery planning |
1814
1814
| `load_ml_max_days_history` | Integer | No | 28 | `load_ml_max_days_history` | Maximum days of load history to fetch from HA on each poll (bounded by HA recorder retention) |
1815
1815
| `load_ml_database_days` | Integer | No | 90 | `load_ml_database_days` | Days of history to accumulate in the on-disk database (`predbat_ml_history.npz`); set to 0 to disable the database |
1816
+
| `load_ml_retrain_interval_hours` | Integer | No | 2 | `load_ml_retrain_interval_hours` | Hours between training cycles (1–48); use 24 for daily retraining. Predictions still update every 30 minutes |
1816
1817
1817
1818
Note: **load_today**, **pv_today** and **car_charging_energy** `apps.yaml` configuration items are also used, but these should already be set in Predbat.
1818
1819
@@ -1831,6 +1832,9 @@ predbat:
1831
1832
# Optional: days of history to accumulate on disk for training (default 90)
1832
1833
# load_ml_database_days: 90
1833
1834
1835
+
# Optional: hours between training cycles (default 2, range 1-48)
1836
+
# load_ml_retrain_interval_hours: 24
1837
+
1834
1838
# Optional but recommended: enable temperature forecasts
Copy file name to clipboardExpand all lines: docs/load-ml.md
+11-2Lines changed: 11 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ The ML Load Prediction component uses a lightweight multi-layer perceptron (MLP)
30
30
- Deep neural network with 3 hidden layers [512, 256, 64 neurons]
31
31
- Optimised with He initialisation and AdamW weight decay for robust training
32
32
- Automatically trains on historical data (requires at least 1 day, recommended 7+ days; fetches up to `load_ml_max_days_history` days from HA and accumulates up to `load_ml_database_days` days in the on-disk database)
33
-
- Fine-tunes periodically (every 2 hours) using full dataset to adapt to changing patterns
33
+
- Fine-tunes periodically (every 2 hours by default) using full dataset to adapt to changing patterns
34
34
- Time-weighted training prioritizes recent data while learning from historical patterns
35
35
- Model persists across restarts
36
36
- Falls back gracefully if predictions are unreliable
@@ -207,12 +207,21 @@ predbat:
207
207
208
208
# Optional: Number of days of history to accumulate in the on-disk database (default: 90)
209
209
# load_ml_database_days: 90
210
+
211
+
# Optional: Retrain once a day instead of every 2 hours
212
+
# load_ml_retrain_interval_hours: 24
210
213
```
211
214
212
215
**Configuration Parameter Details:**
213
216
214
217
-`load_ml_enable`: Enables the ML component (required), defaults to false.
215
218
-`load_ml_source`: When `true`, Predbat uses ML predictions for battery planning. Set to `false` (the default) to test predictions without affecting battery control
219
+
-`load_ml_retrain_interval_hours`: Hours between training cycles, measured from the model's last training time
220
+
-**Default**: 2 hours
221
+
-**Range**: Whole hours from 1 to 48; out-of-range values are clamped to these limits because models become stale after 48 hours
222
+
-**Example**: Set to `24` for daily retraining to reduce how often training uses CPU
223
+
-**Unchanged behaviour**: Initial training still runs after startup once enough data is available; predictions still update every 30 minutes
224
+
-**Apply changes**: Restart Predbat after editing `apps.yaml`; no additional Home Assistant entity is created
216
225
-`load_ml_max_days_history`: Optional maximum days of historical data to fetch from Home Assistant on each poll (every 30 minutes)
217
226
-**Default**: 28 days
218
227
-**Minimum**: 7 days
@@ -383,7 +392,7 @@ Good predictions require:
383
392
4. **Energy Rate Data**: Automatically included - helps model learn consumption patterns based on time-of-use tariffs
384
393
5. **PV Generation Data**: If you have solar panels, include `pv_today` sensor for better correlation
385
394
6. **Clean Data**: Avoid gaps or incorrect readings in historical data
386
-
7. **Recent Training**: Model retrains every 2 hours using full dataset with time-weighted sampling to adapt to changing patterns
395
+
7. **Recent Training**: Model retrains every `load_ml_retrain_interval_hours` (default 2 hours) using full dataset with time-weighted sampling to adapt to changing patterns
0 commit comments