zwave-js / zwave-js-ui

Full featured Z-Wave Control Panel UI and MQTT gateway. Built using Nodejs, and Vue/Vuetify
https://zwave-js.github.io/zwave-js-ui
MIT License
984 stars 201 forks source link

incorrect unit_of_measurement for home assistant for ZW096 power switch #3956

Open brianmay opened 1 month ago

brianmay commented 1 month ago

Checklist

Deploy method

Docker

Z-Wave JS UI version

9.19.0

ZwaveJS version

13.3.0

Describe the bug

Home assistant shows these errors:

Oct 14 14:25:59 iot2 homeassistant[192561]: 2024-10-14 14:25:59.902 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.workshop_pump_workshop_pump_electric_power_factor_value (<class 'homeassistant.components.mqtt.sensor.MqttSensor'>) is using native unit of measurement 'Power Factor' which is not a valid unit for the device class ('power') it is using; expected one of ['W', 'kW']; Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+mqtt%22
Oct 14 14:25:59 iot2 homeassistant[192561]: 2024-10-14 14:25:59.903 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.workshop_pump_workshop_pump_electric_pulse_count_value (<class 'homeassistant.components.mqtt.sensor.MqttSensor'>) is using native unit of measurement 'Pulse count' which is not a valid unit for the device class ('power') it is using; expected one of ['W', 'kW']; Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+mqtt%22
Oct 14 14:25:59 iot2 homeassistant[192561]: 2024-10-14 14:25:59.904 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.workshop_pump_workshop_pump_electric_kvah_value (<class 'homeassistant.components.mqtt.sensor.MqttSensor'>) is using native unit of measurement 'kVAh' which is not a valid unit for the device class ('power') it is using; expected one of ['W', 'kW']; Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+mqtt%22

I was told this is not a bug in home assistant: https://github.com/home-assistant/core/issues/128325

To Reproduce

  1. Add ZW096 power switch
  2. Watch for errors.

(only one of my ZW096 power switch device outputs these values, bit confused here)

Expected behavior

No errors.

Additional context

I just noticed my zwave-js-ui is old, don't see anything in changelog about this being fixed, but will try anyway.

brianmay commented 1 month ago

Updated to latest zwave-js-ui but nothing changed.

robertsLando commented 1 month ago

@brianmay Are you using zwave integration or mqtt discovery?

brianmay commented 1 month ago

Mqtt discovery

robertsLando commented 1 month ago

Is there a specific reason why you are not using the zwave js integration with zui as server?

Using the integration is the recommended way for Home Assistant users: https://zwave-js.github.io/zwave-js-ui/#/homeassistant/homeassistant-official

brianmay commented 1 month ago

I have a lot of my personal code that talks directly using mqtt.

robertsLando commented 1 month ago

What should I change in the discovery payload in order to fix the issue so? If a valueId reports power factor or Kvah should I use a different device class? If so which one?

brianmay commented 1 month ago

No idea sorry. I asked here: https://github.com/home-assistant/core/issues/128325#issuecomment-2420469228 but the only answer was "It seems the logs are clear on this. Also the sensor docs are clear." which doesn't really help me.

brianmay commented 1 month ago

Oh, I see, from: https://www.home-assistant.io/integrations/sensor/

power_factor: Power factor (unitless), unit may be None or %

Pulse count probably shouldn't have a unit.

kVAh - if kWh not appropriate (not really sure here), then maybe it shouldn't have a unit.

brianmay commented 1 month ago

Also I think in all cases the device class == power is wrong.

robertsLando commented 1 month ago

Yeah I was reading that too but cannot find the appropriate unit for kVAh, there is apparent_power but that only lists VA. Could you try to manually edit the discovery payload from UI and re-send it to see what's the correct device class to use foreach unit?

robertsLando commented 1 month ago

Also could you paste here a node export please? I see I actually handle this here:

https://github.com/zwave-js/zwave-js-ui/blob/55318465cf8ab81fb065fbfc11cb44e173067480/api/lib/Constants.ts#L116-L185

But maybe that doesn't cover all cases

brianmay commented 1 month ago

Is there somewhere I can send you my node export in private? Rather not send a complete list of my devices to a public forum...

Getting puzzled here, because for the relevant device all I see is:

 "16": {
    "name": "Pump",
    "loc": "Workshop"
  },

I expected to see more details (???).

brianmay commented 1 month ago

I suspect what we would need is:

power factor: "device_class": "power_factor", delete unit_of_measurement Pulse count: delete device_class, delete unit_of_measurement kVAh: delete device_class, delete unit_of_measurement

For the last two, there doesn't seem to be any good pre-existing device class. Surprised I can't find a "apparent_energy" class actually. "apparent_power" is measuring power, not energy.

I tested this. But of course, just because it isn't showing errors doesn't mean it is correct...

brianmay commented 1 month ago

Also I would really like to know why, out of 5 of this devices running the same firmware, only one of them seems to be producing these values. That seems very odd.

Here is the meter section of that device:

image

Here is the meter section of another one, same type exactly:

image

Have tried clicking "rediscover node" on both, it didn't change anything.

robertsLando commented 1 month ago

Is there somewhere I can send you my node export in private? Rather not send a complete list of my devices to a public forum...

PM here: daniel.sorridi@gmail.com

Getting puzzled here, because for the relevant device all I see is:

Are you clicking on advanced and then debug export?

I suspect what we would need is:

I need to understand how to detect this properly. @kpine do you have any clue how home assistant handles this?

Also I would really like to know why, out of 5 of this devices running the same firmware, only one of them seems to be producing these values. That seems very odd.

Rediscover node has no effect on this as this is ZUI values and rediscover node is an action sent to MQTT discovery. You could try to run a new interview of the node but I'm not sure if that would help. Do you know if that device has fw updates available? About this I cc @AlCalzone

kpine commented 1 month ago

I need to understand how to detect this properly. @kpine do you have any clue how home assistant handles this?

HA doesn't use the value unit except as a last resort. It has its own mappings based on Command Class and other properties and complicated logic. I couldn't say whether this approach is necessary for your use case.

https://github.com/home-assistant/core/blob/1663d8dfa9bd5599638f28b5259e52acaafa0a59/homeassistant/components/zwave_js/discovery_data_template.py#L361

https://github.com/home-assistant/core/blob/1663d8dfa9bd5599638f28b5259e52acaafa0a59/homeassistant/components/zwave_js/sensor.py#L98-L329

brianmay commented 4 weeks ago

PM here: daniel.sorridi@gmail.com

Done

Are you clicking on advanced and then debug export?

advanced -> Backup -> Export

Do you know if that device has fw updates available?

I am not familiar with any fw updates. zwave js ui reports all devices on "FW: v1.4".

I am wondering if the difference is the version of zwave I had installed when I did the interviewing. Either that, or I actually have a different generations of what should be the exact same product.

The oldest device seems to have the most metrics (15), the most recent device has the fewest (only 4). Huh?

Wonder if I should re-interview the old device and see if I still get all the metrics back again. But no going back again if I do lose them... Which might kill any chances of testing a fix for the incorrect units.

kpine commented 4 weeks ago

advanced -> Backup -> Export

I think he's looking for the debug exports either under the node's Advanced menu, or from the "Debug Info" panel.

image

image

Wonder if I should re-interview the old device and see if I still get all the metrics back again. But no going back again if I do lose them... Which might kill any chances of testing a fix for the incorrect units

You could always try downgrading to a previous version and see if the working behavior can be reproduced. Might be challenging to find the version unless you can remember a time frame. I would be a nice feature to have the a timestamp and/or version number saved for the last interview.

AlCalzone commented 4 weeks ago

power factor: "device_class": "power_factor", delete unit_of_measurement Pulse count: delete device_class, delete unit_of_measurement kVAh: delete device_class, delete unit_of_measurement

Agree for the first two, which are unitless, but this part actually looks like a bug in node-zwave-js. The latter seems to be simply missing in HA, so deleting the unit is more of a workaround than a proper fix.

robertsLando commented 4 weeks ago

Thanks both @kpine and @AlCalzone , so seems this should be fixed with the next driver release? Except for the part of removing kVAh units as seems there is no option for that ATM, may be worth if @brianmay opens an issue on HA about that maybe?

AlCalzone commented 4 weeks ago

There's an ongoing discussion about the missing units here: https://github.com/home-assistant/architecture/discussions/724

brianmay commented 3 weeks ago

I think he's looking for the debug exports either under the node's Advanced menu, or from the "Debug Info" panel.

I sent him both of those files to his email also.

robertsLando commented 3 weeks ago

@brianmay Thanks, received!