-
-
Notifications
You must be signed in to change notification settings - Fork 16
Smart Optimization
bolagnaise edited this page Feb 9, 2026
·
36 revisions
PowerSync includes a built-in linear programming (LP) optimizer that calculates the optimal battery charge/discharge schedule based on electricity prices, solar forecasts, and load patterns. No external dependencies required.
Acknowledgement: The optimization approach was inspired by HAEO (Home Assistant Energy Optimizer).
The optimizer uses scipy's HiGHS LP solver to solve a cost minimization problem over a 48-hour horizon:
Minimize: Sum (import_price[t] * grid_import[t] - export_price[t] * grid_export[t]) * dt
Subject to:
- Power balance: solar[t] + grid_import[t] + battery_discharge[t]
= load[t] + grid_export[t] + battery_charge[t]
- SOC dynamics: soc[t] = soc_0 + Sum(charge*eff - discharge/eff) * dt / capacity
- SOC limits: backup_reserve <= soc[t] <= 1.0
- Rate limits: charge <= max_charge_kw, discharge <= max_discharge_kw
The optimizer runs directly inside PowerSync:
- Collects price, solar, and load forecasts from configured providers
- Overlays EV charging plans into the load forecast (if EV integration is enabled)
- Solves the LP problem in a background thread (typically < 1 second)
- Maps the solution to battery actions (charge, discharge, idle, self-consumption)
- Executes battery commands via the appropriate control method
If scipy is unavailable, a greedy fallback optimizer runs instead.
| Action | What It Does | When It's Used |
|---|---|---|
| CHARGE | Force charge battery from grid | Cheap import periods (overnight off-peak) |
| EXPORT | Force discharge battery to grid | Expensive export periods (evening peak) |
| IDLE | Hold battery at current SOC (sets backup reserve) | Grid is cheaper than battery round-trip |
| SELF_CONSUMPTION | Battery operates naturally | Solar hours, moderate prices |
| Feature | Description |
|---|---|
| 48-Hour Optimization | Plans battery actions for the next 48 hours |
| 5-Minute Resolution | 576 optimization intervals for fine-grained control |
| Solar Integration | Uses Solcast forecast data for solar predictions |
| Price Integration | Works with Amber, Octopus, Flow Power, AEMO, and TOU tariffs |
| EV Load Awareness | Incorporates planned EV charging into the load forecast |
| Daily Cost Tracking | Actual cost (midnight to now) + predicted cost (now to midnight) |
| Zero Setup | Built-in — no external integrations or HACS repos needed |
- Go to Settings > Devices & Services > PowerSync > Configure
- Select Smart Optimization (Built-in LP) as your optimization provider
- Set your backup reserve percentage
- In the mobile app: Controls > toggle Enable on the Smart Optimization card
- View the schedule by tapping View Full Schedule
+-----------------------------------------------------------+
| Data Sources |
| - Amber/Octopus/Flow Power/AEMO prices |
| - Solcast solar forecasts |
| - Historical load estimation |
| - EV charging plan overlay |
+-----------------------------------------------------------+
|
v
+-----------------------------------------------------------+
| Built-in LP Optimizer (scipy linprog / HiGHS) |
| Collects forecasts -> LP solve -> Optimal schedule |
| Fallback: Greedy algorithm if scipy unavailable |
+-----------------------------------------------------------+
|
v
+-----------------------------------------------------------+
| Execution Layer |
| Schedule -> Battery commands |
| - Tesla: TOU tariff trick |
| - FoxESS: Work mode + remote control registers |
| - Sigenergy/Sungrow: Modbus commands |
+-----------------------------------------------------------+
PowerSync creates forecast sensors for dashboard visibility:
| Sensor | Description | Unit |
|---|---|---|
sensor.powersync_price_import_forecast |
Grid import price forecast | $/kWh |
sensor.powersync_price_export_forecast |
Feed-in/export price forecast | $/kWh |
sensor.powersync_solar_forecast |
Solar PV generation forecast | W |
sensor.powersync_load_forecast |
Home consumption forecast | W |
Each sensor includes a forecast attribute with up to 576 data points (48 hours at 5-minute intervals).
The optimization screen in the mobile app shows:
| Section | Description |
|---|---|
| Status | Whether optimization is active and the current mode |
| Current/Next Action | What the battery is doing now and what's coming next |
| Predicted Cost | Estimated electricity cost for the day |
| Savings | How much you're saving vs no optimization |
| 48-Hour Chart | Visual timeline of SOC and power |
| Upcoming Actions | List of scheduled charge/discharge periods |