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
- 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.)
- Auto-Full on negative prices — automatically charges EV at full power when electricity is free
- 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
- 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
- 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 — 6-view dashboard with price charts, energy flow, savings, and accuracy
- Live-configurable — all thresholds and settings editable from the dashboard without restart
hsem.create_dashboardservice — install or update the bundled Lovelace dashboard from Developer Tools- 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).
- Set up battery schedules in HSEM (do not use Fusion Solar app for scheduling).
- 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 (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.
- 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 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, battery schedules, 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
- Troubleshooting Guide — Diagnose and fix common problems
- All Documentation — Full index of all documentation files