Huawei Solar Energy Management (HSEM) is a modular, secure, and highly configurable Home Assistant integration for optimizing Huawei solar batteries, inverters, and related energy devices. HSEM automates battery charging/discharging, grid export/import, and adapts to dynamic energy prices, solar forecasts, and EV charging events.
- MILP-based planner — global optimal charge/discharge scheduling via linear programming (HiGHS solver)
- 8-term cost function — rigorous mathematical formulation with formal invariants
- Multiple candidate strategies — baseline, passive, aggressive, partial-SoC, and MILP-optimal plans
- Time-discounted candidate selection — prefers near-term savings over far-future gains
- Dynamic self-learning discharge floor — reserves enough energy to bridge the house to the next solar surplus or cheap grid window, with self-correcting safety margin
- Temperature-adaptive charge rate learning — 7 temperature buckets track actual charge power at p90, adapting to cold-weather limitations
- Battery capacity auto-detection — learns usable capacity from BMS kWh-remaining readings in the 15-85 % SoC range
- Cycle cost accounting — wear-and-tear costs factored into every charge/discharge decision
- Battery target SoC by deadline (issue #1109) — optional: build an extra reserve towards a target SoC by a daily time (e.g. 100 % by 17:00) using only PV that would otherwise be exported. Never buys extra grid energy and never changes the grid charging or discharge the normal plan needs
- Battery export minimum price floor (issue #752) — optional per-slot hard floor below which intentional battery-to-grid export is forbidden (the optimizer still decides above the floor)
- Grid overcurrent protection — respects main fuse rating, caps total grid draw
- Weekday/weekend consumption profiling — separate EWMA load profiles for workdays and weekends improve prediction accuracy
- Solar forecast accuracy auto-correction — per-hour learned factors (4-day rolling) + intra-hour residual correction (2h decay)
- Configurable solar confidence — plans against a user-selectable percentile (10-90 %) of historical forecast accuracy
- 48-hour PV horizon — Solcast today + tomorrow integration
- PV curtailment detection — detects when the inverter throttles solar production
- MILP EV co-optimisation — EV charging scheduled alongside battery in one LP solve
- Session-aware EV demand — treats actively-charging EV as certain demand for the next 2 hours
- Embedded OCPP 1.6 server — direct EV charger control via WebSocket (Easee, Zaptec, Wallbox, etc.), one server per EV (second EV optional, separate port)
- Auto-Full on negative prices — automatically charges EV at full power when electricity is free
- Cheap-price charge — charges an EV immediately at full power whenever the import price is at or below a threshold you choose
- Minimum SoC charge — charges an EV immediately at full power while it is below a minimum SoC you set, whatever the price
- Dual EV support — independent configuration and planning for two EVs
- Export income / import cost / net balance sensors — monetary, cumulative, HA Energy dashboard compatible
- Savings tracker — actual vs missed savings with 90-day rolling log
- Performance sensors — how much of the achievable savings the last 24 hours captured, the actual benefit and the missed opportunity, scored against perfect hindsight, whether it was lost in battery dispatch or in PV surplus handling, and how well EV charging was timed (plus 7- and 30-day figures)
- Prediction accuracy scorecard — 7-day and 30-day SoC MAE, solar MAPE, action mix
- Daily plan-vs-actual tracking — compares planned and actual energy flows
- Read-only / monitoring mode — observe what HSEM would do before enabling control
- Degraded mode — safely degrades when critical entities are missing
- Availability transition logging — logs each configured input once when it becomes unavailable and once when it recovers
- Hardware write verification — confirms inverter accepted every command
- Data quality diagnostics — reports missing price/PV data per horizon day
- Quick setup wizard — auto-detects Huawei Solar, Solcast, and price entities
- Bundled Lovelace dashboard — single-section dashboard with price charts, energy flow, savings, and accuracy
- Live-configurable — all thresholds and settings editable from the dashboard without restart
hsem.create_dashboardservice — creates or updates the bundled Lovelace dashboard automatically- Bilingual — English and Danish translations
- Remove any previous Huawei Solar Battery Optimization Project integrations.
- Install HSEM via Home Assistant's custom integrations or manually.
- Configure your sensors for solar battery, inverter, grid, and EV charger (if present) — do not use the Fusion Solar app for scheduling; HSEM's planner drives charge/discharge decisions automatically.
- Let HSEM run for at least 14 days to collect historical data for optimal performance.
- Monitor the Working Mode Sensor for system status and recommendations.
Tip: If you are a new user and want to safely observe how HSEM would control your battery system without making any changes, enable the Read-Only mode. This acts as a "dry run" and allows you to review all proposed configuration changes before they are applied.
For detailed documentation, see the HSEM Wiki or the docs/ directory.
To use this package, you need the following integrations:
- Huawei Solar integration by wlcrs VERSION 1.5.0a1 REQUIRED
- Solcast integration by oziee
- Any electricity price integration (Strømligning, Open Spot Forecast, Energi Data Service, Nordpool, Amber Electric, etc.)
The following integrations work alongside HSEM but are not required:
- Huawei Solar PEES package by JensenNick
- Smoothing Analytics Sensors by woopstar
- EV Smart Charging by jonasbkarlsson
The Huawei Solar integration by wlcrs provides sensor.inverter_active_power_control and sensor.batteries_rated_capacity but they are disabled by default. To use these entities, go to the device settings, select the inverter or batteries device and show hidden/disabled entities. Find the sensor.inverter_active_power_control and sensor.batteries_rated_capacity and enable them.
If a Huawei EMMA controls your batteries, the Huawei Solar integration only accepts TOU and grid export limit writes on the EMMA device. In the huawei_solar config step, select the EMMA as Huawei TOU Controller Device, and pick the EMMA's working-mode (ESS Control Mode), excess-PV-in-TOU, and TOU-periods entities (the EMMA TOU-periods sensor is disabled by default — enable it first). Leave Huawei Inverter Active Power Control Sensor empty: Huawei Solar has no such sensor for EMMA, so HSEM writes the export limit without read-back. EMMA grid export limits in watts (the negative-price block and a configured export cap) need Huawei Solar 2.1.6 or newer; older versions fail them with a P_max error, and HSEM logs a warning telling you to update. Leave the controller empty for direct LUNA2000 control. See docs/huawei_entities.md.
HSEM needs Home Assistant 2026.10 or newer (hacs.json declares the minimum, and the Marketplace and HACS only offer releases your Home Assistant can run).
Home Assistant 2026.11 ships HACS inside core as the Marketplace. HSEM is not in the catalog yet, so add it from its repository link:
- In Home Assistant, go to Settings -> Marketplace.
- Click the three dots in the top-right corner, and select Add from link.
- Paste this repository URL and select Integration as the type:
https://github.com/woopstar/hsem - Open Huawei Solar Energy Management in the Marketplace and click Install. Turn on Pre-release first if you want the 7.0.0 betas.
- A first install loads without a restart. Add the integration via the Home Assistant integrations page and configure your settings.
Updates and removals of an already loaded integration still need a restart; the Marketplace creates a repair with a restart button.
Upgrading from HACS: existing HACS installs migrate to the Marketplace automatically on the first start after the Home Assistant 2026.11 update. Nothing needs to be reinstalled.
- In HACS, go to Integrations.
- Click the three dots in the top-right corner, and select Custom repositories.
- Add this repository URL and select Integration as the category:
https://github.com/woopstar/hsem - Click Add.
- The integration will now appear in HACS under the Integrations section. Click Install.
- Restart Home Assistant.
- Copy the
hsemfolder to yourcustom_componentsfolder in your Home Assistant configuration. - Restart Home Assistant.
- Add the integration via the Home Assistant integrations page and configure your settings.
- In Home Assistant, go to Settings -> Devices & Services.
- Find the HSEM integration, click the menu icon (three dots), and select Delete.
- Restart Home Assistant.
- In Settings -> Marketplace, open Huawei Solar Energy Management, click the menu icon (three dots), and select Remove.
- Restart Home Assistant again.
- In HACS, go to Integrations, find HSEM, click the menu icon (three dots), and select Remove.
- Restart Home Assistant again.
- Delete the
custom_components/hsemfolder from your Home Assistant configuration directory. - Restart Home Assistant.
After removal, verify that no HSEM entities remain in Settings -> Devices & Services -> Entities.
Full documentation is available on the HSEM Wiki and in the docs/ directory:
- Home — User-facing overview: features, FAQ, working modes, excess export, and more
- Architecture Overview — System context, layered architecture, module map
- Planner Specification — Normative planner invariants, solar correction, dynamic floor, session EV
- Planner Technical Guide — How the planner works with worked examples, solar correction, dynamic floor
- Cost Function Math — Complete mathematical formulation of the 8-term cost function
- Sensors Reference — Complete entity reference: ~40 sensors, switches, numbers, and more
- Config Flow Reference — Setup wizard steps including quick setup and OCPP
- EV Charge Plan Setup — EV planned load and OCPP charger configuration
- Dashboard Setup — Bundled Lovelace dashboard with 6 views
- Consumption Prediction — ML ridge regression with DOW + DOY + temperature features
- MILP Optimization — LP formulation, EV co-optimisation, session-aware demand
- Forecast Accuracy Tracking — Solar correction and prediction accuracy
- Planner Backtest Harness — Replay recorded production cycles offline against the planner spec
- Backtest Runbook — Step-by-step: collect a live corpus and actuals, then replay them
- Troubleshooting Guide — Diagnose and fix common problems
- All Documentation — Full index of all documentation files