Feature: Native Solar Clipping Buffer#4034
Closed
rholligan wants to merge 55 commits into
Closed
Conversation
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.
…ng and only plot when buffer is active
…ated spike buffer
…gs in window optimizer logic
…nd improved discharge math
…dding safety checks
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Key Features:
Clipping Limit" (choosing the most restrictive hardware or DNO constraint).
(default 5% of window solar) to protect against un-forecasted cloud-edge spikes.
Configuration Parameters:
Testing & Documentation: