Skip to content

Home Assistant setup

Solar AI Optimizer is an external application that connects to Home Assistant over REST and WebSocket. For fail-safe and software updates from HA itself, install the HACS custom integration (Home Assistant 2026.7+).

Install from oraad/solar-ai-integration — not this repository (this repo is the Solar app / HA Apps add-on only).

A legacy YAML fail-safe package still exists for older setups; prefer the integration and disable the package when both would run.

Choose your deployment path:

Path When to use
Supervisor app HAOS or Supervised — recommended for most HA users
Docker + hass_ingress Standalone container on the same network as HA
Standalone Docker Direct :8000 access; optional local admin login
HA custom integration Fail-safe + Updates in HA (pairs with any of the above)

After connecting, complete entity mapping. For fail-safe, use the HACS custom integration (do not run the legacy YAML package alongside it).


Connecting Solar to Home Assistant

Deployment How Solar authenticates to HA
HAOS add-on SUPERVISOR_TOKEN automatically — nothing to paste
Standalone (interactive) Settings → Solar controls Home Assistant → IndieAuth
Standalone (headless) Env HA_BASE_URL + HA_TOKEN (long-lived access token)

The HACS integration talks to Solar with a pairing code or Supervisor discovery — not an HA long-lived token. Scripts may still use env API_TOKEN for Solar's own HTTP API.

Headless HA_TOKEN (optional)

  1. In Home Assistant, open Profile → Security → Long-Lived Access Tokens.
  2. Create a token and set HA_BASE_URL / HA_TOKEN in the container environment.
  3. Prefer IndieAuth for interactive setups; revoke unused tokens periodically.

For the HA app, leave credentials empty — Supervisor injects the token.

IndieAuth troubleshooting

If the browser authorize step succeeds but the callback page shows Failed:

  1. Check Solar logs for HA token exchange failed: — the HTTP status and body are the source of truth.
  2. 403 / ha_forbidden: Solar’s host IP is likely in HA config/ip_bans.yaml. Stop Solar, clear the ban, restart Home Assistant Core, then retry IndieAuth. (Authorize uses your browser IP; token exchange uses Solar’s IP.)
  3. ha_unreachable: The HA URL in Settings must be reachable from the Solar container/host (not only from your browser). Prefer a LAN IP over homeassistant.local if DNS differs inside Docker.
  4. ha_ssl_error: Disable Verify SSL in Settings for self-signed HA certificates, then start IndieAuth again.
  5. token_exchange_failed: Often an expired/spent code or client mismatch — close the popup and click Connect with Home Assistant once more.

If the callback shows Connected but Settings still reports auth_invalid / “Invalid access token”:

  1. Click Retry connection — Solar reloads IndieAuth credentials from disk and rebuilds the HA WebSocket client (a full container restart is not required for a successful re-auth).
  2. If Retry still fails after a fresh IndieAuth, stop Solar, clear any IP bans, restart HA Core, then start Solar and connect again (see IP ban recovery).

Supervisor app

Open your Home Assistant instance and show the add app repository dialog.

  1. Settings → Apps → App store → ⋮ → Custom repositories → add:
    https://github.com/oraad/solar-ai-optimizer
    
  2. Install Solar AI Optimizer and start it.
  3. Open the ingress panel from the HA sidebar.
  4. In Settings, configure latitude/longitude, PV arrays, and inverter entities.

The app pulls ghcr.io/oraad/solar-ai-optimizer from GHCR (version tag from the app manifest); no build on the HA host.

Settings, telemetry, and learned models persist on the Supervisor /data volume. run.sh forces DATA_DIR=/data on app startup (overriding the image default /app/data) so UI config survives restarts and upgrades.

App options (Supervisor UI) map to environment variables via run.sh:

App option Environment variable
prerelease_updates ADDON_PRERELEASE_UPDATES
shadow_mode SHADOW_MODE
log_level LOG_LEVEL
ha_verify_ssl HA_VERIFY_SSL
mcp_token MCP_TOKEN
api_token (legacy options.json only) API_TOKEN

Ingress is trusted automatically when running as a Supervisor app (SUPERVISOR_TOKEN); set TRUST_INGRESS_HEADERS=true for external Docker/Proxmox deployments. This enables proxied user identity and X-Frame-Options: SAMEORIGIN for the sidebar panel. See Roles and access for admin vs viewer behavior.

App updates

  • The HA app store manifest promotes stable releases only. Pre-release builds publish to GHCR but do not change the store version until a stable GA release.
  • Update via Settings → Apps → Solar AI Optimizer → Update when Supervisor shows an update. The update dialog shows release notes from the app store CHANGELOG.md (kept in sync with the repo root changelog).
  • The in-app Software updates section is hidden on HA App installs (updates are managed by Supervisor).
  • Optional Pre-release updates (app configuration): when enabled and the app is restarted, the optimizer checks for newer beta/RC builds and logs when one is available. Update manually via Settings → Apps when Supervisor offers a matching version. Users already on a beta build stay on it until a stable GA release or manual reinstall.

Docker with hass_ingress

Use when the optimizer runs as a separate container but HA users should open it from the HA sidebar.

1. Optimizer container

Example docker-compose.yml service on the same Docker network as Home Assistant:

services:
  solar-ai-optimizer:
    image: ghcr.io/oraad/solar-ai-optimizer:latest
    container_name: solar-ai-optimizer
    restart: unless-stopped
    environment:
      SHADOW_MODE: "true"
      TRUST_INGRESS_HEADERS: "true"
      DATA_DIR: /app/data
      DATABASE_URL: sqlite+aiosqlite:////app/data/solar.db
      # Optional direct admin access to :8000 (keep port unpublished if ingress-only):
      # LOCAL_ADMIN_USERNAME: admin
      # LOCAL_ADMIN_PASSWORD_HASH: ...
      # SESSION_SECRET: ...
    volumes:
      - solar-data:/app/data
    networks:
      - homeassistant
    # Do not publish 8000 publicly when using ingress-only access.

networks:
  homeassistant:
    external: true   # or shared with your HA stack

volumes:
  solar-data:

Configure HA URL/token in Settings after first start, or set HA_BASE_URL / HA_TOKEN in environment.

2. Home Assistant ingress block

Add to configuration.yaml:

ingress:
  solar_ai:
    title: Solar AI
    icon: mdi:solar-power-variant
    require_admin: false
    work_mode: ingress
    url: http://solar-ai-optimizer:8000
    headers:
      X-Remote-User-Id: $user_id
      X-Remote-User-Name: $username
      X-Remote-User-Display-Name: $user_name

Reload ingress: Developer tools → YAML → INGRESS.

Requires TRUST_INGRESS_HEADERS=true on the optimizer so HA can embed the panel in the sidebar (X-Frame-Options: SAMEORIGIN).

Full auth patterns: Roles and access.


Standalone Docker

docker compose up -d --build

Open http://localhost:8000 directly. Optionally enable local admin login via LOCAL_ADMIN_PASSWORD_HASH and SESSION_SECRET (see Configuration).

Set HA URL and token in Settings — no ingress wrapper required.


Home Assistant packages

Packages let you split YAML configuration into files under config/packages/.

Enable packages in configuration.yaml

If not already present:

homeassistant:
  packages: !include_dir_named packages

Restart Home Assistant or reload core configuration after adding this block.

Fail-safe package (legacy — do not use with HACS)

Prefer the HACS integration fail-safe. Solar no longer writes an HA heartbeat helper; liveness for the integration is heartbeat_last_pulse on GET /api/health.

The example YAML package under examples/home-assistant/packages/solar-optimizer-failsafe.yaml is deprecated. If you still run it, disable it when using HACS so grid charge is not applied twice. It will not receive Solar heartbeat entity updates on current Solar builds.


Inverter entity discovery

The optimizer uses a vendor-agnostic entity map in Settings → Inverter entity map. Logical capabilities (battery SOC, PV power, grid charge enable, etc.) map to your HA entity IDs. When HA is connected, fields offer autocomplete from live entities.

Use Developer tools → States to find entity IDs. The tables below are starting points — naming varies by integration version and device model.

Read sensors

Capability Deye / Sunsynk (MSA) Victron (Venus / HA) Growatt
pv_power sensor.*_pv*_power or sensor.*_solar_power sensor.*_pv_power sensor.*_pv_power
load_power sensor.*_load_power sensor.*_ac_consumption sensor.*_load_power
battery_soc sensor.*_battery_soc sensor.*_soc sensor.*_battery_soc
battery_power sensor.*_battery_power sensor.*_battery_power sensor.*_battery_power
grid_power sensor.*_grid_power sensor.*_grid_power sensor.*_grid_power
grid_present binary_sensor.*_grid_connected binary_sensor.*_ac_input binary_sensor.*_grid_status
battery_temp sensor.*_battery_temperature sensor.*_battery_temperature sensor.*_battery_temp

Write controls

Capability Deye / Sunsynk (MSA) Victron Growatt
grid_charge_enable switch.*_grid_charge integration-specific switch.*_grid_charge
max_grid_charge_current number.*_grid_charge_current number.*_max_charge_current number.*_max_grid_charge

Load shedding

Each tier accepts multiple switch entities (pool pump + heater, AC power switch, etc.). Use switch.* or input_boolean.* entities for power control.

Companion entities (climate, select, fan, etc.) on the same Home Assistant device are discovered automatically and snapshotted when shedding; they are restored when the tier comes back. Devices that were off before shedding are never turned on by restore.

Snapshots are captured once per shed episode and held until restore, clear, or config prune — repeat shed cycles while the switch is already off do not overwrite the pre-shed state. Capture may run while the HA write watchdog is stale; the OFF write still waits until HA is fresh.

Per-tier options:

Field Purpose
restore_enabled Restore on SOC when soc >= restore_above_soc
restore_on_grid Restore when grid is present (if global flag is on)
state_entities Optional override map of power entity → companion entity IDs

Omit a key in state_entities to autodiscover companions; set [] for switch-only.

Configure in the dashboard Load shedding tab. Grid-charge write entities are not required for shedding-only deployments (use the shed-only preset on that tab). You still need inverter read sensors for battery SOC and grid presence.

See Dashboard user guide → Load-shedding tiers.

Outdoor temperature (optional)

Settings → Forecast → Temperature → Outdoor sensor entity — any sensor.* reporting °C for temperature-aware load forecasting.


Verification checklist

  1. Dashboard top bar shows HA connected (not offline).
  2. Overview status cards show live SOC, PV, and load values.
  3. Forecast tab shows a 48-hour chart (requires latitude/longitude in Settings).
  4. Settings entity fields autocomplete when typing (requires valid token).
  5. Fail-safe (HACS): Healthy binary sensor stays on while Solar is cycling; see integration docs.

Troubleshooting

Symptom What to check
HA offline URL reachable from container; token valid; SSL setting matches HA
Empty status cards Read entities mapped correctly; entities not unavailable in HA
No forecast Latitude/longitude set; not 0,0
Writes fail Write entities mapped; shadow mode off; HA reachable
Ingress 401/403 TRUST_INGRESS_HEADERS=true; ingress URL matches container hostname (this is Solar UI auth, not HA Core)
HA WebSocket 403 See IP ban recovery below

IP ban recovery

Home Assistant can ban Solar’s source IP after failed WebSocket/token attempts (config/ip_bans.yaml, http.login_attempts_threshold). Solar reconnects with backoff and pauses on repeated auth/ban failures, but a bad token can still re-ban the host if you clear the ban while Solar keeps retrying.

Recovery sequence:

  1. Stop Solar so it cannot re-create the ban.
  2. Remove Solar’s IP(s) from HA config/ip_bans.yaml (or delete the file). Docker bridge / gateway addresses may differ from the LAN IP you expect — clear all matching entries.
  3. Restart Home Assistant Core so the ban list reloads; confirm the file stays empty for about a minute.
  4. Mint a new long-lived access token for HA_TOKEN (or re-run IndieAuth in Solar Settings). Revoke the old token.
  5. Start Solar. In Settings → Solar controls Home Assistant, use Retry connection to reload credentials and close an open circuit (IndieAuth success also rebuilds the live HA client automatically).
  6. In Solar logs, distinguish auth_invalid / WebSocket auth failed (bad token) from HTTP 403 (ban or proxy).

Optional test-only: set http.ip_ban_enabled: false, restart HA, confirm Solar connects, then re-enable bans.

Who needs which URL / token

Consumer What to configure
Human (ingress UI) Nothing — HA sidebar ingress
HACS integration → Solar Supervisor discovery on HAOS, or LAN URL + pairing code (standalone)
Solar engine → HA (add-on) Nothing — Supervisor token
Solar engine → HA (standalone) IndieAuth in Settings (preferred) or HA_TOKEN env (headless)