Node-Red Flow Samples/Sharing

https://nodered.org/docs/user-guide/editor/workspace/subflows

2 Likes

Not sure what you mean here? If you mean turn "send events" on/off with subflow properties - you can't.

That was what I was trying to do... Darn.

You could always make a feature request to @fblackburn to make the "send events" option settable by variable. Not sure how many people want that / how hard it is to do. The code is currently expecting it to be set at creation time, though, so probably not a completely trivial change.

I usually keep my HE Nodes out of my subflows just to keep things simple.

Yeah, What I have works, and my want was for cosmetic reasons. I'll pass on asking for just that.

1 Like

Index organization Ideas?

Thanks to all that have posts samples. We now have almost 20 and starting to get a good variety. The time has come to consider organizing the index. I am not going to get time to work on it until this afternoon, or tomorrow afternoon. Being unsure of the best way to approach this I'd love to hear anyone's ideas on how the links should be organized.

Thanks again to all that share. It's great to see other uses of nodes I was not aware of. I'm a visual learning and these samples help a ton!!

2 Likes

Put them on GitHub?.. that way folks can update as needed. You can also put github links here if necessary.

1 Like

Not against that, but still would need to be organized. Like by category (would need some categories), or 'major' nodes used, or something.

Stupid JSONATA Tricks...

In JSONATA you can grab the value of a property of the message object by doing something like this:

$lookup('payload');

If you try and go "deeper" this does not work:

$lookup('payload.value');

As far as I can tell there is no simple command to do this in JSONATA directly.. but with some functional/recursion trickery you can:

(
  $getkey := function($x,$keyVal){
	$count($split($keyVal,'.')) > 1 
	? $x ~> $lookup($split($keyVal,'.')[0]) ~> $getkey($substringAfter($keyVal, $split($keyVal,'.')[0] & '.'))
	: $lookup($x,$keyVal)
  };
  $getkey(msg,'payload.s1.s2.s3.s4');
)
	
Stupid JSONATA tricks example

[{"id":"9fb34974.d1ccd8","type":"debug","z":"af91369d.586338","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"(   $getkey := function($x,$keyVal){ \t$count($split($keyVal,'.')) > 1  \t? $x ~> $lookup($split($keyVal,'.')[0]) ~> $getkey($substringAfter($keyVal, $split($keyVal,'.')[0] & '.')) \t: $lookup($x,$keyVal)   };   $getkey(msg,'payload.s1.s2.s3.s4'); )","targetType":"jsonata","statusVal":"","statusType":"auto","x":580,"y":780,"wires":[]},{"id":"71eadc98.ee5464","type":"inject","z":"af91369d.586338","name":"","props":[{"p":"payload.s1.s2.s3.s4","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":390,"y":780,"wires":[["9fb34974.d1ccd8"]]}]

The above entry creates a function called "$getkey" that calls itself until the entire $keyVal string runs out of "."'s at which point it returns the $lookup() of the final object and $keyVal and unwinds.

Why do this? Well you might store a certain property name in a global or in the case of subflows have a property/env variable that contains the property name you want to use. Of course you could also use a function node but where is the fun in that? :wink:

edit: wanted to be clear that the $getkey parameter used i.e. "payload.s1.s2...." is arbitrary. Likely you would replace it with $env('SOME_VAR'), $globalContext('someVAR') or msg.someProperty etc.

1 Like

Maybe something abstract.. like these. But I'm thinking you don't want to confine a sequence to necessarily one category.

"Timed Based Sequences"
"Weather/Environmental Based Sequences"
"Geo and Presence Based Sequences"
"Logic Sequences"..
"MQTT Sequences"
"Startup/Initialization Sequences"
"Health and Alert Based Sequences"
"Switch and Change Node Examples"
etc.

Help, please. I just don't know enough to pull off what I thought was a very simple combination of @aaiyar's Node-Red Flow Samples/Sharing and @pat.richards' Node-Red Flow Samples/Sharing.

[{"id":"29d65b9e.c42c44","type":"subflow","name":"SMS via gmail","info":"","category":"","in":[{"x":40,"y":60,"wires":[{"id":"3be4d5f8.c4943a"}]}],"out":[],"env":[],"color":"#DDAA99"},{"id":"3be4d5f8.c4943a","type":"e-mail","z":"29d65b9e.c42c44","server":"smtp.gmail.com","port":"465","secure":true,"tls":true,"name":"@vtext.com","dname":"Message to Steve via SMS","x":220,"y":60,"wires":[]},{"id":"d0f2cf2d.02296","type":"tab","label":"Network Speed Test","disabled":false,"info":""},{"id":"14926736.f53d09","type":"template","z":"d0f2cf2d.02296","name":"time","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{mydate}} {{mytimes}}","output":"str","x":630,"y":380,"wires":[["271a0f38.1d68e"]]},{"id":"e19e8754.effd38","type":"switch","z":"d0f2cf2d.02296","name":"down < 90","property":"payload.speeds.download","propertyType":"msg","rules":[{"t":"lt","v":"90","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":650,"y":660,"wires":[["5b9a7443.f207ec"]]},{"id":"5d269750.f6f478","type":"speedtest","z":"d0f2cf2d.02296","name":"Speedtest","serverId":"","maxTime":"10000","x":340,"y":360,"wires":[["5f640878.bb3168","4c8b7d77.c30684","d5c4d352.b3681","67e5ffd4.0e59b","48a6a1f5.c7025","96f73373.d1fe9","5e857b8.6d6c184","21c73f12.baefa","ba1a1914.db0128","4cc3c92f.905318"]]},{"id":"5b9a7443.f207ec","type":"change","z":"d0f2cf2d.02296","name":"Speed Test","rules":[{"t":"set","p":"topic","pt":"msg","to":"Speed Test","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":660,"wires":[["b96697dc.0a9f38"]]},{"id":"d5c4d352.b3681","type":"change","z":"d0f2cf2d.02296","name":"download","rules":[{"t":"set","p":"topic","pt":"msg","to":"Download","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"payload.speeds.download","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":300,"wires":[["d6cb3a8b.a43188","a03bad9f.8c32a"]]},{"id":"67e5ffd4.0e59b","type":"change","z":"d0f2cf2d.02296","name":"upload","rules":[{"t":"set","p":"topic","pt":"msg","to":"Upload","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"payload.speeds.upload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":340,"wires":[["a936c1bf.e3a53","a03bad9f.8c32a"]]},{"id":"48a6a1f5.c7025","type":"change","z":"d0f2cf2d.02296","name":"ping","rules":[{"t":"set","p":"topic","pt":"msg","to":"Ping","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"payload.server.ping","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":420,"wires":[["b446897a.e37d58","a1598f78.b238c"]]},{"id":"96f73373.d1fe9","type":"change","z":"d0f2cf2d.02296","name":"distance","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.server.distanceMi","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"Distance","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":460,"wires":[["7dc67cd2.351a64","a1598f78.b238c"]]},{"id":"5e857b8.6d6c184","type":"change","z":"d0f2cf2d.02296","name":"ISP","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.server.sponsor","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":500,"wires":[["6887d568.c8094c"]]},{"id":"b96697dc.0a9f38","type":"template","z":"d0f2cf2d.02296","name":"SMS","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Internet speed was {{payload.speeds.download}}/{{payload.speeds.upload}} (down/up Mbits/s) at {{mytimes}} on {{mymonthn}}/{{mydom}}. Speedtest server was {{payload.server.sponsor}}.","output":"str","x":1030,"y":660,"wires":[["9c78eadf.b64358"]]},{"id":"46543bab.6432c4","type":"file","z":"d0f2cf2d.02296","name":"Speed Test Data Save","filename":"/home/steve/.node-red/data/speedtest/speedtestData.json","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":1160,"y":100,"wires":[[]]},{"id":"87dd27d9.d19038","type":"json","z":"d0f2cf2d.02296","name":"","x":1130,"y":40,"wires":[["a03bad9f.8c32a"]]},{"id":"bb03c8f5.5a64f8","type":"file","z":"d0f2cf2d.02296","name":"Speed Test Data Save","filename":"/home/steve/.node-red/data/speedtest/speedtestDataPD.json","appendNewline":false,"createDir":false,"overwriteFile":"true","x":1160,"y":180,"wires":[[]]},{"id":"d1ba11da.f8075","type":"json","z":"d0f2cf2d.02296","name":"","x":1130,"y":280,"wires":[["a1598f78.b238c"]]},{"id":"d67fab79.b60ec8","type":"file in","z":"d0f2cf2d.02296","name":"Speed Test Data Restore","filename":"/home/steve/.node-red/data/speedtest/speedtestData.json","format":"utf8","x":1170,"y":140,"wires":[["87dd27d9.d19038"]]},{"id":"4e673693.f6b888","type":"file in","z":"d0f2cf2d.02296","name":"Speed Test Data Restore","filename":"/home/steve/.node-red/data/speedtest/speedtestDataPD.json","format":"utf8","x":1170,"y":220,"wires":[["d1ba11da.f8075"]]},{"id":"c061c2b1.31c4c","type":"inject","z":"d0f2cf2d.02296","name":"","props":[{"p":"payload","v":"restore","vt":"str"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":true,"topic":"","payload":"restore","payloadType":"str","x":900,"y":160,"wires":[["d67fab79.b60ec8","4e673693.f6b888"]]},{"id":"7e9425db.977cfc","type":"ui_button","z":"d0f2cf2d.02296","name":"","group":"62ee13da.6e537c","order":3,"width":0,"height":0,"passthru":false,"label":"SpeedTest Now!","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"date","topic":"","x":170,"y":320,"wires":[["5d269750.f6f478"]]},{"id":"271a0f38.1d68e","type":"ui_text","z":"d0f2cf2d.02296","group":"62ee13da.6e537c","order":6,"width":0,"height":0,"name":"Last Speedtest","label":"Last Speedtest","format":"<font color=\"cyan\">{{msg.payload}}</font>","layout":"col-center","x":900,"y":380,"wires":[]},{"id":"b446897a.e37d58","type":"ui_text","z":"d0f2cf2d.02296","group":"62ee13da.6e537c","order":4,"width":0,"height":0,"name":"","label":"Ping Time","format":"<font color=\"cyan\">{{msg.payload}}</font>","layout":"col-center","x":890,"y":420,"wires":[]},{"id":"7dc67cd2.351a64","type":"ui_text","z":"d0f2cf2d.02296","group":"62ee13da.6e537c","order":5,"width":0,"height":0,"name":"","label":"Distance","format":"<font color=\"cyan\">{{msg.payload}} mi</font>","layout":"col-center","x":880,"y":460,"wires":[]},{"id":"6887d568.c8094c","type":"ui_text","z":"d0f2cf2d.02296","group":"62ee13da.6e537c","order":2,"width":0,"height":0,"name":"","label":"Hosted By","format":"<font color=\"cyan\">{{msg.payload}}</font>","layout":"col-center","x":890,"y":500,"wires":[]},{"id":"d6cb3a8b.a43188","type":"ui_gauge","z":"d0f2cf2d.02296","name":"","group":"62ee13da.6e537c","order":7,"width":0,"height":0,"gtype":"gage","title":"Download Speed","label":"Download Mbits","format":"{{value}}","min":0,"max":"150","colors":["#ff002d","#e4b400","#03f81f"],"seg1":"50","seg2":"100","x":910,"y":300,"wires":[]},{"id":"a936c1bf.e3a53","type":"ui_gauge","z":"d0f2cf2d.02296","name":"","group":"62ee13da.6e537c","order":8,"width":0,"height":0,"gtype":"gage","title":"Upload Speed","label":"Upload MBits","format":"{{value}}","min":0,"max":"15","colors":["#ff002d","#ffed36","#03f81f"],"seg1":"2","seg2":"8","x":900,"y":340,"wires":[]},{"id":"a03bad9f.8c32a","type":"ui_chart","z":"d0f2cf2d.02296","name":"Performance Chart","group":"89577c58.28a14","order":2,"width":12,"height":6,"label":"Performance Chart","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"2","removeOlderPoints":"","removeOlderUnit":"86400","cutout":"","useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":910,"y":100,"wires":[["46543bab.6432c4"]]},{"id":"a1598f78.b238c","type":"ui_chart","z":"d0f2cf2d.02296","name":"Latency Chart","group":"89577c58.28a14","order":4,"width":12,"height":6,"label":"Latency Chart","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"2","removeOlderPoints":"","removeOlderUnit":"86400","cutout":"","useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":900,"y":220,"wires":[["bb03c8f5.5a64f8"]]},{"id":"2a109aa3.af9a36","type":"cronplus","z":"d0f2cf2d.02296","name":"30 past every 4 hours","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"30 past every 4 hours","topic":"30 past every 4 hours","payloadType":"str","payload":"start","expressionType":"cron","expression":"30 0,4,8,12,16,20 * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":140,"y":400,"wires":[["5d269750.f6f478"]]},{"id":"5f640878.bb3168","type":"simpletime","z":"d0f2cf2d.02296","name":"","mydate":true,"myymd":true,"myyear":true,"mymonth":true,"mymonthn":true,"mydom":true,"mydoy":true,"myday":true,"myhourpm":true,"myhour":true,"mytime":true,"mytimes":true,"myminute":true,"myminutes":true,"mysecond":true,"mymillis":true,"myepoch":true,"myrawdate":true,"mypm":true,"x":330,"y":540,"wires":[["14926736.f53d09","e19e8754.effd38"]]},{"id":"9c78eadf.b64358","type":"subflow:29d65b9e.c42c44","z":"d0f2cf2d.02296","name":"","x":1180,"y":660,"wires":[]},{"id":"d9be25fd.d45958","type":"influxdb out","z":"d0f2cf2d.02296","influxdb":"9033c1be.b67f8","name":"Influxdb Upload","measurement":"Upload","precision":"","retentionPolicy":"","x":900,"y":580,"wires":[]},{"id":"32aff5a6.03155a","type":"influxdb out","z":"d0f2cf2d.02296","influxdb":"9033c1be.b67f8","name":"Influxdb Download","measurement":"Download","precision":"","retentionPolicy":"","x":910,"y":540,"wires":[]},{"id":"7dbf4a2b.9de8c4","type":"influxdb out","z":"d0f2cf2d.02296","influxdb":"9033c1be.b67f8","name":"Influxdb Ping","measurement":"Ping","precision":"","retentionPolicy":"","x":890,"y":620,"wires":[]},{"id":"4c8b7d77.c30684","type":"debug","z":"d0f2cf2d.02296","name":"msg from Speedtest","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":240,"wires":[]},{"id":"ba1a1914.db0128","type":"function","z":"d0f2cf2d.02296","name":"Add ms unit tag","func":"// create object and populate with Influx tags\nvar tags = {}\ntags.topic = \"Ping\"\ntags.unit = \"ms\"\n\n// create and fill array for the payload\nvar arr = [] \narr[0] = msg.payload.server.ping // the measurement value\narr[1] = tags\n\n// put the array into msg.payload and send it off\nmsg.payload = arr\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":620,"wires":[[]]},{"id":"21c73f12.baefa","type":"function","z":"d0f2cf2d.02296","name":"Add Mbps unit tag","func":"// create object and populate with Influx tags\nvar tags = {}\ntags.topic = \"Upload\"\ntags.unit = \"Mbps\"\n\n// create and fill array for the payload\nvar arr = [] \narr[0] = msg.payload.speeds.upload  // the measurement value\narr[1] = tags\n\n// put the array into msg.payload and send it off\nmsg.payload = arr\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":670,"y":580,"wires":[[]]},{"id":"4cc3c92f.905318","type":"function","z":"d0f2cf2d.02296","name":"Add Mbps unit tag","func":"// create object and populate with Influx tags\nvar tags = {}\ntags.unit = \"Mbps\"\n\n// create and fill array for the payload\nvar arr = [] \narr[0] = msg.payload.speeds.download  // the measurement value\narr[1] = tags\n\n// put the array into msg.payload and send it off\nmsg.payload = arr\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":670,"y":540,"wires":[["251c879b.80eab8","32aff5a6.03155a"]]},{"id":"251c879b.80eab8","type":"debug","z":"d0f2cf2d.02296","name":"Download","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1160,"y":500,"wires":[]},{"id":"62ee13da.6e537c","type":"ui_group","z":"d0f2cf2d.02296","name":"Graphs","tab":"55f2b57d.416b5c","order":1,"disp":false,"width":"6","collapse":false},{"id":"89577c58.28a14","type":"ui_group","z":"d0f2cf2d.02296","name":"Charts","tab":"55f2b57d.416b5c","order":2,"disp":false,"width":"12","collapse":false},{"id":"9033c1be.b67f8","type":"influxdb","z":"d0f2cf2d.02296","hostname":"localhost","port":"8086","protocol":"http","database":"Internet","name":"InfluxDB on pvr","usetls":false,"tls":""},{"id":"55f2b57d.416b5c","type":"ui_tab","z":"d0f2cf2d.02296","name":"Internet Speed","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

ALL that I need to add is the unit for each measurement. I thought I had the idea from Send csv file to influxdb using node-red - General - Node-RED Forum but I don't because this ain't makin' it.

It looks like you're using the same influxDB node that I'm using so I'll show you what one of my msg objects looks like. I haven't used arrays in the payload so I'm not sure how the other members are doing it (many ways to skin a cat). This works for me though and I could do it with a couple of change nodes vs. a function. Hopefully this will help you and not confuse you more?

(I removed some of the additional tags that it didn't look like you were interested in, but you can put however many you want within the payload object.)

{
 "payload":
  {
   "value":103.432,
   "optional tag":"clever displayName",
   "unit":"Mbps"
  },
 "topic":"speedtest",
 "measurement":"Download",  //Optional, but you can use this to feed a single influxDB node vs separate ones for each measurement
 "_msgid":"187fb67b.d3782a",
}
2 Likes

from the doc for the influxdb nodes

msg.payload = {
numValue: 123.0,
strValue: "message",
randomValue: Math.random()*10
}
return msg;

1 Like

Ahem, look at the docs you say :roll_eyes:...didn't even think to look there. D'oh! Color me silly.

Thanks so much for the example to both you and @harold.min.

I expected it to be simple, like I said, and it is. And to think I spent hours trying to complicate it. :crazy_face:

msg.payload={
"value":msg.payload.speeds.download,
"unit":"Mbps"
}
return msg;

I wish I could say I looked at the node documentation first... I got lost in the InfluxDB API documentation for about an hour before kicking myself.

1 Like

LOL only reason I did is because NR has been kicking my butt a bit even then I had to take the sample code import it to understand

and fyi I was just giving credit to where I found the code not be one of those RTFM people :slight_smile:

1 Like

Funny thing is that I'm usually the RTFM type but here I was relying on the node info in the sidebar which I wrongly assumed had all the goods. Another example of ASSuME.

@LosinIt just a thought now that you have multiple fields working you could just have one influxdb table for internet stats

I think

1 Like

And I'd like to but I'm not sure of the formatting... which brings up a question I was about to ask you:

How does one get to the -contrib- docs? I always check them via the option when installing to the palette but I'm not finding them on the NR site and nothing in the community there either (that I've found).