Skip to content
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

incorrect unit_of_measurement for home assistant for ZW096 power switch #3956

Open
3 tasks done
brianmay opened this issue Oct 17, 2024 · 23 comments
Open
3 tasks done
Labels
bug Something isn't working

Comments

@brianmay
Copy link

Checklist

  • I am not using Home Assistant. Or: a developer has told me to come here.
  • I have checked the troubleshooting section and my problem is not described there.
  • I have read the changelog and my problem is not mentioned there.

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: home-assistant/core#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 brianmay added the bug Something isn't working label Oct 17, 2024
@brianmay
Copy link
Author

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

@robertsLando
Copy link
Member

@brianmay Are you using zwave integration or mqtt discovery?

@brianmay
Copy link
Author

Mqtt discovery

@robertsLando
Copy link
Member

robertsLando commented Oct 21, 2024

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
Copy link
Author

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

@robertsLando
Copy link
Member

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
Copy link
Author

No idea sorry. I asked here: home-assistant/core#128325 (comment) 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
Copy link
Author

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
Copy link
Author

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

@robertsLando
Copy link
Member

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
Copy link
Member

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

export function meterType(ccSpecific: IMeterCCSpecific): any {
const meter = getMeter(ccSpecific.meterType)
const scale = getMeterScale(ccSpecific.meterType, ccSpecific.scale)
const cfg = {
sensor: meter?.name || 'unknown',
objectId: scale?.label || `unknown${ccSpecific.scale}`,
props: {},
}
// https://github.com/zwave-js/node-zwave-js/blob/master/packages/config/config/meters.json
switch (ccSpecific.meterType) {
case 0x01: // electric
switch (ccSpecific.scale) {
case 0x00: // kWh
cfg.props = {
state_class: 'total_increasing',
device_class: 'energy',
}
break
case 0x02: // W
cfg.props = {
state_class: 'measurement',
device_class: 'power',
}
break
case 0x04: // V
cfg.props = {
state_class: 'measurement',
device_class: 'voltage',
}
break
case 0x05: // A
cfg.props = {
state_class: 'measurement',
device_class: 'current',
}
break
default:
cfg.props = {
device_class: 'power',
}
break
}
break
case 0x02: // gas
cfg.props = {
icon: 'mdi:thought-bubble',
device_class: 'gas',
}
break
case 0x03: // water
cfg.props = {
icon: 'mdi:water',
}
break
case 0x04: // heating
cfg.props = {
icon: 'mdi:fire',
}
break
case 0x05: // cooling
cfg.props = {
icon: 'mdi:snowflake',
}
break
}
return cfg
}

But maybe that doesn't cover all cases

@brianmay
Copy link
Author

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
Copy link
Author

brianmay commented Oct 22, 2024

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
Copy link
Author

brianmay commented Oct 22, 2024

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
Copy link
Member

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
Copy link
Contributor

kpine commented Oct 24, 2024

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
Copy link
Author

brianmay commented Oct 24, 2024

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
Copy link
Contributor

kpine commented Oct 25, 2024

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
Copy link
Member

AlCalzone commented Oct 25, 2024

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
Copy link
Member

robertsLando commented Oct 25, 2024

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
Copy link
Member

There's an ongoing discussion about the missing units here: home-assistant/architecture#724

@brianmay
Copy link
Author

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
Copy link
Member

@brianmay Thanks, received!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants