zwave-js / node-zwave-js

Z-Wave driver written entirely in JavaScript/TypeScript
https://zwave-js.github.io/node-zwave-js/
MIT License
749 stars 600 forks source link

Invalid response from S2 multicast setValue command #6696

Closed AlCalzone closed 6 months ago

AlCalzone commented 7 months ago

Discussed in https://github.com/zwave-js/node-zwave-js/discussions/6695

Originally posted by **@kpine** March 13, 2024 ### Checklist - [X] I have read and followed the above instructions - [X] I have checked the [troubleshooting section](https://zwave-js.github.io/node-zwave-js/#/troubleshooting/index) and my problem is **not** described there. - [X] I have read the [changelog](https://github.com/zwave-js/node-zwave-js/blob/master/CHANGELOG.md) and my problem was **not** mentioned there or the fix **did not work**. ### Describe the issue What is happening? An invalid result is returned for a S2 multicast setValue command. The result is the object `{"nodeId":255,"ccId":"Supervision","ccCommand":"0x02"}` but it should be a `SetValueResult` instead. The invalid result causes exceptions when submitted via HA's Z-Wave integration, as it expects a `SetValueResult` return value. See https://github.com/home-assistant/core/issues/111685. What did you expect to happen instead? The method should return `SetValueResult`, example: `{"status":254}`. Steps to reproduce the behavior: I used ZUI driver code to exclude HA as the problem, and could reproduce. Run this driver code, where the multicast targets are included with Security S2: ```javascript const { logger } = this const virtualNode = driver.controller.getMulticastGroup([39, 43]); const result = await virtualNode.setValue( {"commandClass": 38, "property": "targetValue"}, 24, ); logger.info(`Response: ${JSON.stringify(result)}`); ``` You will see a log message like: ```text 2024-03-12 21:48:21.340 INFO Z-WAVE: Response: {"nodeId":255,"ccId":"Supervision","ccCommand":"0x02"} ``` Anything else we should know? It's not a problem when the multicast targets are included with no security. With the same driver code I see: ```text 2024-03-12 22:39:47.110 INFO Z-WAVE: Response: {"status":254} ``` In the attached log file I used nodes 39 and 43 (S2 Auth) for the invalid response, and 2 and 14 (no security) for the working one. ### Software versions zwave-js-ui: 9.9.0.09b107a zwave-js: 12.4.4 ### Device information N/A ### Checklist - [X] I [made sure](https://zwave-js.github.io/node-zwave-js/#/troubleshooting/index?id=rule-1-use-the-driver-log-luke) to provide a **driver log** on level **debug**. - [ ] The log includes a re-interview of the problematic device _(if applicable)_. - [X] The log includes the problematic interaction with the device _(if applicable)_. - [X] I provided the node ID of the problematic device _(if applicable)_. ### Upload Logfile [zwave_js.log](https://github.com/zwave-js/node-zwave-js/files/14582870/zwave_js.log)
AlCalzone commented 6 months ago

Seems you're hitting this comment:

            // api.setValue could technically return a SupervisionResult
            // but supervision isn't used for multicast / broadcast

            // FIXME: It just may for S2 multicast
Daniel-dev22 commented 6 months ago

Not sure this is 100% fixed as I'm still seeing this and I pulled latest of zwave js UI.

Failed to call service light.turn_on. Unable to set value via multicast.

I don't see the same issue about the status key but I'm seeing both this error and I'm seeing No zwave_js entities found in service call but the service executes still.

AlCalzone commented 6 months ago

This may need some more debugging on the HA side of things. node-zwave-js should return a valid response now.

Daniel-dev22 commented 6 months ago

This may need some more debugging on the HA side of things. node-zwave-js should return a valid response now.

Not sure where to start.

I currently see frontend errors like this

[134947289678144] Error handling message: Unable to set value via multicast (home_assistant_error) User from 192.168.6.10 (Mozilla/5.0 (Linux; Android 14; SM-S928U1 Build/UP1A.231005.007; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/123.0.6312.118 Mobile Safari/537.36 Home Assistant/2024.4.1-12576 (Android 14; SM-S928U1))
[134947382890304] Error handling message: No zwave_js entities found in service call. Got {'type': 'execute_script', 'sequence': [{'service': 'light.turn_off', 'data': {}, 'target': {'entity_id': ['light.master_bedroom_light_strips_frontend']}}], 'id': 358} (invalid_format) User from 192.168.6.10 (Mozilla/5.0 (Linux; Android 14; SM-S928U1 Build/UP1A.231005.007; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/123.0.6312.118 Mobile Safari/537.36 Home Assistant/2024.4.1-12576 (Android 14; SM-S928U1))

Where light.master_bedroom_light_strips_frontend is a template light consiting of 3 Zwave inovelli light strips entities so while light.master_bedroom_light_strips_frontend in not literally a Zwave entity the 3 behind it are and the service call does work but it throws the error anyway.

I also currently have light entities for each individual light strip rather than the generic light entity because it's more reliable to use Zwave commands to turn on/off, set color and brightness with these light strips. I don't use multicast commands since I'm targeting specific lights and I never see any errors about not consiting of zwave entities.

Here's my template light yaml. Where light.master_bedroom_light_strip_1, light.master_bedroom_light_strip_2,light.master_bedroom_light_strip_3 are the zwave entities. https://dpaste.org/QcLqf

I tried turning on zwavejs debugging for the ha integration itself but I don't see any errors in those logs.

kpine commented 6 months ago

I would suggest taking your turn_off service code, pasting it into the Service devtools, and see if that is working. If it's working, than it means an issue with either your automation, the template light, or a problem in HA. At this point, nothing is reaching Z-Wave JS.

Daniel-dev22 commented 6 months ago

I would suggest taking your turn_off service code, pasting it into the Service devtools, and see if that is working. If it's working, than it means an issue with either your automation, the template light, or a problem in HA. At this point, nothing is reaching Z-Wave JS.

So this might be the issue. When I run turning the light on and off via a script I don't see any errors. But when I do it via the frontend with a service call I do see these errors

Master Bedroom Light Strips Frontend: Error executing script. Error for call_service at pos 1: Unable to set value via multicast
Master Bedroom Light Strips Frontend: Already running
Master Bedroom Light Strips Frontend: Error executing script. Error for call_service at pos 2: Unable to set value via multicast

I wonder if the errors are as a result of this. zwave_js_server.exceptions.SetValueFailed: 5 Multilevel Switch: "targetColor" is not a supported property (ZW0322)

Even though I'm not targeting that device I guess because it's multicast it's blasted to all devices and somehow that's causing an issue.

https://dpaste.org/uKEJe

I will also note I fixed my template light code and I'm not seeing the error about not having a valid zwavejs entity anymore so the only issue now is simply that it keeps throwing an error even though it carries out the action successfully.

AlCalzone commented 6 months ago

Multicast isn't "blasted" to all devices. All entities you select are targeted as a single command (or more if you have mixed security classes).

The error you quote is Z-Wave JS refusing to change the target color of a dimmer (which is not something that exists).

Daniel-dev22 commented 6 months ago

Multicast isn't "blasted" to all devices. All entities you select are targeted as a single command (or more if you have mixed security classes).

The error you quote is Z-Wave JS refusing to change the target color of a dimmer (which is not something that exists).

Any idea why it would even be trying to change the target color of a dimmer?

kpine commented 6 months ago

Any idea why it would even be trying to change the target color of a dimmer?

You told it to.

            command_class: "38"
            endpoint: "0"
            property: targetColor
Daniel-dev22 commented 6 months ago

Any idea why it would even be trying to change the target color of a dimmer?

You told it to.

            command_class: "38"
            endpoint: "0"
            property: targetColor

I told a light that though not a dimmer?

Oh I see the command class 38 is for switches. For some reason that works though on inovelli light strips.

Edit I just noticed when I created the light group for multicast bad copy pasta occurred. Somehow I ended up using command class 38 instead of 51 for those service calls.

All is good now. Thank you both.