Skip to content

(wmbus_common) Don't assign "?" unit to sensors of fields without unit suffix - #56

Closed
KrzysztofHajdamowicz wants to merge 2 commits into
IoTLabs-pl:masterfrom
KrzysztofHajdamowicz:fix/timestamp-invalid-unit
Closed

KrzysztofHajdamowicz wants to merge 2 commits into
IoTLabs-pl:masterfrom
KrzysztofHajdamowicz:fix/timestamp-invalid-unit

Conversation

@KrzysztofHajdamowicz

Copy link
Copy Markdown

Problem

As described in #55: for well-known fields without a unit suffix (e.g. timestamp), the auto-detected unit_of_measurement fell back to "?".

Home Assistant treats any sensor with a unit of measurement as numeric, while its ESPHome integration delivers a datetime value for device_class: timestamp sensors. This conflict makes HA reject every state update, so the entity stays unavailable forever. The only workaround was an explicit unit_of_measurement: "" in the user's YAML.

Fix

  • get_human_readable_unit() returns an empty string instead of "?" when no unit can be inferred from the field name (the function has a single call site, so this is safe),
  • default_unit_of_measurement() skips setting unit_of_measurement entirely in that case.

Fields with a proper unit suffix (_kwh, _m3, _dbm, …) are unaffected — the only behavioral change is for fields that previously got the question mark.

Also added a field: timestamp sensor with device_class: timestamp to tests/wmbus.yaml to cover this case.

Fixes #55

🤖 Generated with Claude Code

For well-known fields without a unit suffix (e.g. timestamp), the
auto-detected unit_of_measurement fell back to "?". Home Assistant
treats any sensor with a unit as numeric, while its ESPHome integration
delivers a datetime for device_class: timestamp - every state update is
rejected and the entity stays unavailable forever.

Skip setting unit_of_measurement entirely when no unit can be inferred
from the field name. Fields with a proper unit suffix (_kwh, _m3,
_dbm, ...) are unaffected.

Fixes IoTLabs-pl#55

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kubasaw kubasaw added bug Something isn't working component: wmbus_common labels Aug 28, 2026
@kubasaw kubasaw changed the title Don't assign "?" unit to sensors of fields without unit suffix (wmbus_common) Don't assign "?" unit to sensors of fields without unit suffix Aug 28, 2026
@kubasaw

kubasaw commented Aug 28, 2026

Copy link
Copy Markdown
Member

@KrzysztofHajdamowicz Can you check if it still works?

@kubasaw

kubasaw commented Oct 11, 2026

Copy link
Copy Markdown
Member

Superseded by #75

@kubasaw kubasaw closed this Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working component: wmbus_common

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"last update" field have ? unit, should have none.

2 participants