Skip to content

Add state_class: measurement for battery level sensors (+ per-entity overrides) to enable statistics#55

Merged
derolli1976 merged 2 commits into
mainfrom
feature/state_class_for_battery_entities
Sep 2, 2025
Merged

Add state_class: measurement for battery level sensors (+ per-entity overrides) to enable statistics#55
derolli1976 merged 2 commits into
mainfrom
feature/state_class_for_battery_entities

Conversation

@derolli1976
Copy link
Copy Markdown
Owner

Description

This PR classifies the battery level entities as measurement so they are recorded by Home Assistant’s Recorder and become available in Long-Term Statistics and Statistics cards.

  • Adds a small STATE_CLASS_OVERRIDES map to target specific entities (e.g., sensor.energy_battery_charge_level and unit-specific variants).
  • Applies overrides in the entity factory so SoC (%) is exposed with state_class=measurement.
  • No entity IDs or unique_ids are changed. No configuration changes required.

Motivation and Context

Users want to track daily min/max/avg battery state of charge to assess charge/discharge windows and decide on potential capacity upgrades. Without a state_class, these sensors aren’t included in Recorder and can’t power Statistics cards.

Closes #54

How Has This Been Tested?

Local test in Home Assistant:

  1. Update to this version, reload the integration (or restart HA).
  2. Verify in Developer Tools → States that the battery SoC entity now shows state_class: measurement and the correct device_class/unit.
  3. Add a Statistics card for the SoC sensor; confirm min/max/mean values appear after new samples are collected.
  4. Confirm no unit changes occur over time and values remain numeric.

Verified no migration or unique_id changes; history builds from installation time onward.
Confirmed behavior when the entity is excluded from Recorder (expected: no stats until exclusion removed).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@derolli1976 derolli1976 self-assigned this Sep 2, 2025
@derolli1976 derolli1976 merged commit 5b4014f into main Sep 2, 2025
11 checks passed
@derolli1976 derolli1976 deleted the feature/state_class_for_battery_entities branch October 9, 2025 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] State Class for Inverter Battery and Inverter Battery Absolute Entities.

1 participant