Skip to content

mqtt-hassio.cfg: energy device_class/state_class not applied to kWh sensors (unit pattern ,Wh$ doesn't match kWh) #1756

Description

@ebaschiera

Summary

In contrib/etc/ebusd/mqtt-hassio.cfg, the type_switch-number rule that assigns device_class: energy + state_class: total_increasing only matches the unit Wh, not kWh (or MWh).

Detail

The rule (around line 197):

    sensor,energy,total_increasing = energy|,Wh$

matches if the message/field name contains energy or the unit matches ,Wh$. The switch key is %name%field,%unit, so a kWh field produces a key ending in ,kWh, and the pattern ,Wh$ (comma immediately followed by Wh) does not match because of the k.

The neighbouring power rule already handles the k-prefix explicitly (,kW$|,W$); the energy (and yield) rules do not.

Effect

Any energy reading in kWh whose name does not contain "energy" gets no device_class and no state_class, so it is excluded from long-term statistics and the Energy dashboard. Real example: Vaillant StatFuelSum (gas counter, unit kWh) is published as a plain sensor.

Fix

See PR — change the unit alternative to also match kWh. The yield rule on the next line (total*,Wh$) has the same limitation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions