Zwave_js.set_config_parameter is awesome!

We replaced a bunch of dummy switches with Inovelli LZW30. They have large LED with selectable color and intensity, and naturally we couldn’t agree on what looked best. So how do you go about mass updates of the respective parameters? Thankfully, the awesome Z-Wave JS developers dropped in a new service in the latest release! Here’s my flow to do this with as little effort as I could think of in my favorite engine, node-red:

node-red-flow

The flow is made up of several nodes:

  1. It reads the HA device registry at /config/.storage/core.device_registry so that you can just point to a manufacturer/model rather then hardcoding the device_id you want to address.
  2. The output from the first node is then converted to JSON for further processing.
  3. The heart of the logic resides in a function node (see below). There is a wonderful compilation of device configurations at https://devices.zwave-js.io/
  4. A rate limiter is added to give the slowish Z-Wave a chance for success
  5. And finally, zwave_js.set_config_parameter is called for each device and parameter

The JavaScript code snippet only shows a single parameter, but you can add them all to the array. Until the service can update more than one parameter at a time, this array is needed to make individual service calls.

let devices = msg.payload.data.devices;
let manufacturer = 'Inovelli';
let model = 'LZW30';
let cfg = [
    {
        "description": "LED Indicator Color",
        "parameter": 5, 
        "value": 21
    },
]

for(let i = 0; i < devices.length; i++) {
    let device = devices[i];
    if(device.manufacturer == manufacturer 
            && device.model == model){
        for (let j in cfg){
            msg.payload = {
                'data': {
                    'device_id': device.id,
                    'parameter': cfg[j]['parameter'],
                    'value': cfg[j]['value']
                }
            }
            node.send(msg);
        }
    }
}

I would have you know that, in the end, we agreed on setting the LEDs to orange at 10% intensity.

4 Likes

This looks really useful. Right now I have three of these switches so I just have an indivudal node for each color or notification setting.

Would you mind sharing the entire Node Red Flow?

Hoping this works:

[{"id":"6c387d2c.4c3554","type":"file in","z":"294b601a.13836","name":"Read Registry","filename":"/config/.storage/core.device_registry","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":300,"y":60,"wires":[["1858a0da.b3191f"]]},{"id":"18855f49.0bd0f1","type":"inject","z":"294b601a.13836","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":60,"wires":[["6c387d2c.4c3554"]]},{"id":"1858a0da.b3191f","type":"json","z":"294b601a.13836","name":"Convert to JSON","property":"payload","action":"","pretty":false,"x":490,"y":60,"wires":[["34e7c669.3f8b5a"]]},{"id":"34e7c669.3f8b5a","type":"function","z":"294b601a.13836","name":"Inovelli LZW30","func":"let devices = msg.payload.data.devices;\nlet manufacturer = 'Inovelli';\nlet model = 'LZW30';\nlet cfg = [\n    {\n        \"description\": \"LED Indicator Color\",\n        \"parameter\": 5, \n        \"value\": 21\n    },\n]\n\nfor(let i = 0; i < devices.length; i++) {\n    let device = devices[i];\n    if(device.manufacturer == manufacturer \n            && device.model == model){\n        for (let j in cfg){\n            msg.payload = {\n                'data': {\n                    'device_id': device.id,\n                    'parameter': cfg[j]['parameter'],\n                    'value': cfg[j]['value']\n                }\n            }\n            node.send(msg);\n        }\n    }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":160,"y":120,"wires":[["210bd3e1.9d0d3c"]]},{"id":"e5b37192.324f7","type":"api-call-service","z":"294b601a.13836","name":"Set configuration parameters","server":"2274bf95.f7369","version":1,"debugenabled":true,"service_domain":"zwave_js","service":"set_config_parameter","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":560,"y":120,"wires":[[]]},{"id":"210bd3e1.9d0d3c","type":"delay","z":"294b601a.13836","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":340,"y":120,"wires":[["e5b37192.324f7"]]},{"id":"2274bf95.f7369","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
2 Likes

Worked great. Didnt know you could process config files that way. Thanks again.