Skip to content

15 min interval#233

Merged
MaStr merged 12 commits intomainfrom
15-min-interval
Jan 8, 2026
Merged

15 min interval#233
MaStr merged 12 commits intomainfrom
15-min-interval

Conversation

@MaStr
Copy link
Owner

@MaStr MaStr commented Nov 27, 2025

Closes #185

@MaStr MaStr requested a review from Copilot November 27, 2025 21:15
@MaStr MaStr self-assigned this Nov 27, 2025
@MaStr MaStr added the enhancement New feature or request label Nov 27, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py module 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

@MaStr
Copy link
Owner Author

MaStr commented Nov 27, 2025

Next Step:

Setup a test configuration with:

  • MQTT based inverter config and 15 minute interval
  • MQTT inverter script, that follows the consumption forecast and the requests from batcontrol (adjust SOC).
  • influx DB + Grafana
  • Telegraf for transporting batcontrol status
  • showcase everything and verify functionality

@MaStr
Copy link
Owner Author

MaStr commented Jan 5, 2026

Rebased on 0.5.7
Test with Grafana and everything works fine.

Testing 60 Minute config now locally

@MaStr MaStr marked this pull request as ready for review January 8, 2026 09:07
@MaStr MaStr requested a review from Copilot January 8, 2026 09:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 33 out of 35 changed files in this pull request and generated 3 comments.

Comment on lines +149 to +166
# 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
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Copy link
Contributor

Copilot AI commented Jan 8, 2026

@MaStr I've opened a new pull request, #245, to work on those changes. Once the pull request is ready, I'll request review from you.

MaStr and others added 2 commits January 8, 2026 10:16
…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>
@MaStr MaStr merged commit 1c1ddc0 into main Jan 8, 2026
10 checks passed
@MaStr MaStr deleted the 15-min-interval branch January 8, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for quarter-hourly spot electricity prices

3 participants