Skip to content
github-actions edited this page Sep 13, 2026 · 8 revisions

Huawei Solar Energy Management (HSEM)

Home Assistant integration for optimizing Huawei solar batteries, inverters, and EV charging.

HSEM is a modular, secure, and highly configurable Home Assistant integration that automates battery charging/discharging, grid export/import, and adapts to dynamic energy prices, solar forecasts, and EV charging events.


Terminology

  • Battery: Refers to your solar battery (e.g., Huawei battery), not your EV battery.
  • EV Charger: Any wall charger integration for electric vehicles.
  • Grid Import/Export: Import = buying electricity from the grid; Export = selling electricity to the grid.

Quick Start

  1. Remove any previous Huawei Solar Battery Optimization Project integrations.
  2. Install HSEM via HACS or manually.
  3. 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.
  4. Let HSEM run for at least 14 days to collect historical data for optimal performance.
  5. Monitor the Working Mode Sensor for system status and recommendations.

Tip: New user? Enable Read-Only mode to safely observe what HSEM would do before letting it control your system.


Devices

HSEM's entities are split across 7 Home Assistant devices — Controller, Battery & Energy, Hourly Consumption Profile, Financial, Forecast, EV Primary, and EV Secondary — instead of one, so each subsystem can be scoped independently in dashboards, automations, and Areas. See Devices in the sensors reference for the full entity-to-device mapping.

Upgrading from an older HSEM version? A one-time migration moves existing entities to their new device on first startup; dashboards or automations that reference the old single device_id will need to be re-pointed to the new devices. unique_ids and entity history/statistics are preserved automatically.


Features

  • Dynamic Grid Export/Import Management — avoids export at negative prices, forces charging at negative import prices.
  • EV Charging Optimization — smart TOU mode during EV charging, prevents battery drain into EV unless configured.
  • MILP-Optimal Battery Planning — a globally optimal charge/discharge plan is computed every cycle from price, solar, and consumption forecasts; no manual schedules to configure.
  • Excess Battery Export — automatically exports excess battery capacity when profitable, differentiating solar-charged vs grid-charged energy.
  • Consumption Forecasting — legacy weighted-average (1d/3d/7d/14d with IQR outlier detection) or ML ridge regression.
  • Solar Forecast Integration — Solcast PV forecasts for today and tomorrow.
  • Seasonal Mode Switching — Maximize Self Consumption (summer) vs Time-of-Use (winter/spring).
  • Read-Only Mode — full "dry run" for safe testing without sending commands to devices.

Frequently Asked Questions

Is HSEM a replacement for the Huawei Solar Battery Optimization Project?

Yes. HSEM is a full replacement. Remove the old optimization project before installing HSEM.

What does "battery" refer to in this integration?

Always your solar battery (e.g., Huawei battery), not your EV battery.

Does HSEM optimize EV charging?

Yes. When "EV Planned Load" is enabled, HSEM's EV planner computes an optimal charging schedule that charges from excess PV first, then from cheapest grid hours, completing before the configured deadline.

How does HSEM use EV charger data in its calculations?

HSEM uses the EV charger status and power sensors to determine when your EV is charging. Depending on your sensor setup, it either subtracts or adds EV charger power to net consumption to avoid double-counting or underestimation.

Can I allow the battery to discharge while my EV is charging?

Yes, but the setting is permission, not a command. Huawei exposes one global battery discharge limit shared by the house battery and every EV, so by default HSEM forces battery discharge to 0 W whenever an EV is charging or about to be commanded — 100% of the EV's load then comes from the grid. Enabling hsem_ev_charger_force_max_discharge_power lifts that block; hsem_ev_charger_max_discharge_power sets the ceiling. The ceiling must be above 0 W — enabling the permission while the ceiling stays at its 0 default still caps discharge at 0 W (the config flow rejects that combination, and existing entries saved with it log a one-time warning naming both settings — issue #991). The actual discharge rate is still the planner's own solved value for the slot, clamped to that ceiling — enabling the option does not by itself create any discharge.

Should I configure time-of-use (TOU) settings in the Fusion Solar app?

No. HSEM calculates and manages your battery's charge/discharge behavior automatically. Any time slots in the Fusion Solar app will be overwritten.

How does HSEM interact with Fusion Solar time slots?

HSEM calculates and rewrites the time slots in Fusion Solar as needed. You do not need to manually adjust them.

How long does it take for HSEM to optimize my system?

Allow at least 14 days for HSEM to collect enough historical data for accurate optimization.

Is there a "dry run" mode for safe testing?

Yes. Enable Read-Only mode via the switch entity. HSEM will show proposed actions without sending commands.

What if my house consumption sensor includes or excludes EV charger power?

Configure hsem_house_power_includes_ev_charger_power to match your setup. HSEM adjusts net consumption accordingly.

Can I manually override the working mode?

Yes. Use the hsem_force_working_mode select entity. Set to "auto" to return to automatic optimization.

What happens if required sensors are missing or unavailable?

HSEM enters a "Missing Entities Input" state with a clear error description. No changes are made until all sensors are available.


Working Mode Sensor States

Working Mode Description
Time Passed No recommendations — the hour has already passed.
Force Export Charges from grid at negative prices, then exports for profit.
Force Batteries Charge Forces discharge to export excess capacity when profitable.
EV Smart Charging Disables battery discharge when EV charger is active.
Force Batteries Discharge Discharges battery during high-cost periods.
Batteries Charge Solar Charges battery from solar surplus.
Batteries Charge Grid Charges from grid during low/negative import prices.
Batteries Discharge Mode Scheduled battery discharge to minimize grid import.
Batteries Wait Mode Battery idle, waiting for optimal conditions.
Missing Entities Input Missing or misconfigured input sensors.
Read Only Dry run mode — no commands sent to devices.

Working Mode Sensor Logic

Every update cycle, the sensor:

  1. Fetches configuration & sensor states — battery, inverter, grid prices, solar production, EV charger.
  2. Performs pre-calculations — net consumption, battery capacity, weighted consumption forecasts, solar forecast, hourly net consumption.
  3. Applies optimization strategy — determines the best action per hour (Force Export, Charge Solar/Grid, EV Smart Charging, Discharge, Wait).
  4. Applies working mode & TOU periods — sets battery mode and updates TOU periods if not in read-only mode.
  5. Updates state & attributes — exposes hourly calculations, recommendations, and schedule status.

Best Practices

  • Do not configure schedules in the Fusion Solar app. HSEM overwrites them.
  • Ensure all required sensors are available and correctly configured.
  • Allow HSEM to collect 14 days of data before expecting optimal results.

Excess Battery Export

Automatically exports excess battery capacity to the grid when profitable:

  1. Calculate required battery — minimum capacity needed for rest-of-day consumption + safety buffer.
  2. Identify excess — any capacity above requirement is available for export.
  3. Optimize timing — export at peak price hours, respecting max discharge rate.
  4. Differentiate energy source — solar-charged energy exports at any positive price; grid-charged only exports if profit ≥ threshold.
  5. Economic threshold — calculated from battery charging economics:

$$ \alpha = \frac{P \times \left(\frac{L_{pct}}{100}\right)}{2 \times N \times C_u} $$

See Battery Charging Economics for the full derivation.

Example

  • Battery: 100 kWh usable, current 95 kWh
  • Consumption forecast (rest of day): 60 kWh, buffer 10%
  • Required: 70 kWh → Excess: 25 kWh → Export at peak prices

Weighted & Average Consumption Sensors

HSEM supports two prediction modes:

  • Legacy (default): Weighted averages over 1d/3d/7d/14d windows with IQR outlier detection, baseline capping, and reliability scaling.
  • ML (optional): Ridge regression querying the HA recorder directly.

Default Weights (sum must equal 100)

Mode 1 Day 3 Days 7 Days 14 Days
Balanced (default) 25 30 30 15
Conservative 20 30 35 15
Fast-reacting 30 30 25 15

Special Configuration Options

Option Purpose
hsem_ev_charger_force_max_discharge_power Permits (does not force) battery discharge while this EV is charging; without it, discharge is 0 W whenever the EV is active
hsem_ev_charger_max_discharge_power Maximum discharge power (W) for EV charging; must be above 0 W when the permission above is enabled (issue #991)
hsem_force_working_mode Manually override to a specific working mode

Derived from the Huawei Solar Battery Optimization Project

This integration was inspired by and derived from the Huawei Solar Battery Optimization Project.

HSEM Documentation

Quick Reference

Architecture Decision Records

Clone this wiki locally