Can I have something ignored if a payload isnt present?

Some zwave_js parameters are partial parameters that require a bitmask, some arent. But for the ones that arent, I dont want to have to make a completely separate call service node. Is there anyway I can use the same call service node and have it ignore the bitmask argument if its not present in the preceding change node.

To explain better…

here is the complete flow…

[{"id":"f1ca98b1.b2e218","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"c680b90b.8415c8","type":"inject","z":"f1ca98b1.b2e218","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":862,"y":90,"wires":[["231cca39.5a2706"]]},{"id":"f76c7b80.5516d8","type":"change","z":"f1ca98b1.b2e218","name":"Without bitmask","rules":[{"t":"set","p":"parameter","pt":"msg","to":"17","tot":"str"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1061,"y":152,"wires":[["4a887e0.efc6d84"]]},{"id":"231cca39.5a2706","type":"change","z":"f1ca98b1.b2e218","name":"With bitmask","rules":[{"t":"set","p":"parameter","pt":"msg","to":"16","tot":"num"},{"t":"set","p":"bitmask","pt":"msg","to":"255","tot":"str"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1051,"y":89,"wires":[["4a887e0.efc6d84"]]},{"id":"4a887e0.efc6d84","type":"api-call-service","z":"f1ca98b1.b2e218","name":"Office","server":"456659de.370498","version":1,"debugenabled":false,"service_domain":"zwave_js","service":"set_config_parameter","entityId":"light.office","data":"{\"bitmask\":\"{{bitmask}}\",\"parameter\":\"{{parameter}}\",\"value\":\"{{value}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1283,"y":117,"wires":[[]]},{"id":"466ae424.089fdc","type":"inject","z":"f1ca98b1.b2e218","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":862,"y":153,"wires":[["f76c7b80.5516d8"]]},{"id":"456659de.370498","type":"server","name":"AvilaSmartHome","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

image

With bitmask looks like this…
image

Without bitmask looks like this…
image

Change node looks like this…
image

The current flow will only work when triggering ‘With bitmask’. If I try ‘Without bitmask’, I get the following error…
image

Is there anything I can add into the change node json to have it ignore bitmask if there isnt a bitmask payload?

Does no bitmask mean bitmask = 0?
If not then the only way I can think of is to use a function node instead of the change nodes and make the json dynamic with an if statement.

Edit above is assuming there is something in the sequence that differentiate if there is or not bitmask.
If not then you can just replace the change nodes with function nodes.

have you tried bitmask is empty? Nevermind, that won’t do it… I just understood what you meant

@Hellis81 i dont think bitmask=0 when there is no bitmask. I tried setting it to 0 for the ‘no bitmask’ change node and I get a new error.

image

@obaldius Yes i tried with nothing in the bitmask change node section and I get same error as original post shows

Ok.
But what does the sequence look like prior?
Is there something that tells you when to use bitmask and when not to?
My idea is to merge the two lines in to one.

@Hellis81 well this is for my setting of my inovelli switch parameters. Some parameters have bitmasks, some dont. I just wanted to avoid having multiple service call nodes for each switch as I am already gonna have 30+ of them. But to avoid additonal coding as you said in a function node, I think I may just have to have 2 service call nodes. One that includes a {{bitmask}} and one that doesnt. Using a switch node to route the parameter I want to change to the correct one.

I believe he wants to avoid exactly that. Long story short, he wants a dynamic data field in the service call

For example, parameter 15 doesnt have a bitmask, parameter 16 does.

This is not the end result I wanted but a mid step.

[{"id":"f76c7b80.5516d8","type":"change","z":"f1ca98b1.b2e218","name":"Without bitmask","rules":[{"t":"set","p":"parameter","pt":"msg","to":"17","tot":"str"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1061,"y":152,"wires":[["2fba69a2.f560e6"]]},{"id":"466ae424.089fdc","type":"inject","z":"f1ca98b1.b2e218","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":862,"y":153,"wires":[["f76c7b80.5516d8"]]},{"id":"2fba69a2.f560e6","type":"function","z":"f1ca98b1.b2e218","name":"","func":"if (typeof msg.bitmask !== 'undefined') {\n    msg.payload = {\n        \"bitmask\": msg.bitmask,\n        \"parameter\": msg.parameter,\n        \"value\": msg.value\n    };\n}else{\n    msg.payload = {\n        \"parameter\": msg.parameter,\n        \"value\": msg.value\n    };\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1240,"y":120,"wires":[["4a887e0.efc6d84"]]},{"id":"231cca39.5a2706","type":"change","z":"f1ca98b1.b2e218","name":"With bitmask","rules":[{"t":"set","p":"parameter","pt":"msg","to":"16","tot":"num"},{"t":"set","p":"bitmask","pt":"msg","to":"255","tot":"str"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1051,"y":89,"wires":[["2fba69a2.f560e6"]]},{"id":"4a887e0.efc6d84","type":"api-call-service","z":"f1ca98b1.b2e218","name":"Office","server":"456659de.370498","version":1,"debugenabled":false,"service_domain":"zwave_js","service":"set_config_parameter","entityId":"light.office","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1390,"y":120,"wires":[[]]},{"id":"c680b90b.8415c8","type":"inject","z":"f1ca98b1.b2e218","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":862,"y":90,"wires":[["231cca39.5a2706"]]},{"id":"456659de.370498","type":"server","name":"AvilaSmartHome","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Noticed an error in the sequence, updated.

Meaning one service call and using a function node to do the logic and passing the dynamic json.
But you need to answer my questions if you want us to help you further.

FYI, this works. It’s an example with lights but I guess you’ll find it useful. You can set dynamic data fields this way. Note the msg.payload.data.brightness from the inject node.


[{"id":"54a265c6.5f13cc","type":"inject","z":"d4450f17.60952","name":"","props":[{"p":"payload.data.brightness","v":"25","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":240,"y":340,"wires":[["b0a4d778.6b6be8"]]},{"id":"b0a4d778.6b6be8","type":"api-call-service","z":"d4450f17.60952","name":"b","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.q_cocina","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":400,"y":340,"wires":[["7e76b9d1.5e4f98"]]},{"id":"7e76b9d1.5e4f98","type":"debug","z":"d4450f17.60952","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":550,"y":340,"wires":[]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true}]

@Hellis81

I dont know how to answer your question any other way; referring to the prior steps. Here is a mockup of how the final flow would look. If Im misunderstanding your question, please let me know.

Heres best way I can explain the end result Im looking for.

I wake up and my wife says she wants all the LED bars changed to flashing green EXCEPT for living room and entryway. I go into the flow, delete the lines connecting ‘function’ to ‘living room’ and ‘entryway’, edit the corresponding parameter ‘change node’, lets say its parameter 6 (which IS a partial parameter) and then press inject. I dont need to be concerned if its a partial parameter Im setting or not, the logic will take care of it.

Or I want to change all the switches so that the led bar shows the dimming level. Lets assume this is parameters 2 (which IS NOT a partial parameter). I go back into same flow, reconnect ‘function’ to ‘living room’ and ‘entryway’, adjust ‘parameter 2’ change node accordingly and press inject. Again, I dont need to be concerned if its partial or not.

Your flow would be great, if it could work like that. With your flow, I dont need TWO service calls nodes for each switch (one for parameters that have a bitmask and one that doesnt).

Hope that explains my goal.

Pardon me then.
I thought the inject nodes was a simplified version just for the question.

Perhaps you could use a card in in lovelace that toggles booleans and set input texts to the parameters you want and then you activate the sequence with button?
Just a thought. I wouldn’t want to open node red each time I want to turn on/change a light.

No no, its not turning on/off the lights. I have notification bars on the switch itself. So occasionally, I like to switch it up. Or theres a parameter I want to change on all of them, for instance, how long it takes to activate. These are things I am setting maybe once a month.

@nappyjim so you want to flow only to trigger the livng room and entryway if bitmask is not present? or the other way around?

Not sure it’ll help but this won’t yield and API error. It’ll trigger the service call regardless of whether the change node contains bitmask or not.

[{"id":"f92367fc.4419e8","type":"inject","z":"26a8be47.ed6452","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":580,"y":320,"wires":[["99b13374.187cf"]]},{"id":"d94b539d.052b7","type":"change","z":"26a8be47.ed6452","name":"Without bitmask","rules":[{"t":"set","p":"payload.data.parameter","pt":"msg","to":"17","tot":"str"},{"t":"set","p":"payload.data.value","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":779,"y":382,"wires":[["9233a7a6.019a78"]]},{"id":"99b13374.187cf","type":"change","z":"26a8be47.ed6452","name":"With bitmask","rules":[{"t":"set","p":"payload.data.parameter","pt":"msg","to":"16","tot":"num"},{"t":"set","p":"payload.data.bitmask","pt":"msg","to":"255","tot":"str"},{"t":"set","p":"payload.data.value","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":769,"y":319,"wires":[["9233a7a6.019a78"]]},{"id":"9233a7a6.019a78","type":"api-call-service","z":"26a8be47.ed6452","name":"Office","server":"456659de.370498","version":1,"debugenabled":false,"service_domain":"zwave_js","service":"set_config_parameter","entityId":"light.office","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1001,"y":347,"wires":[[]]},{"id":"94ca593e.fcc5b8","type":"inject","z":"26a8be47.ed6452","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":580,"y":383,"wires":[["d94b539d.052b7"]]},{"id":"456659de.370498","type":"server","name":"AvilaSmartHome","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]