-
-
Notifications
You must be signed in to change notification settings - Fork 16
Smart Optimization
Warning
The built-in optimizer is actively under development. Expect occasional bugs, unexpected schedules, and behaviour that doesn't match your expectations — especially on less common tariffs, battery configurations, or edge-case scenarios. If the optimizer does something you didn't expect, please report it on Discord or open a GitHub issue with your tariff details and the action plan it generated. Your reports directly improve the algorithm.
Important: Solar forecasting must be configured for accurate scheduling — either install the Solcast Solar HA integration (recommended, PowerSync auto-detects it) or enter your Solcast API key directly in PowerSync's Weather & Solar Forecast settings. Without solar forecast data, the optimizer cannot see when solar will be available and will make purely price-based decisions — which can result in unnecessary grid imports even when solar is available.
PowerSync includes a built-in optimizer that calculates the optimal battery charge/discharge schedule based on electricity prices, solar forecasts, and load patterns. No external tools or additional HACS integrations are required.
Acknowledgement: The optimization approach was inspired by HAEO (Home Assistant Energy Optimizer).
The optimizer finds the cheapest way to run your home over the next 48 hours. It works out:
- When to charge the battery (cheapest grid periods, or from solar)
- When to discharge or export (highest price periods)
- When to leave the battery alone (when it's not worth the round-trip losses)
It runs every 5 minutes, updating the plan as prices and solar forecasts change.
| 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 level | Grid is cheaper than the battery round-trip |
| SELF_CONSUMPTION | Battery operates naturally | Solar hours, moderate prices |
| OFF_GRID | Physically disconnect from grid (Tesla only) | Negative export prices — avoids paying to export |
| Feature | Description |
|---|---|
| 48-Hour Planning | Plans battery actions for the next 48 hours |
| 5-Minute Resolution | Fine-grained control throughout the day |
| Solar Integration | Uses Solcast forecast data for solar predictions |
| Price Integration | Works with Amber, Localvolts, Octopus, Flow Power, EPEX, AEMO, NZ TOU, and custom 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 needed beyond Solcast |
| Off-Grid Curtailment | Automatically islands the Powerwall during negative export prices (opt-in, Tesla only) |
When enabled in Battery Setup > Local Control, the optimizer can physically disconnect the Powerwall from the grid during low-value export periods. This is a stronger curtailment method — the grid connection physically opens, guaranteeing zero export.
The optimizer identifies eligible periods where export value is below 1 c/kWh and projected SOC is near full, then groups them into runs of at least 15 minutes to avoid rapid reconnection cycling. A reconnect window is automatically inserted before any upcoming charge period.
Requirements:
- Tesla Powerwall with completed gateway pairing
- Off-grid curtailment enabled in Battery Setup > Local Control
- Optimizer enabled
Safety gates:
- SOC floor (default 40%) — won't go off-grid below this battery level
- Near-full battery gate — optimizer overlay only schedules off-grid curtailment when projected SOC is at least 98%
- Daily duration cap (default 6 hours)
When the optimizer is enabled, the independent curtailment loop is bypassed to prevent conflicts. If the optimizer is disabled, the independent curtailment loop still works.
Solar continues producing while off-grid — it charges the battery and powers the home. The battery is the sole backup when solar is insufficient, which is why the SOC floor is important.
When using dynamic pricing (Amber, Localvolts, AEMO, Octopus Agile/Flux, Flow Power, EPEX), the optimizer receives price forecasts up to 48 hours ahead. Near-term prices are accurate but far-future forecasts are speculative — a predicted 40c/kWh spike at 2am tomorrow might settle at 22c.
Without adjustment, the optimizer might charge overnight at 20c for a "spike" 18 hours away that never materialises, when cheaper midday solar charging is available in between.
Confidence decay pulls far-future above-average prices toward the average as they get further from now:
| Parameter | Value | Description |
|---|---|---|
| Horizon | 6 hours | Prices within 6h are trusted completely (no decay) |
| Decay rate | 0.15 | How quickly speculative prices are discounted beyond the horizon |
With an average of 21c/kWh and a raw forecast price of 30c/kWh:
| Hours ahead | Decayed price |
|---|---|
| 7h (just outside horizon) | 28.8c |
| 10h | 25.9c |
| 14h | 23.7c |
| 24h | 21.6c (nearly at average) |
The decay is asymmetric — only above-average prices are decayed. Below-average (cheap) prices are preserved because cheap periods are structurally reliable: midday solar dumps and off-peak overnight rates are predictable, not speculative.
This ensures the optimizer can see that midday at 15c is genuinely cheaper than overnight at 18c, and won't pre-charge overnight for a dubious far-future spike when cheaper daytime charging is available.
Note: Confidence decay is not applied to static TOU providers (GloBird, custom tariffs) where prices are known and fixed.
The LP optimizer learns your home's load patterns from the last 7 days of history. If you go on holiday, those 7 days fill with near-zero consumption data. When you return, the LP thinks you barely use any power and under-plans charging for evening loads.
Away Mode solves this in two stages:
Stage 1 — Enable before you leave While the switch is on, the LP continues using normal recent history. As the house sits empty, recent history naturally shows low loads, which biases the LP toward exports rather than reserving battery for non-existent home load. No manual intervention is needed during the trip.
Stage 2 — Disable when you get home Turning the switch off starts a 7-day recovery window. During this time the LP automatically excludes the entire vacation period from its history and backfills with the 7 days before you left — your normal pre-departure patterns. As each new day of real post-return usage accumulates, it slots into the reference window and gradually replaces the pre-vacation data. After 7 days the recovery window closes automatically and normal operation resumes.
If you accidentally toggle the switch on and off within an hour, it is treated as a no-op and no recovery window starts.
switch.power_sync_away_mode
It appears under your PowerSync device in Settings → Devices & Services → PowerSync → Configuration.
- Before leaving: turn the switch ON
- When you get home: turn the switch OFF — recovery starts automatically
- After ~7 days: the switch can be left off; normal history has fully repopulated
While recovering, sensor.power_sync_load_forecast_today exposes these attributes:
| Attribute | Description |
|---|---|
away_in_recovery |
true during the 7-day recovery window |
away_recovery_remaining_hours |
Hours until the window closes automatically |
away_enabled_at |
ISO timestamp of departure |
away_disabled_at |
ISO timestamp of return |
Note: Away mode affects the load forecast only. Solar forecasting uses weather/irradiance data and is unaffected.
By default, the LP optimizer is conservative with stored battery energy. It still exports when the tariff makes export worthwhile, but it also values the battery charge left at the end of the planning horizon. That end-of-horizon value is the optimizer's "insurance" against bad solar forecasts, higher-than-expected overnight prices, or home load arriving after the visible export window.
Profit Maximisation Mode tells the LP to value near-term export revenue more than that future recharge insurance.
| Behaviour | Profit Max OFF | Profit Max ON |
|---|---|---|
| Main goal | Lowest bill with more SOC protection after the forecast horizon | Maximise high-value export opportunities, accepting more recharge risk |
| End-of-horizon battery value | Full terminal SOC weight (1.0) |
Reduced terminal SOC weight (0.3) |
| What that means | Stored energy is treated as valuable, so the LP is reluctant to drain the battery unless the export margin is clearly worth it | Stored energy is treated as easier to replace, so the LP is more willing to discharge into strong export windows |
| Dynamic price confidence | Above-average prices beyond 6 hours are discounted toward the average | Above-average prices are trusted for 12 hours before decay starts |
| Flow Power Happy Hour | Happy Hour export prices are still shown and used, but the LP does not add a special "be full before Happy Hour" target | Adds a pre-window SOC target so the battery aims to be full before the next Happy Hour export window |
| GloBird ZEROHERO | Works from the tariff's export-price schedule; low-value positive export rates can still invite small exports | More willing to spend battery energy in any positive export period, so set non-Super-Export periods to 0c if they should not trigger battery export |
| Grid charging before exports | Charges only when the normal LP economics choose it | More likely to charge ahead of a known export window if grid charging is allowed |
| Risk profile | Lower risk of finishing the day too empty | Higher risk of later grid import if solar underperforms or the next cheap charge period is missed |
When the switch is off, PowerSync uses a terminal SOC weight of 1.0. The LP compares export revenue against the estimated replacement cost of stored energy, including round-trip efficiency losses. This makes the schedule more likely to hold charge for the evening, overnight load, or the next day.
When the switch is on, PowerSync lowers that terminal SOC weight to 0.3. The battery's future replacement value still exists, but it has much less influence. This makes exports more attractive and makes it easier for the LP to spend stored energy during high export periods.
For dynamic providers other than Flow Power, Profit Max also extends the confidence horizon from 6 hours to 12 hours. That means a high export price later today is discounted less aggressively, so the LP is more likely to plan around it instead of assuming it may disappear.
Flow Power is handled differently because Happy Hour is contractual rather than speculative. PowerSync does not apply confidence decay to Flow Power's fixed export window. With Profit Max on, Flow Power sites with a Happy Hour export rate get an additional pre-window SOC target: the LP tries to reach 100% before the next 17:30-19:30 Happy Hour window, with a 15-minute safety buffer. Happy Hour is 45c/kWh in NSW, QLD, and SA, 35c/kWh in VIC, and not available in TAS.
The pre-window SOC target is configurable. In Settings > Devices & Services > PowerSync > Configure > Optimization, set Profit Max full by time as an HH:MM local time. The default is 17:15, which targets full SOC 15 minutes before a 17:30 export window. This setting is also exposed through the optimization settings API used by the mobile app.
GloBird ZEROHERO is not hard-coded like Flow Power. PowerSync follows the tariff schedule it reads from Tesla or the custom tariff configured in PowerSync. For ZEROHERO, set the Super Export window, commonly 6pm-9pm, to the boosted export value from the user's plan, and set export rates outside that window to 0c if those low feed-in periods should not trigger battery export. Profit Max can then help prioritise the special export window, but it will not understand the daily kWh cap by itself.
Profit Max does not remove the optimizer backup reserve or the hardware backup reserve. Those floors still apply.
Profit Max does not allow battery export into negative or zero-value export slots. Solar surplus can still export normally, but intentional battery-to-grid export is only allowed where PowerSync has an allowed export slot, such as a positive sell price, Flow Power Happy Hour, Export Boost, or a joined Octopus Saving Session.
Profit Max does not override demand charge protection, grid charging disabled settings, inverter limits, SOC limits, or force-mode/manual actions.
Turn Profit Max on when you have a strong, predictable export window and you want the battery to prioritise that revenue. Good fits include Flow Power Happy Hour, GloBird ZEROHERO/Super Export when the tariff export rates are shaped correctly, and dynamic tariffs where export spikes are large and reasonably reliable.
Leave Profit Max off when you want a more conservative schedule, when solar forecasts are uncertain, when overnight recharge prices are volatile, when your battery capacity is small relative to evening load, or when you mainly care about avoiding imports rather than maximising export revenue.
With Profit Max off, the LP may decide that keeping SOC for later self-consumption is more valuable than fully emptying into Happy Hour, especially if the next cheap charge period is not obvious inside the horizon.
With Profit Max on, PowerSync treats Happy Hour as the target. If grid charging is allowed, the LP tries to fill the battery before the 17:30 start, blocks charging during the Happy Hour window itself, and is more willing to export stored energy during the high-rate period.
If your export window starts at a different time, update Profit Max full by time to the local time you want the battery to be full. For example, a 18:00 export window usually pairs with a target around 17:45.
For GloBird ZEROHERO, the key setup is the export tariff shape. Use the user's own fact sheet, but a common current setup is:
| Period | Import price | Export price for LP |
|---|---|---|
| Free charge window, e.g. 11:00-14:00 | 0c/kWh if applicable | 0c/kWh |
| Super Export / ZEROHERO, e.g. 18:00-21:00 | Actual import rate | Boosted total export value, commonly 15c/kWh |
| All other periods | Actual import rate | 0c/kWh unless intentionally exporting for the ordinary FiT |
With that shape, the LP sees only the Super Export window as valuable battery-export time. Profit Max then lowers the future-SOC penalty, making the battery more willing to export during that window. If the user leaves the ordinary low FiT as a positive export price outside the window, PowerSync may export outside ZEROHERO because the LP sees those slots as valid export opportunities.
switch.power_sync_profit_max_mode
It appears under your PowerSync device in Settings → Devices & Services → PowerSync → Configuration.
Note: Profit Max only helps static TOU plans when the tariff schedule exposes a meaningful export window. For GloBird ZEROHERO, that means positive export in the Super Export window and 0c export outside it. A flat positive FiT across the day gives the LP permission to export across the day.
The hardware backup reserve is a floor that supported battery hardware enforces independently of the optimizer. This is useful as a safety net — even if the optimizer schedules a full discharge, the hardware should not go below this level.
- Set via the mobile app: Settings > Optimization > Reserve Levels > Hardware Backup Reserve
- This value is written through
power_sync.set_backup_reserveusing thepercentfield - The optimizer's backup reserve is a separate, software-level floor used during schedule planning
- Typically set the hardware reserve a few percent below the optimizer reserve as a safety margin
- ESY Sunhome and SAJ H2/HS2 do not expose backup reserve writes, so this hardware floor is not available on those systems
- Fronius Reserva exposes this when the upstream Fronius Modbus integration provides the Reserva minimum SOC entity
- Neovolt / Bytewatt exposes this when the upstream Neovolt integration provides the default discharging cutoff SOC entity
Solcast Solar forecast is required. Without it, the optimizer cannot see when solar will be available and will make decisions based only on electricity prices — leading to unnecessary grid imports even when the sun is shining.
Configure one of:
- Solcast Solar HA integration (recommended) — install via HACS, PowerSync auto-detects it. No API key needed in PowerSync.
- Solcast API key in PowerSync — enter directly in the Weather & Solar Forecast settings. Requires a free account at toolkit.solcast.com.au.
- Install Solcast Solar (see prerequisites above)
- During initial PowerSync setup, choose your electricity provider and battery system first
- On the Optimization Provider step, select Smart Optimization (Built-in LP)
- Set battery capacity, maximum charge/discharge power, and the optimizer backup reserve
- Complete the battery connection step for your battery system
- In the mobile app: Controls > toggle Enable on the Smart Optimization card
- View the schedule by tapping View Full Schedule
For existing installations, go to Settings > Devices & Services > PowerSync > Configure > Optimization.
Use the mobile app's Automations screen to add Enable Optimizer and Disable Optimizer actions. These are PowerSync automation actions, not Home Assistant Developer Tools services. For Home Assistant YAML automations, call power_sync.force_charge, power_sync.force_discharge, or power_sync.restore_normal as needed, and use the PowerSync app control to change the optimizer state.
PowerSync creates forecast sensors for dashboard visibility:
| Sensor | Description | Unit / Attributes |
|---|---|---|
sensor.power_sync_lp_import_price_forecast |
Average grid import price over the optimizer horizon | $/kWh; attributes include min_price, max_price, price_values
|
sensor.power_sync_lp_export_price_forecast |
Average export/feed-in value over the optimizer horizon | $/kWh; attributes include min_price, max_price, price_values
|
sensor.power_sync_lp_solar_forecast |
Total forecast solar energy over the optimizer horizon | kWh; attributes include peak_kw, forecast_values_kw
|
sensor.power_sync_lp_load_forecast |
Total forecast home load over the optimizer horizon | kWh; attributes include peak_kw, forecast_values_kw
|
sensor.power_sync_load_forecast_today_remaining |
Remaining load forecast for today | kWh; includes Away Mode recovery attributes when active |
sensor.power_sync_load_forecast_tomorrow |
Tomorrow's load forecast | kWh |
Forecast arrays can contain 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 battery level and power |
| Upcoming Actions | List of scheduled charge/discharge periods |