Skip to content

Smart Optimization

bolagnaise edited this page May 6, 2026 · 36 revisions

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).

How It Works

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 Model

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

Features

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)

Off-Grid Curtailment in the Optimizer (v2.12.0+)

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.


Confidence Decay (Dynamic Pricing Only)

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

Example

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)

Asymmetric Decay

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.

Away Mode (v2.12.157+)

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.

How to Use

switch.power_sync_away_mode

It appears under your PowerSync device in Settings → Devices & Services → PowerSync → Configuration.

  1. Before leaving: turn the switch ON
  2. When you get home: turn the switch OFF — recovery starts automatically
  3. After ~7 days: the switch can be left off; normal history has fully repopulated

Recovery Status

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.


Profit Maximisation Mode (v2.12.158+)

By default, the LP optimizer keeps some charge in reserve for post-horizon needs — if recharging overnight looks expensive, it won't drain the battery completely during Happy Hour in case the solar forecast is wrong. This is conservative and reduces the risk of expensive overnight grid imports.

Profit Maximisation Mode tells the LP to value today's export revenue more than future recharge insurance. It does this by adjusting two internal settings:

Setting Default Profit Max
Terminal value weight 1.0 0.3 — end-of-horizon SOC valued at 30% of replacement cost
Confidence decay horizon 6 hours 12 hours — far-future Happy Hour spikes trusted longer

Who this is for: users on dynamic tariffs with strong, predictable export windows — Flow Power Happy Hour (45c/kWh 17:30–19:30), Amber/Octopus spike periods, or any tariff where evening export prices reliably exceed daytime import prices by a wide margin.

Trade-off: the LP will discharge more aggressively toward the end of an export window, which means if solar underperforms the next day or prices are higher than forecast overnight, you may import more from the grid than the conservative mode would have required.

switch.power_sync_profit_max_mode

It appears under your PowerSync device in Settings → Devices & Services → PowerSync → Configuration.

Note: This switch has near-zero effect on flat-rate TOU tariffs (GloBird, custom tariffs) where terminal valuation isn't the binding constraint. It is intended for dynamic pricing providers.


Hardware Backup Reserve (v2.5.0+)

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_reserve using the percent field
  • 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
  • Neovolt / Bytewatt exposes this when the upstream Neovolt integration provides the default discharging cutoff SOC entity

Enable/Disable Optimizer

Prerequisites

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.

Manual

  1. Install Solcast Solar (see prerequisites above)
  2. Go to Settings > Devices & Services > PowerSync > Configure
  3. Select Smart Optimization (Built-in LP) as your optimization provider
  4. Set your backup reserve percentage
  5. In the mobile app: Controls > toggle Enable on the Smart Optimization card
  6. View the schedule by tapping View Full Schedule

Via PowerSync Automations

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.

Forecast Sensors

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).

Understanding the Schedule

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

Smart Optimization summary — current & next action 24-hour action plan TOU schedule and 48-period price forecast

Clone this wiki locally