Skip to content

Fix SolarEdge battery charge/discharge energy always reporting 0#173096

Draft
it-rec wants to merge 1 commit into
home-assistant:devfrom
it-rec:solaredge-battery-energy-from-power
Draft

Fix SolarEdge battery charge/discharge energy always reporting 0#173096
it-rec wants to merge 1 commit into
home-assistant:devfrom
it-rec:solaredge-battery-energy-from-power

Conversation

@it-rec

@it-rec it-rec commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Proposed change

The SolarEdge battery sensors storage_charge_energy / storage_discharge_energy
(and their per-battery counterparts) were always reporting 0.

Root cause: SolarEdge frequently returns lifeTimeEnergyCharged /
lifeTimeEnergyDischarged as 0 in the storageData response, even while the
battery is actively charging or discharging. The integration computed the energy
as a delta of those lifetime counters, so it stayed at 0. The power
telemetry, in contrast, is reliably populated.

The energy is now derived by trapezoidal integration of the power
telemetry
(positive = charging, negative = discharging).

Following review feedback (@joostlek), this device/service-specific parsing lives
in the aiosolaredge library rather than in the integration:

Important

This is a draft until aiosolaredge 1.1.0 (containing
Solarlibs/aiosolaredge#132) is released. The bump to aiosolaredge==1.1.0 is
already included here, so CI will go green once that release is on PyPI.

Verified against a live site: the power integral gave ~4.84 kWh charged vs.
~4.47 kWh from SoC × capacity (~3% = charging losses), while the lifetime
counters stayed at 0 the entire time.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass.
  • There is no commented out code in this PR.
  • I have followed the development checklist.
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

@home-assistant

home-assistant Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Hey there @frenck, @bdraco, @tronikos, mind taking a look at this pull request as it has been labeled with an integration (solaredge) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of solaredge can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign solaredge Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR changes the SolarEdge battery energy calculation from using unreliable lifeTimeEnergyCharged/lifeTimeEnergyDischarged lifetime counters (which SolarEdge frequently reports as 0) to integrating energy from the reliably-populated power telemetry using the trapezoidal rule.

Changes:

  • Added _battery_energy_from_power() function in coordinator.py that performs trapezoidal integration of power telemetry to derive charge/discharge energy in Wh.
  • Replaced the delta-based lifetime counter approach in SolarEdgeStorageDataService.async_update_data with the new power integration approach.
  • Updated all test fixtures, assertions, and snapshots to reflect the new energy calculation method.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
homeassistant/components/solaredge/coordinator.py Added _battery_energy_from_power() helper and replaced lifetime counter delta logic with power integration.
tests/components/solaredge/test_coordinator.py Added comprehensive parametrized unit tests for _battery_energy_from_power().
tests/components/solaredge/test_sensor.py Updated inline mock data and assertion values to match the new integration approach.
tests/components/solaredge/fixtures/storage_data.json Expanded fixture with more telemetry points and zeroed lifetime counters to simulate the real-world API behavior.
tests/components/solaredge/snapshots/test_sensor.ambr Updated snapshot expected values.

@it-rec
it-rec force-pushed the solaredge-battery-energy-from-power branch from d22db39 to 8fc4c88 Compare June 5, 2026 11:57

@joostlek joostlek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we shouldn't integrate the information in the integration level. Instead users can use the integral integration for that instead of doing it ourselves. Integrations should connect with the service/device and not make abstractions on top of that

@home-assistant

home-assistant Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

SolarEdge frequently reports lifeTimeEnergyCharged/lifeTimeEnergyDischarged as
0 in the storageData response even while the battery is actively cycling, which
left the storage_charge_energy/storage_discharge_energy sensors stuck at 0.

The energy is instead derived by integrating the reliably-populated power
telemetry. Following review feedback, this device-specific parsing now lives in
the aiosolaredge library (get_parsed_storage_data, returning typed StorageData)
rather than in the integration, so the coordinator just consumes the parsed
result.

Fixes home-assistant#169964
Copilot AI review requested due to automatic review settings June 6, 2026 11:16
@it-rec
it-rec force-pushed the solaredge-battery-energy-from-power branch from 8fc4c88 to 727df52 Compare June 6, 2026 11:16
@it-rec

it-rec commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

Reworked per @joostlek's feedback that device/service-specific code belongs in the library rather than in HA.

The power-integration logic has been moved out of the integration into aiosolaredge:

  • Library PR: feat: add parsed battery storage data with power integration Solarlibs/aiosolaredge#132 — adds StorageData / BatteryStorageData models and SolarEdge.get_parsed_storage_data(), with the parsing + power integration unit-tested there.
  • Here: the coordinator now just calls get_parsed_storage_data() and consumes the typed result. The integration-side _battery_energy_from_power helper and its parametrized test are gone, and aiosolaredge is bumped to 1.1.0.

Keeping this in draft until aiosolaredge 1.1.0 is released so CI can install the dependency; happy to adjust the library API if you'd prefer a different shape before it's tagged.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@it-rec
it-rec marked this pull request as ready for review June 8, 2026 17:09
@home-assistant
home-assistant Bot requested a review from joostlek June 8, 2026 17:09
@it-rec
it-rec marked this pull request as draft June 8, 2026 17:09
@tronikos
tronikos removed their request for review June 17, 2026 00:50
@tronikos tronikos removed their assignment Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Solar Edge Battery informartion does not update

6 participants