Skip to content

Comments

Default logic: pre-charge overflow when recharge demand exceeds one grid-charging slot (with expert feature flag and price-proximity guard)#272

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/update-logic-charge-rate-calculation
Draft

Default logic: pre-charge overflow when recharge demand exceeds one grid-charging slot (with expert feature flag and price-proximity guard)#272
Copilot wants to merge 5 commits intomainfrom
copilot/update-logic-charge-rate-calculation

Conversation

Copy link
Contributor

Copilot AI commented Feb 22, 2026

Wenn die nachzuladende Energie größer ist als in einem Slot mit max_grid_charge_rate erreichbar, soll vor dem Preis-Wendepunkt mit einem Überhang begonnen werden, während der Hauptanteil weiter am Wendepunkt geladen wird. Zusätzlich wird ein konservativer Ladeverlust als Expert-Parameter berücksichtigt.

  • Logic: overflow-first charging before turning point

    • Extended recharge planning in DefaultLogic to detect the first lower-price turning point and compute slot capacity from:
      • max_grid_charge_rate
      • interval length (15/60 min)
      • configurable loss factor
    • If recharge requires multiple slots, logic now schedules only the overhang before turning point; single-slot cases remain unchanged.
    • Added targeted helper path (__get_recharge_overhang_energy) to keep existing decision flow intact.
  • Logic: price-proximity guard for early overhang charging

    • Early overhang charging (before reaching the price bottom) is now only allowed if the current price is close enough to the next lowest future price.
    • Guard condition:
      • abs(current_price - next_lowest_price) <= min_price_difference / 2
    • If this condition is not met, early overhang charging is skipped (to avoid charging too early while price is still expensive), and the full recharge amount remains.
  • Config: expert loss assumption

    • Added battery_control_expert.max_charge_loss_factor (default 0.1) to model worst-case charging losses in slot planning.
    • Wired this expert value into default logic via Logic.create_logic(...).
  • Config: expert feature flag

    • Added battery_control_expert.enable_precharge_overhang (default false) as a feature flag.
    • When enabled, overhang pre-charging before the turning point is active.
    • When disabled, behavior falls back to the previous full recharge amount calculation for the current slot.
    • Updated tests so the overhang-positive scenario explicitly enables the flag.
  • Parameter plumbing for slot-capacity calculation

    • Added max_grid_charge_rate to CalculationParameters.
    • Passed inverter value from core into logic parameter construction.
  • Focused behavior coverage

    • Added a unit test verifying multi-slot scenarios charge only the pre-turning-point overhang, leaving bulk energy for turning-point charging.
    • Added a unit test verifying disabling the feature flag restores the non-overhang behavior.
    • Added a unit test verifying early overhang charging is skipped when current price is too far from the next lowest price.
# core.py -> logic parameter wiring
calc_parameters = CalculationParameters(
    self.max_charging_from_grid_limit,
    self.min_price_difference,
    self.min_price_difference_rel,
    self.get_max_capacity(),
    self.inverter.max_grid_charge_rate,
)

# default.py -> feature-flagged and price-guarded multi-slot overhang handling
if self.enable_precharge_overhang:
    usable_charge_per_slot = max_grid_charge_rate * slot_hours * (1.0 - self.max_charge_loss_factor)
    required_slots = int(np.ceil(recharge_energy / usable_charge_per_slot))
    if required_slots > 1:
        next_lowest_price = min(prices[h] for h in range(1, len(prices)))
        if abs(current_price - next_lowest_price) <= min_price_difference / 2:
            recharge_energy = max(recharge_energy - usable_charge_per_slot, 0.0)

[!WARNING]

Original prompt

Evaluiere wie die Logik im Logic/default geändert werden muss, dass das:

Wenn: nachzuladende Energie > als mit Max Grid charge Rate möglich ist

Dann ermittelt wird wie viele ladeslots nötig sind um nachzuladen, wenn mehr als 1 nötig ist, muss bereits vor dem Wendepunkt der Preise angefangen werden. Also nicht mehr mit n+1 > current, sondern n+2 . Und das man dann anfängt den "Überhang" jetzt zu laden
. Das Gros soll noch immer am Wendepunkt geladen werden. Beachte hier, dass wir als Möglichste Maximalwerte an kWh ladeverluste annehmen müssen. Ladeverluste (0.1 Faktor) bitte als expert Werte in die Konfiguration setzen.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: MaStr <1036501+MaStr@users.noreply.github.com>
Copilot AI changed the title [WIP] Update charge logic for energy loading requirements Default logic: pre-charge overflow when recharge demand exceeds one grid-charging slot Feb 22, 2026
Copilot AI requested a review from MaStr February 22, 2026 11:44
@MaStr MaStr requested review from Copilot and removed request for Copilot February 22, 2026 11:49
@MaStr
Copy link
Owner

MaStr commented Feb 22, 2026

@copilot please add a feature flag on the functionality. Add it to the batcontrol.expert settings

Co-authored-by: MaStr <1036501+MaStr@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 22, 2026

@copilot please add a feature flag on the functionality. Add it to the batcontrol.expert settings

Implemented in 48447a1. Added battery_control_expert.enable_precharge_overhang (default true) as a feature flag, wired it through logic factory, and gated the overhang precharge behavior in DefaultLogic. Also added a focused test that verifies disabling the flag restores full recharge behavior.

Copilot AI changed the title Default logic: pre-charge overflow when recharge demand exceeds one grid-charging slot Default logic: pre-charge overflow when recharge demand exceeds one grid-charging slot (with expert feature flag) Feb 22, 2026
@MaStr MaStr added enhancement New feature or request ConfigChange Needs to be reviewed for HA Addon labels Feb 22, 2026
@MaStr
Copy link
Owner

MaStr commented Feb 22, 2026

@copilot Change the battery_control_expert.enable_precharge_overhang default to false

Co-authored-by: MaStr <1036501+MaStr@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 22, 2026

@copilot Change the battery_control_expert.enable_precharge_overhang default to false

Done in aa320b0. battery_control_expert.enable_precharge_overhang now defaults to false in config and logic; I also updated the overhang-positive test to explicitly enable the flag.

@MaStr
Copy link
Owner

MaStr commented Feb 22, 2026

@copilot I need to change the logic a bit.
It is only allowed to do this kind of recharging (before reaching the price bottom) if the current how is within min_price_difference/2 range to the next lowest price. This should ensure, that sometimes we skipp to charge earlier, because it is still pricy.

Co-authored-by: MaStr <1036501+MaStr@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 22, 2026

@copilot I need to change the logic a bit.
It is only allowed to do this kind of recharging (before reaching the price bottom) if the current how is within min_price_difference/2 range to the next low...

Implemented in 16c07dd. Early overhang charging now only applies when abs(current_price - next_lowest_price) <= min_price_difference / 2; otherwise it is skipped and the full recharge amount remains. I also added a focused test for the “too expensive now” case and adjusted the positive test to use an in-range current price.

Copilot AI changed the title Default logic: pre-charge overflow when recharge demand exceeds one grid-charging slot (with expert feature flag) Default logic: pre-charge overflow when recharge demand exceeds one grid-charging slot (with expert feature flag and price-proximity guard) Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ConfigChange Needs to be reviewed for HA Addon enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants