Skip to content

variable is using native unit of measurement 'None' which is not a valid unit for the device class ('power') #184

Closed

Description

@GiZMoSK1221

Why do I get error with " is using native unit of measurement 'None' which is not a valid unit for the device class ('power'); expected one of ['MW', 'mW', 'W', 'GW', 'kW', 'TW']" ?
There seems to be something wrong in sensor... :( like when unit_of_measurement was defined as user attribute and not system attribute. The value is correct.

variable definition:
variable_test_del_15m:
value: 1
restore: false
exclude_from_recorder: false
unique_id: variable_test_del_15m
attributes:
state_class: measurement
device_class: power
unit_of_measurement: kW

after restart i get these messages in log:
2026-08-20 21:12:41.626 WARNING (MainThread) [custom_components.variable] [YAML] Creating New Sensor Variable: variable_test_del_15m
2026-08-20 21:12:41.628 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.variable_test_del_15m (<class 'custom_components.variable.sensor.Variable'>) is using native unit of measurement 'None' which is not a valid unit for the device class ('power') it is using; expected one of ['MW', 'mW', 'W', 'GW', 'kW', 'TW']; Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/wibias/hass-variables/issues

I get second error after every restart.

states view seems ok:
Image

Activity

  1. Wibias commented on Aug 22, 2026

    @Wibias
    Owner

    Thanks for the clear report and the YAML example.

    YAML sensors already promoted device_class and state_class from attributes to native sensor properties. unit_of_measurement was left as a custom extra attribute instead, so Home Assistant compared device class power against native unit None and logged that warning. The States view still looked correct because kW was present as that extra attribute.

    #186 maps unit_of_measurement onto the native unit (including after restart when older restore data still had native unit None).

    If you grant issue-comment access, or want this posted on the PR instead, I can post it from here.

  2. GiZMoSK1221 commented on Aug 26, 2026

    @GiZMoSK1221
    Author

    Hi Wibias, thanks for the repair, now I have no warnings after restart.
    Sorry for late answer, it's holiday time :)

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

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