Battery Overcharge/Undercharge Configuration Guide

Alex Johnson
-
Battery Overcharge/Undercharge Configuration Guide

In this comprehensive guide, we'll delve into how to add overcharge and undercharge settings to your battery systems, enhancing their performance and economic efficiency. This feature allows batteries to operate beyond their typical range when it's economically beneficial, offering a balance between battery longevity and cost optimization. This article provides a detailed explanation of implementing soft limits for battery charging, allowing for operation beyond the typical range under specific economic conditions. This enhances flexibility and cost-effectiveness in battery management. By understanding and implementing these strategies, you can optimize your battery usage for various scenarios.

Understanding Overcharge and Undercharge

To begin, let's clarify what overcharge and undercharge mean in the context of battery operation. Overcharging occurs when a battery is charged beyond its maximum capacity, while undercharging refers to discharging a battery below its minimum safe level. Both scenarios can lead to battery degradation and reduced lifespan, making it crucial to manage these conditions effectively. Traditionally, batteries have fixed operating limits defined by minimum and maximum charge percentages. However, there are situations where exceeding these limits, with appropriate safeguards, can be economically advantageous. The concept of soft limits addresses this by allowing batteries to operate outside their normal range when justified by cost considerations.

The Problem: Fixed Battery Limits

Previously, battery systems operated with hard limits set by min_charge_percentage and max_charge_percentage, typically 10% and 90%, respectively. This rigid framework lacked the flexibility to accommodate economic incentives for operating outside these bounds. There was no mechanism to express a preference for operating within a specific range while allowing excursions beyond it under extreme economic conditions, albeit with a cost penalty. This inflexibility meant that potential cost savings during peak demand or grid imbalances could not be realized, as the system could not intelligently decide to overcharge or undercharge the battery based on economic signals. The absence of soft limits prevented the system from taking advantage of opportunities where exceeding normal operating ranges could yield significant financial benefits.

The Solution: Introducing Soft Limits

The solution involves introducing soft limits within the existing hard limits, adding a layer of control that enables more nuanced battery management. We retain the min_charge_percentage and max_charge_percentage as absolute hard limits, ensuring battery safety. Alongside these, we introduce new parameters:

  • soft_min_charge_percentage: The normal minimum operating level, set between the absolute minimum and maximum.
  • soft_max_charge_percentage: The normal maximum operating level, also within the absolute limits.
  • undercharge_cost: The cost in $/kWh for energy drawn below the soft_min level.
  • overcharge_cost: The cost in $/kWh for energy added above the soft_max level.

Soft limits provide a flexible boundary for battery operation. These limits define the preferred range for battery charge levels, allowing for deviations when economically justified. By introducing undercharge_cost and overcharge_cost parameters, the system can intelligently weigh the economic benefits of exceeding soft limits against the associated costs. This approach enables the optimizer to make informed decisions about battery usage, balancing economic gains with potential battery degradation. The key advantage of soft limits is the ability to optimize battery usage based on real-time economic conditions, enhancing the overall efficiency and profitability of the energy system.

Example Configuration

Consider a scenario with absolute limits set at 5% and 95% (min_charge_percentage / max_charge_percentage). The normal operating range is defined between 10% and 90% (soft_min_charge_percentage / soft_max_charge_percentage). With these settings, the optimizer can utilize the 5-10% and 90-95% ranges when economically beneficial, incurring the specified overcharge or undercharge costs. This configuration allows the battery to participate in grid services or arbitrage energy prices, even if it means briefly operating outside the normal range. The flexibility provided by soft limits ensures that the battery system can adapt to changing economic conditions, maximizing its value and contribution to the energy system. This example illustrates how soft limits can be tailored to specific operational needs and economic incentives.

Implementation Details: Technical Changes

To implement this solution, several technical changes are required within the system's architecture. These changes involve modifications to the data model, schema, configuration flow validation, and translation updates.

Model Changes (battery.py)

The primary changes are within the Battery class in the custom_components/haeo/model/battery.py file:

  1. New Parameters: We add the following new parameters to the Battery.__init__() method:

    • soft_min_charge_percentage: float | None = None
    • soft_max_charge_percentage: float | None = None
    • undercharge_cost: Sequence[float] | float | None = None
    • overcharge_cost: Sequence[float] | float | None = None

    These parameters support sequences for time-varying values, accommodating forecasts and dynamic pricing.

  2. Slack Variables: We create slack variables (overcharge_slack[t] and undercharge_slack[t]) to represent the energy stored above soft_max_charge_percentage and below soft_min_charge_percentage at time t. These variables are only created when soft limits and associated costs are set. The bounds for these variables are set with a lowBound of 0 and an upBound determined by the battery's capacity and the soft/hard percentage ranges.

  3. Energy Variable Bounds: The energy variable bounds remain unchanged, ensuring that the absolute hard limits are enforced:

    • lowBound = capacity * min_charge_percentage / 100
    • upBound = capacity * max_charge_percentage / 100

    These bounds serve as the ultimate constraints, preventing the battery from operating outside the safe limits.

  4. Soft Limit Constraints: We add soft limit constraints in the Battery.constraints() method, which are activated only if configured:

    • Overcharge:
      • soft_max_energy = capacity * soft_max_charge_percentage / 100
      • Constraint: energy[t] <= soft_max_energy + overcharge_slack[t]
      • The slack variable allows the energy to exceed the soft maximum, up to the hard maximum.
    • Undercharge:
      • soft_min_energy = capacity * soft_min_charge_percentage / 100
      • Constraint: energy[t] >= soft_min_energy - undercharge_slack[t]
      • The slack variable allows the energy to fall below the soft minimum, down to the hard minimum.
  5. Cost Penalties: We add cost penalties in the Battery.cost() method:

    • Overcharge cost: sum(overcharge_slack[t] * overcharge_cost[t] for t in periods)
    • Undercharge cost: sum(undercharge_slack[t] * undercharge_cost[t] for t in periods)
    • The units are in dollars, calculated by multiplying energy (kWh) by cost ($/kWh).
    • Scalar costs are broadcast to sequences if needed.

Schema Changes (battery.py)

Modifications to the schema in custom_components/haeo/elements/battery.py include:

  1. Configuration Constants: Adding new configuration constants:

    • CONF_SOFT_MIN_CHARGE_PERCENTAGE
    • CONF_SOFT_MAX_CHARGE_PERCENTAGE
    • CONF_UNDERCHARGE_COST
    • CONF_OVERCHARGE_COST
  2. TypedDict Updates: Updating the BatteryConfigSchema TypedDict:

    • Adding soft_min_charge_percentage: NotRequired[BatterySOCFieldSchema]
    • Adding soft_max_charge_percentage: NotRequired[BatterySOCFieldSchema]
    • Adding undercharge_cost: NotRequired[PriceFieldSchema | PriceSensorsFieldSchema]
    • Adding overcharge_cost: NotRequired[PriceFieldSchema | PriceSensorsFieldSchema]

    This supports both constant values and sensor sequences for dynamic cost inputs.

  3. Data TypedDict Updates: Updating the BatteryConfigData TypedDict with corresponding fields.

Configuration Flow Validation (element.py)

Validation is added in custom_components/haeo/flows/element.py to ensure paired configurations and valid ranges:

  • If soft_max_charge_percentage is set, overcharge_cost must also be set, and vice versa.
  • If soft_min_charge_percentage is set, undercharge_cost must also be set, and vice versa.
  • Validating range ordering: min_charge_percentage <= soft_min_charge_percentage < soft_max_charge_percentage <= max_charge_percentage
  • Ensuring all percentages are within the range [0, 100].

Translation Updates (en.json)

User-facing text for the new fields is added in custom_components/haeo/translations/en.json:

  • soft_min_charge_percentage:

You may also like