zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

Missing device_class and state_class in "sub-"power of energy-meter

Open xs400dohc opened this issue 1 year ago • 1 comments

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:

availability:
  - topic: zigbee2mqtt/bridge/state
    value_template: '{{ value_json.state }}'
  - topic: zigbee2mqtt/<friendly_name>/availability
    value_template: '{{ value_json.state }}'
availability_mode: all
device:
  hw_version: 1
  identifiers:
    - zigbee2mqtt_<unique_id>
  manufacturer: Tuya
  model: Bidirectional energy meter with 80A current clamp
  model_id: PC311-Z-TY
  via_device: zigbee2mqtt_bridge_<unique_id>
  name: <friendly_name>
device_class: power
enabled_by_default: true
entity_category: diagnostic
object_id: <friendly_name>_power
origin:
  sw_version: 2.0.0
  name: Zigbee2MQTT
  support_url: https://www.zigbee2mqtt.io
state_class: measurement
state_topic: zigbee2mqtt/<friendly_name>
unique_id: <unique_id>_power_zigbee2mqtt
unit_of_measurement: W
value_template: '{{ value_json.power }}'

Topic: homeassistant/sensor/<unique_id>/power_a/config shows:

availability:
  - topic: zigbee2mqtt/bridge/state
    value_template: '{{ value_json.state }}'
  - topic: zigbee2mqtt/<friendly_name>/availability
    value_template: '{{ value_json.state }}'
availability_mode: all
device:
  hw_version: 1
  identifiers:
    - zigbee2mqtt_<unique_id>
  manufacturer: Tuya
  model: Bidirectional energy meter with 80A current clamp
  model_id: PC311-Z-TY
  via_device: zigbee2mqtt_bridge_<unique_id>
  name: <friendly_name>
                                                                                             <-----NO DEVICE_CLASS HERE
enabled_by_default: true
object_id: <friendly_name>_power_a
origin:
  sw_version: 2.0.0
  name: Zigbee2MQTT
  support_url: https://www.zigbee2mqtt.io
                                                                                             <-----NO STATE_CLASS HERE
state_topic: zigbee2mqtt/<friendly_name>
unique_id: <unique_id>_power_a_zigbee2mqtt
unit_of_measurement: W
value_template: '{{ value_json.power_a }}'
name: Power a

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

xs400dohc avatar Jan 27 '25 14:01 xs400dohc

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.

ViscountHermit avatar Feb 08 '25 20:02 ViscountHermit