Conversation
There was a problem hiding this comment.
Pull request overview
This pull request implements support for 15-minute time intervals throughout the batcontrol system, addressing issue #185. The implementation adds flexible time resolution support (15 or 60 minutes) for forecasts, dynamic tariffs, and battery control logic, enabling more granular control and optimization.
Key Changes:
- Added
interval_utils.pymodule with upsampling/downsampling functions for converting between 15-minute and hourly resolutions - Implemented baseclass architecture for automatic resolution handling in solar, consumption, and tariff forecasts
- Updated all provider implementations to support native resolutions with automatic conversion
- Modified core logic to handle interval factorization based on configurable time resolution
Reviewed changes
Copilot reviewed 31 out of 33 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
src/batcontrol/interval_utils.py |
New utility module providing upsampling (linear/constant) and downsampling functions for interval conversions |
src/batcontrol/forecastsolar/baseclass.py |
Added resolution handling with _convert_resolution() and _shift_to_current_interval() methods |
src/batcontrol/forecastconsumption/baseclass.py |
New baseclass implementing resolution conversion for consumption forecasts |
src/batcontrol/dynamictariff/baseclass.py |
Enhanced baseclass with price replication and averaging for resolution conversion |
src/batcontrol/core.py |
Updated interval factorization logic to work with configurable 15/60-minute resolutions |
src/batcontrol/mqtt_api.py |
Modified to handle both 15 and 60-minute intervals for MQTT publishing |
src/batcontrol/logic/default.py |
Updated charge rate calculation to account for 15-minute intervals |
config/batcontrol_config_dummy.yaml |
Added time_resolution_minutes configuration parameter |
src/batcontrol/__main__.py |
Added --one-shot and --config command-line arguments |
tests/batcontrol/test_interval_utils.py |
Comprehensive tests for interval conversion functions |
tests/batcontrol/forecastsolar/test_baseclass_alignment.py |
Tests for solar forecast resolution conversion and interval alignment |
tests/batcontrol/forecastconsumption/test_baseclass.py |
Tests for consumption forecast baseclass functionality |
tests/batcontrol/dynamictariff/test_baseclass.py |
Tests for tariff baseclass with resolution handling |
| Provider implementations | Updated EVCC, Tibber, Energyforecast, FCSolar, SolarPrognose, EvccSolar to support target_resolution parameter |
| Consumption providers | Updated HomeAssistant and CSV providers to use new baseclass with resolution support |
|
Next Step: Setup a test configuration with:
|
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Rebased on 0.5.7 Testing 60 Minute config now locally |
src/batcontrol/logic/default.py
Outdated
| # Calculate remaining time in current interval | ||
| current_minute = calc_timestamp.minute | ||
| current_second = calc_timestamp.second | ||
|
|
||
| if self.interval_minutes == 15: | ||
| # Find start of current 15-min interval and calculate remaining time | ||
| current_interval_start = (current_minute // 15) * 15 | ||
| remaining_minutes = (current_interval_start + 15 | ||
| - current_minute - current_second / 60) | ||
| else: # 60 minutes | ||
| remaining_minutes = 60 - current_minute - current_second / 60 | ||
|
|
||
| remaining_time = remaining_minutes / 60 # Convert to hours | ||
|
|
||
| # Ensure minimum remaining time to avoid division by very small numbers | ||
| remaining_time = max(remaining_time, MIN_REMAINING_TIME_HOURS) # At least 1 minute | ||
|
|
||
| charge_rate = required_recharge_energy / remaining_time |
There was a problem hiding this comment.
Division by zero protection: if both current_minute and current_second are 0 at the start of an interval, and interval_minutes is also somehow 0 (though validated), this could theoretically cause issues. More critically, when the remaining time calculation yields a very small number near the end of an interval, this could cause extremely high charge rates. The MIN_REMAINING_TIME_HOURS constant helps but should be documented more clearly about why 1 minute is the minimum.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
…arge rate calculation (#245) * Add comprehensive documentation for division by zero protection * Fix comment to accurately reference where interval_minutes is validated Co-authored-by: MaStr <1036501+MaStr@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MaStr <1036501+MaStr@users.noreply.github.com> Co-authored-by: Matthias Strubel <matthias.strubel@aod-rpg.de>
Closes #185