Skip to content

Feature: Native Solar Clipping Buffer#4034

Closed
rholligan wants to merge 55 commits into
springfall2008:mainfrom
rholligan:clipping-buffer-dev
Closed

Feature: Native Solar Clipping Buffer#4034
rholligan wants to merge 55 commits into
springfall2008:mainfrom
rholligan:clipping-buffer-dev

Conversation

@rholligan

@rholligan rholligan commented Jun 9, 2026

Copy link
Copy Markdown

This PR introduces a native clipping buffer to Predbat. It prevents solar energy loss on high-generation days by reserving a dynamic buffer in the battery SoC, specifically targeting periods where PV generation is forecast to exceed inverter AC capacity or DNO export limits.

image

Key Features:

  • Dynamic Buffer Calculation: Computes the required buffer (sensor.predbat_clipping_buffer_kwh) based on the solar forecast area exceeding the "Effective
    Clipping Limit" (choosing the most restrictive hardware or DNO constraint).
  • Grid-Charge Capping: Restricts overnight grid charging to ensure headroom for the calculated buffer.
  • Proactive Risk Management: Includes a two-stage safety system. It uses a risk_threshold (trigger) and a configurable clipping_buffer_safety_margin
    (default 5% of window solar) to protect against un-forecasted cloud-edge spikes.
  • Dynamic Buffer Decay: Reserved space shrinks as the solar peak passes, releasing capacity for evening use.
  • Web UI Integration: Adds a "Clipping Analysis" chart to the Predbat Web UI, displaying PV curves, clipping ceilings, and the decaying buffer.
  • Improved Peak Reporting: Refined the clipping status text to report the actual high-risk generation period (minutes exceeding the limit) rather than the broad protection window, providing clearer information for the user.

Configuration Parameters:

  • clipping_buffer_enable: Master toggle.
  • clipping_buffer_forecast: Selection of forecast model (recommends pv_clearsky).
  • clipping_buffer_safety_margin: Percentage of window solar to reserve as a safety factor (default 0.05).
  • clipping_buffer_risk_threshold: Sensitivity factor to trigger the safety margin logic (default 0.80).
  • clipping_buffer_can_discharge: Discharge behavior (None, Cost Optimal, or Always).
  • clipping_buffer_min_kwh / max_kwh: Manual size constraints.
  • clipping_buffer_limit_override: Manual power threshold override (Watts).

Testing & Documentation:

  • Verified on live 5kW hardware; effectively mitigated 6.28kW solar spikes by holding battery headroom.
  • Includes unit tests in apps/predbat/tests/test_clipping.py.
  • Full feature documentation available in docs/clipping.md.

rholligan added 30 commits May 31, 2026 18:55
Enhance solar forecasting and battery management to mitigate PV clipping:
- Implement dynamic 'clipping buffer' logic to leave room in battery for predicted excess solar
- Add support for Solcast 'Clear Sky' and 'Hist Max' (10%) forecasts for improved clipping detection
- Introduce grid charge capping when clipping is anticipated to maximize self-consumption
- Add Web UI visualization for clipping status and new configuration options
- No additional API usage: leverages existing Solcast data fields and local calculations
- Include specialized unit test for buffer verification and updated documentation
- Fix 'ValueError' in load_ml_component by unpacking all 5 values returned by fetch_pv_forecast
- Initialize 'load_minutes_now' in LoadMLComponent to prevent AttributeError on fetch failure
- Replace undefined 'minutes_to_time' with 'time_abs_str' in plan.py clipping buffer logging
- Restore individual inverter PV/load power sensors in execute.py
- Add future enhancement to todo-list for configurable clipping buffer start/stop times
…is None

- Add None check to clipping_buffer_end before performing <= comparison against charge window end times.
- This prevents a TypeError when a clipping buffer minimum is set but no actual clipping is predicted by the forecast.
…tatus sensors

- Add horizontal 'Inverter Limit' annotation line to the Clipping Analysis chart in the Web UI
- Create 'sensor.predbat_clipping_buffer_kwh' to track the raw calculated buffer size
- Create 'sensor.predbat_clipping_status' to provide a human-readable summary of predicted clipping times and actions
- Add explanatory text detailing the clipping buffer forecast and mitigation actions to the 'Plan textual description' section of the dashboard.
- Add 'clipping_buffer_start_time' and 'clipping_buffer_end_time' config options
- Update optimizer to respect manual time overrides if provided
- Add 'clipping_buffer_manual_time' unit test to verify functionality
- Ensure status messaging handles manual window correctly
- Fix KeyError in web.py by escaping curly braces in ApexCharts annotations
- Update output.py text plan to use user-friendly clipping status (no more N/A)
- Refactor chart threshold to correctly use summed inverter_limit (W) instead of pv_ac_limit
- Update todo-list with advanced hardware and export limit requirements
- Refactor 'render_chart' to support dynamic vertical X-axis annotations
- Add 'Clipping Start' and 'Clipping End' vertical markers to the Clipping Analysis chart
- Expose 'clipping_start' and 'clipping_end' as ISO-formatted attributes on the clipping_status sensor for HA automation access
…raints

- Implement 'Hierarchy of Limits': prioritizes manual overrides > DNO export limits > Physical AC capacity.
- Add 'clipping_buffer_limit_override' (Watts) for manual threshold control.
- Support multi-inverter systems by summing AC and export limits across all units.
- Refactor chart threshold line to dynamically reflect the active constraint (labeled in legend).
- Improve hardware topology support: correctly handle DC-coupled (Hybrid) vs AC-coupled PV clipping.
- Expose 'clipping_mode' attribute to sensor.predbat_clipping_status for visibility into the active limit.
- Update documentation to reflect the new Advanced Model.
…ensor

- Expose 'clipping_remaining_today' and 'clipping_tomorrow' via plan.py for use in sensors/UI.
- Add 'Actual SOC' to the Clipping Analysis chart to easily compare vs 'Target SOC'.
- Add Vertical markers for the start and end of the calculated clipping window to the chart.
…odes)

- Implement 'Always' discharge mode: actively schedule battery 'purge' exports to reach clipping target before window starts.
- Implement 'Cost Optimal' discharge mode: penalize clipped solar in the metric, allowing the optimizer to decide if early export is profitable.
- Fix: Properly integrate hierarchical clipping limit into core minute-by-minute energy simulation.
- Update documentation and status messaging to reflect active mitigation capabilities.
- Set 'Cost Optimal' as the default mode for clipping buffer discharge.
- Expand documentation to explain the financial logic behind 'Cost Optimal' mode.
- Clarify the hierarchy of limits used to determine the clipping threshold.
- Use 'self.midnight' (local time) instead of 'self.midnight_utc' for chart annotations to fix visual drift.
- Merge SOC lines into a single secondary kWh axis for consistency.
- Fix scaling error in DNO export limit calculation (removed redundant division by 60000).
- Improve simulation logic to proactively cap grid charging targets by the clipping buffer size.
- Ensure 'clipping_limit' is correctly prioritized over the legacy 'pv_ac_limit' in the prediction model.
- Fix 'time_string_to_stamp' NameError by adding missing import to plan.py.
- Fix scaling bug in clipping simulation by multiplying limit by step.
- Fix 'inverter_hybrid' AttributeError in Prediction initialization.
- Re-enable legacy solar clipping fallback for non-hybrid systems when buffer logic is inactive.
- Modify test_infra.py to check for 'PREDBAT_PLOT' environment variable before calling plt.show().
- Ensure plots are still saved as PNG files but don't block execution.
- This prevents the agent from hanging while waiting for user interaction on headless/automated test cycles.
- Update the 'Dash' tab textual plan to include the active clipping constraint (e.g., Inverter vs DNO).
- Indicate in the plan if 'Morning Purge' (active mitigation) is enabled and which mode is being used.
- Enhance the 'clipping_status' sensor state message to explicitly mention the restricting hardware/grid limit.
- Ensure normal solar/grid charging is capped at target SOC to reserve the hole.
- Allow only excess (clipped) solar to overflow and fill the reserved buffer.
- Add default 08:00-16:00 window if buffer is required but no spikes are forecast.
- This ensures visual markers always appear and mitigation logic always triggers.
- Add safety checks to web.py to prevent 500 error when solar forecasts return None.
- Refactor Clipping chart axes to a single unified kWh primary axis for better readability.
- Clean up clipping status messages by removing redundant and ambiguous date strings.
- Fix missing comma in ApexCharts JS annotation rendering.
- Resolved all 'not enough values to unpack' ValueErrors by standardizing the 12-tuple simulation return across all threads and modules.
- Refactored chart axes to perfectly align grid lines (unified min/max/ticks).
- Fixed 'AttributeError: WebInterface object has no attribute midnight' by adding the property to ComponentBase.
- Cleaned up human-readable date formatting for the clipping window status.
- Added 'clipping_mitigated' and 'clipping_remaining' metrics for advanced dashboarding.
- Confirmed stable test infrastructure for headless automated testing.
rholligan added 25 commits June 1, 2026 12:17
…rgin

Fixes grid_export_limit calculation to use power instead of SOC limits. Adds 5% safety margin to auto clipping buffer when risk is detected. Fixes JS syntax error in Web UI clipping chart (None -> null). Adds detailed debug logging to is_running.
@rholligan rholligan closed this Jun 9, 2026
@rholligan rholligan changed the title Feature: Native Solar Clipping Buffer (Resolves #1206) Feature: Native Solar Clipping Buffer Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant