Exec Node with Variables

I'm able to execute this: /usr/bin/avahi-browse -t _hap._tcp | grep "03V8" | wc -l at the command line and I can also feed it to an Exec node [with Append msg.payload checked] to get the same output.

The value being grepped for, "03V8", identifies one of several devices, so I'd like to find a way that I can use a variable or template that I can update independently.

Is this possible please?

Hi @lorccan

You could make use of a subflow?
passing in only the "03V8" value to it?

[{"id":"793c0c2e9751236e","type":"subflow","name":"avahi-browse","info":"","category":"","in":[{"x":155,"y":195,"wires":[{"id":"a85816385af348e7"}]}],"out":[{"x":770,"y":180,"wires":[{"id":"d13e98cb53d509d6","port":0}]}],"env":[],"meta":{},"color":"#3FADB5","icon":"node-red-contrib-tplink-tapo-connect-api/icon-command.png"},{"id":"d13e98cb53d509d6","type":"exec","z":"793c0c2e9751236e","command":"/usr/bin/avahi-browse","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":560,"y":195,"wires":[[],[],[]]},{"id":"a85816385af348e7","type":"function","z":"793c0c2e9751236e","name":"function 1","func":"msg.payload = ` -t _hap._tcp | grep \"${msg.payload}\" | wc -l`\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":195,"wires":[["d13e98cb53d509d6"]]},{"id":"0e6a1b19b997b779","type":"subflow:793c0c2e9751236e","z":"fa8c241adfe1f04a","name":"","x":495,"y":565,"wires":[[]]}]

EDIT
The icon I used, is from a node I use - so you may need to edit the subflow

Here's an alternative approach using a template to assemble the Bash command line.
One advantage to using a template is that the complete command line is available for inspection via a debug node

[{"id":"4d82f796d89d6044","type":"inject","z":"db04fd79f3a93d19","name":"Pass search string msg.payload","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"03V8","payloadType":"str","x":190,"y":780,"wires":[["f66b1b60040f4067"]]},{"id":"f66b1b60040f4067","type":"template","z":"db04fd79f3a93d19","name":"Bash","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"/usr/bin/avahi-browse -t _hap._tcp | grep {{payload}} | wc -l\n","output":"str","x":410,"y":780,"wires":[["d9290c0c62e0f7c0","cc39d099b49cf9fe"]]},{"id":"d9290c0c62e0f7c0","type":"exec","z":"db04fd79f3a93d19","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":710,"y":780,"wires":[["af8dbd68b05f6313"],["af8dbd68b05f6313"],[]]},{"id":"cc39d099b49cf9fe","type":"debug","z":"db04fd79f3a93d19","name":"Full Script","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":820,"wires":[]},{"id":"af8dbd68b05f6313","type":"debug","z":"db04fd79f3a93d19","name":"output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":780,"wires":[]}]

Thanks. For some reason I was unable to import the whole flow - I just got the 'avahi-browse' node. It was probably to do with the missing icon that you mentioned. Anyway, I have a solution that works for me now.

Thank you. That's just what I needed.

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