[Feature Request]Add ability to use buffer type in switch node

I'm sending 3 byte RGB buffers down a flow and wanted to detect [0,0,0] and was surprised to find that the switch node doesn't seem to be able to do this

I tried a bit of JSONata but wasn't successful with that

Could the ability be added to node please?

Hi @cymplecy

If your payload for example is [0,0,0]

you can use the $sum JSONata function

$sum takes an array of values and returns the result after summing them.

PS: Im surprised I was able to test that after a few Ales! :smiley:

1 Like

Your test was a little flawed as it would pass [0,0,0,0] and others.
try
$count($$.payload.*[$ = 0]) = 3

[edit]still not perfect

This would be better
$count($$.payload.*) = 3 and $count($$.payload.*[$ = 0]) = 3
or
$count($$.payload.*) = 3 and $sum($$.payload.*) = 0
or
$sum($$.payload.*) + $count($$.payload.*)
== 3

[edit] you could test for any buffer using an expression like this
$not(false in $$.payload.*#$i.([0,0,0][$i] = $))
where 0,0,0 could be replaced with any buffer combination for comparison.

2 Likes

Dang it! :nerd_face:

I tried the 1st and the last one but neither worked for me.

The incoming msg.payload is a 3 byte buffer

@E1cid

Your up - my JSONata isn’t up to your standards :nerd_face:

Works for me please supply your test flow.

[{"id":"6f18bc6d7dd7174f","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[0,25,0,0]","payloadType":"bin","x":70,"y":1480,"wires":[["3e2bbff42a84efa4"]]},{"id":"3e2bbff42a84efa4","type":"switch","z":"d1395164b4eec73e","name":"","property":"$count($$.payload.*) = 3 and $count($$.payload.*[$ = 0]) = 3","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":270,"y":1440,"wires":[["4dfb5d80e28a7ca8"]]},{"id":"50999b455bd5c850","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[0,0,0]","payloadType":"bin","x":70,"y":1620,"wires":[["3e2bbff42a84efa4"]]},{"id":"a1a205e83f1b444c","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1 ,0,0]","payloadType":"bin","x":70,"y":1520,"wires":[["3e2bbff42a84efa4"]]},{"id":"6ea79d895c640869","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1 ,0,0,0]","payloadType":"bin","x":70,"y":1560,"wires":[["3e2bbff42a84efa4"]]},{"id":"4dfb5d80e28a7ca8","type":"debug","z":"d1395164b4eec73e","name":"debug 2456","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":450,"y":1560,"wires":[]},{"id":"0f23ca3219ee63b6","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$not(false in $$.payload.*#$i.([0,25,0][$i] = $))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":1560,"wires":[["4dfb5d80e28a7ca8"]]}]
1 Like

I wasn't setting the 1st box to JSONata - I'd just left it at ==
Silly me

image

@marcus-j-davies is 3 sheets to the wind, whats your excuse?

2 Likes

I'm from Newcastle

3 Likes

I was betting your were mortal to.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.