Skip to content

battery_plus not created when source entity's registry unit_of_measurement is null at startup (deep-sleep devices) #5089

Description

@bitzer-git

Checklist

  • I have restarted Home Assistant after the HACS or manual install.
  • I have read the FAQ's.
  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of any previous issues..

Battery Notes Version

3.6.3

Describe the issue

For an entity-associated battery note on a Shelly Gen1 (H&T, SHHT-1) battery sensor, the battery_plus sensor is unreliably created depending on the state of the entity registry's unit_of_measurement field at Home Assistant startup — not the entity's live state.

Debug log at the time of failure:

sensor.shellyht_15_battery is not a battery entity device_class: battery unit_of_measurement: None
At the same moment, Developer Tools > States confirmed the entity's live attributes were:

state_class: measurement
unit_of_measurement: '%'
device_class: battery

I traced this to the entity registry (core.entity_registry) itself: unit_of_measurement for this entity flips between "%" and null across restarts (confirmed via registry snapshots with timestamps), apparently because this Gen1 (block-protocol) Shelly sensor reports its unit dynamically based on live device data rather than as a fixed value, and the underlying deep-sleep device hasn't reported yet at the exact moment the Shelly platform re-registers the entity on startup.

Manually patching unit_of_measurement to "%" in core.entity_registry and restarting Home Assistant reliably produces a working battery_plus — for exactly one session. Critically, once Battery Notes has determined the entity is invalid, this decision is never re-evaluated: even after confirming a valid live value and manually calling homeassistant.reload_config_entry (for the source entity) and reloading the Battery Notes integration itself, battery_plus remains missing until a fresh process restart with the registry field already correct (by patching).

This suggests two compounding issues:

  1. The "is this a battery entity" check should evaluate the live state's attributes (hass.states.get(...).attributes) rather than (or in addition to) the entity registry's unit_of_measurement field, which can be stale/transiently null for dynamically-reporting sensors on deep-sleep devices.
  2. The coordinator should re-evaluate entity validity on subsequent refreshes/reloads rather than permanently caching a negative determination for the lifetime of the process.

This may share a root cause with #5077 (battery percent does not persist when battery device goes to sleep) — both issues involve Battery Notes not handling the transient unavailable/missing-attribute state of sleep-cycling battery devices robustly. In #5077 an already-created battery_plus loses its last known value; in this issue, battery_plus is never created in the first place because the one-time validity check happens to run while the registry snapshot is momentarily invalid. A fix that makes Battery Notes tolerant of transient unavailability (e.g. falling back to the last known good value/attributes, or re-evaluating validity on subsequent coordinator refreshes) would likely resolve both.

Reproduction steps

  1. Add a Shelly Gen1 H&T (deep-sleep battery sensor with dynamically-reported unit) to HA.
  2. Add a Battery Notes entity-association note for its battery sensor.
  3. Restart Home Assistant while the device hasn't reported yet in this boot cycle.
  4. Observe: battery_plus is not created; debug log shows the entity rejected with unit_of_measurement: None, even though Developer Tools > States (once the device wakes) shows the correct attributes.
  5. Waking the device and reloading (both the source integration and Battery Notes) afterward does not create battery_plus — only a full process restart with the registry field already correct works.

System Health details

Version core-2026.8.0
Installation type Home Assistant Container
Development false
Supervisor false
Docker true
Container architecture aarch64
User root
Virtual environment false
Python version 3.14.6
Operating system family Linux
Operating system version 6.12.87+rpt-rpi-2712
CPU architecture aarch64
Timezone Europe/Berlin
Configuration directory /config

Debug logs

2026-09-02 22:54:42.261 DEBUG (MainThread) [custom_components.battery_notes.coordinator] sensor.shellyht_15_battery is not a battery entity device_class: battery unit_of_measurement: None

Diagnostics dump

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

no-staleDo not close as stale

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions