-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing device_class and state_class in "sub-"power of energy-meter #26028
Labels
problem
Something isn't working
Comments
I have pretty much the same issue. It seems for some reason that Z2m is not sending the state_class for some entities. I've looked but can't seem to find how and where the class is set. BTW, mine is a _TZE204_81yrt3lo PJ1203A I know there's so much to do, but can this issue pretty please not be forgotten. |
xs400dohc
added a commit
to xs400dohc/zigbee2mqtt
that referenced
this issue
Feb 12, 2025
Made some investigation: - as written in my post, energy has a device_class and state_class power and current don't. - searched for the reason why energy behaves different to power and current - in [homeassistant.ts](https://github.com/Koenkk/zigbee2mqtt/blob/master/lib/extension/homeassistant.ts) I found this code in line 1018: ``` // If a variable includes Wh, mark it as energy if (firstExpose.unit && ['Wh', 'kWh'].includes(firstExpose.unit)) { Object.assign(extraAttrs, {device_class: 'energy', state_class: 'total_increasing'}); } ``` I think a possible solution could be to add following ``` // If a variable includes A or mA, mark it as energy if (firstExpose.unit && ['A', 'mA'].includes(firstExpose.unit)) { Object.assign(extraAttrs, {device_class: 'current', state_class: 'measurement'}); } // If a variable includes mW, W, kW, MW, GW, TW, mark it as energy if (firstExpose.unit && ['mW', 'W', 'kW', 'MW', 'GW', 'TW'].includes(firstExpose.unit)) { Object.assign(extraAttrs, {device_class: 'power', state_class: 'measurement'}); } ``` But I don't know how to test the changes in my homeassistant if that would fix the problem. Didn't found homeassistant.ts in my installation (using VS-Code-extension). Perhaps it's also way for other sensors with other units, e.g. Data rate in bit/s, kbit/s, Mbit/s, Gbit/s, B/s, kB/s, MB/s, GB/s, KiB/s, MiB/s or GiB/s (see [here](https://www.home-assistant.io/integrations/sensor#device-class)).
xs400dohc
added a commit
to xs400dohc/zigbee2mqtt
that referenced
this issue
Feb 12, 2025
Made some investigation: - as written in my post, energy has a device_class and state_class power and current don't. - searched for the reason why energy behaves different to power and current - in [homeassistant.ts](https://github.com/Koenkk/zigbee2mqtt/blob/master/lib/extension/homeassistant.ts) I found this code in line 1018: ``` // If a variable includes Wh, mark it as energy if (firstExpose.unit && ['Wh', 'kWh'].includes(firstExpose.unit)) { Object.assign(extraAttrs, {device_class: 'energy', state_class: 'total_increasing'}); } ``` I think a possible solution could be to add following ``` // If a variable includes A or mA, mark it as energy if (firstExpose.unit && ['A', 'mA'].includes(firstExpose.unit)) { Object.assign(extraAttrs, {device_class: 'current', state_class: 'measurement'}); } // If a variable includes mW, W, kW, MW, GW, TW, mark it as energy if (firstExpose.unit && ['mW', 'W', 'kW', 'MW', 'GW', 'TW'].includes(firstExpose.unit)) { Object.assign(extraAttrs, {device_class: 'power', state_class: 'measurement'}); } ``` But I don't know how to test the changes in my homeassistant if that would fix the problem. Didn't found homeassistant.ts in my installation (using VS-Code-extension). Perhaps it's also way for other sensors with other units, e.g. Data rate in bit/s, kbit/s, Mbit/s, Gbit/s, B/s, kB/s, MB/s, GB/s, KiB/s, MiB/s or GiB/s (see [here](https://www.home-assistant.io/integrations/sensor#device-class)).
xs400dohc
added a commit
to xs400dohc/zigbee2mqtt
that referenced
this issue
Feb 12, 2025
Made some investigation: - as written in my post, energy has a device_class and state_class power and current don't. - searched for the reason why energy behaves different to power and current - in [homeassistant.ts](https://github.com/Koenkk/zigbee2mqtt/blob/master/lib/extension/homeassistant.ts) I found this code in line 1018: ``` // If a variable includes Wh, mark it as energy if (firstExpose.unit && ['Wh', 'kWh'].includes(firstExpose.unit)) { Object.assign(extraAttrs, {device_class: 'energy', state_class: 'total_increasing'}); } ``` I think a possible solution could be to add following ``` // If a variable includes A or mA, mark it as energy if (firstExpose.unit && ['A', 'mA'].includes(firstExpose.unit)) { Object.assign(extraAttrs, {device_class: 'current', state_class: 'measurement'}); } // If a variable includes mW, W, kW, MW, GW, TW, mark it as energy if (firstExpose.unit && ['mW', 'W', 'kW', 'MW', 'GW', 'TW'].includes(firstExpose.unit)) { Object.assign(extraAttrs, {device_class: 'power', state_class: 'measurement'}); } ``` But I don't know how to test the changes in my homeassistant if that would fix the problem. Didn't found homeassistant.ts in my installation (using VS-Code-extension). Perhaps it's also way for other sensors with other units, e.g. Data rate in bit/s, kbit/s, Mbit/s, Gbit/s, B/s, kB/s, MB/s, GB/s, KiB/s, MiB/s or GiB/s (see [here](https://www.home-assistant.io/integrations/sensor#device-class)).
xs400dohc
added a commit
to xs400dohc/zigbee2mqtt
that referenced
this issue
Feb 12, 2025
implemented the suggestion of @Koenkk
xs400dohc
added a commit
to xs400dohc/zigbee2mqtt
that referenced
this issue
Feb 12, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What happened?
I have an energy meter integrated via Zigbee2mqtt (type: Tuya PC311-Z-TY).
The "main"-power-entity (object_id: <friendly_name>_power) has "device_class: power"and "state_class: measurement". The "sub"-power-entityties (object_id: <friendly_name>_power_a and <friendly_name>_power_b) does not. Same issue with current ("main"-current with device_class and state_class, "sub"-current without).
The energy-entities ("main"- and "sub"-entities of energy and energy_produced) have all "device_class: energy" and "state_class: total_increasing".
Following is from settings->devices->devices->device-info->MQTT INFO:
Topic: homeassistant/sensor/<unique_id>/power/config shows payload:
Topic: homeassistant/sensor/<unique_id>/power_a/config shows:
I'm not sure, if it's an issue for MQTT or for ZIGBEE2MQTT/zigbee-herdsman, so I will open an issue in both.
If the issue is wrong here, please close it. If you are having the same problem and this issue is closed, have a look on the other github.
Found this issue while creating a statistics-graph on a dashboard and only 1 entity (helper of sum of three "sub"-entities (line1+line2+line3)) was displayed but not the "sub"-entities directly, due to missing statistic data.
What did you expect to happen?
I expect that "sub"-power and "sub"-current have device_class and stat_class, so statistics are recordable/displayable.
How to reproduce it (minimal and precise)
No response
Zigbee2MQTT version
2.0.0-2
Adapter firmware version
7.4.1 [GA]
Adapter
EmberZNet
Setup
Add-on on HA OS on Fujitsu Thinclient
Debug log
No response
The text was updated successfully, but these errors were encountered: