btsimonh / node-red-contrib-flowman

Node-red nodes to manipulate flows
MIT License
1 stars 2 forks source link

Dynamically loading (adding) a flow with Json input #5

Closed happytm closed 5 years ago

happytm commented 5 years ago

Hi Simon, I thank you for this node and I can find only this node in library to add flows to existing running instance of node-red. I tried saveflow and it is working very nicely and it is very useful feature. I am trying to add a flow to my node-red but I get message saying:

2/3/2019, 7:07:38 PMnode: 69dd7691.348db8 msg : error "TypeError: Cannot read property 'nodes' of undefined"

I am using following flow to implement it:

[{"id":"69dd7691.348db8","type":"addflow","z":"c0844d0e.ea02c","name":"","x":640,"y":580,"wires":[[]]},{"id":"82ac311.50e04d","type":"function","z":"c0844d0e.ea02c","name":"Devices","func":"var m1 = {payload:msg.payload.System.Name,topic:\"name\"};\nvar m2 = {payload:msg.payload.Sensors[0].TaskValues[0].Name,topic:\"SensorValue\"};\nvar m3 = {payload:msg.payload.Sensors[1].TaskValues[0].Name,topic:\"SensorValue\"};\nvar m4 = {payload:msg.payload.Sensors[2].TaskValues[0].Name,topic:\"Sensorvalue\"};\n\nvar m5 = {\n\t\"id\": \"b23f10d3.a520b\",\n\t\"label\": \"Room Template\",\n\t\"nodes\": [{\n\t\t\t\"id\": \"c152d520.662a98\",\n\t\t\t\"type\": \"switch\",\n\t\t\t\"z\": \"b23f10d3.a520b\",\n\t\t\t\"name\": \"Livingroom\",\n\t\t\t\"property\": \"topic\",\n\t\t\t\"propertyType\": \"msg\",\n\t\t\t\"rules\": [\n\t\t\t\t{\n\t\t\t\t\t\"t\": \"cont\",\n\t\t\t\t\t\"v\": \"uptime\",\n\t\t\t\t\t\"vt\": \"str\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"t\": \"cont\",\n\t\t\t\t\t\"v\": \"rssi\",\n\t\t\t\t\t\"vt\": \"str\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"t\": \"cont\",\n\t\t\t\t\t\"v\": \"ram\",\n\t\t\t\t\t\"vt\": \"str\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"t\": \"cont\",\n\t\t\t\t\t\"v\": \"load\",\n\t\t\t\t\t\"vt\": \"str\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"t\": \"cont\",\n\t\t\t\t\t\"v\": \"temprature\",\n\t\t\t\t\t\"vt\": \"str\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"t\": \"cont\",\n\t\t\t\t\t\"v\": \"humidity\",\n\t\t\t\t\t\"vt\": \"str\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"t\": \"cont\",\n\t\t\t\t\t\"v\": \"pressure\",\n\t\t\t\t\t\"vt\": \"str\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"t\": \"cont\",\n\t\t\t\t\t\"v\": \"lux\",\n\t\t\t\t\t\"vt\": \"str\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"t\": \"cont\",\n\t\t\t\t\t\"v\": \"breach\",\n\t\t\t\t\t\"vt\": \"str\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"t\": \"cont\",\n\t\t\t\t\t\"v\": \"oled\",\n\t\t\t\t\t\"vt\": \"str\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"t\": \"cont\",\n\t\t\t\t\t\"v\": \"pin\",\n\t\t\t\t\t\"vt\": \"str\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"t\": \"cont\",\n\t\t\t\t\t\"v\": \"dimvalue\",\n\t\t\t\t\t\"vt\": \"str\"\n\t\t\t\t}\n\t\t\t]\n\t\t\t//[{\"id\":\"98c1390a.706f18\",\"type\":\"subflow\",\"name\":\"Livingroom\",\"info\":\"Fan Number\nFan On/Off\nFan Speed\nSecurity Breach\nAlarm On/Off\nMessage\",\"category\":\"\",\"in\":[{\"x\":40,\"y\":220,\"wires\":[{\"id\":\"64db0c61.1360e4\"}]}],\"out\":[{\"x\":680,\"y\":340,\"wires\":[{\"id\":\"10c43b2c.29e575\",\"port\":0}]}]},{\"id\":\"64db0c61.1360e4\",\"type\":\"switch\",\"z\":\"98c1390a.706f18\",\"name\":\"Livingroom\",\"property\":\"topic\",\"propertyType\":\"msg\",\"rules\":[{\"t\":\"cont\",\"v\":\"uptime\",\"vt\":\"str\"},{\"t\":\"cont\",\"v\":\"rssi\",\"vt\":\"str\"},{\"t\":\"cont\",\"v\":\"ram\",\"vt\":\"str\"},{\"t\":\"cont\",\"v\":\"load\",\"vt\":\"str\"},{\"t\":\"cont\",\"v\":\"temprature\",\"vt\":\"str\"},{\"t\":\"cont\",\"v\":\"humidity\",\"vt\":\"str\"},{\"t\":\"cont\",\"v\":\"pressure\",\"vt\":\"str\"},{\"t\":\"cont\",\"v\":\"lux\",\"vt\":\"str\"},{\"t\":\"cont\",\"v\":\"breach\",\"vt\":\"str\"},{\"t\":\"cont\",\"v\":\"oled\",\"vt\":\"str\"},{\"t\":\"cont\",\"v\":\"pin\",\"vt\":\"str\"},{\"t\":\"cont\",\"v\":\"dimvalue\",\"vt\":\"str\"}],\"checkall\":\"true\",\"repair\":false,\"outputs\":12,\"x\":170,\"y\":220,\"wires\":[[\"d0a2ade6.ada41\"],[\"5bc6f195.e235c\"],[\"d68fae84.1eb28\"],[\"47d7e9d2.b3d908\"],[\"9ae91fc9.4bdaa\"],[\"518f796b.e7faf8\"],[\"fae4e6fd.bbfd78\"],[\"9863844b.a6ad38\"],[\"3b17aa35.3b33b6\"],[\"7a8a3b21.378c34\"],[\"a70013ed.e4d35\"],[\"f2406736.ccda68\",\"38f9a7dd.6340c8\"]]},{\"id\":\"d0a2ade6.ada41\",\"type\":\"ui_text\",\"z\":\"98c1390a.706f18\",\"group\":\"11655475.b9d69c\",\"order\":5,\"width\":\"1\",\"height\":\"1\",\"name\":\"\",\"label\":\"Uptime\",\"format\":\"{{msg.payload}}\",\"layout\":\"col-center\",\"x\":360,\"y\":120,\"wires\":[]},{\"id\":\"47d7e9d2.b3d908\",\"type\":\"ui_text\",\"z\":\"98c1390a.706f18\",\"group\":\"11655475.b9d69c\",\"order\":7,\"width\":\"1\",\"height\":\"1\",\"name\":\"\",\"label\":\"Load\",\"format\":\"{{msg.payload}} %\",\"layout\":\"col-center\",\"x\":356,\"y\":237,\"wires\":[]},{\"id\":\"d68fae84.1eb28\",\"type\":\"ui_text\",\"z\":\"98c1390a.706f18\",\"group\":\"11655475.b9d69c\",\"order\":6,\"width\":\"1\",\"height\":\"1\",\"name\":\"\",\"label\":\"RAM\",\"format\":\"{{msg.payload}}\",\"layout\":\"col-center\",\"x\":355,\"y\":197,\"wires\":[]},{\"id\":\"5bc6f195.e235c\",\"type\":\"ui_text\",\"z\":\"98c1390a.706f18\",\"group\":\"11655475.b9d69c\",\"order\":8,\"width\":\"1\",\"height\":\"1\",\"name\":\"\",\"label\":\"RSSI\",\"format\":\"{{msg.payload}}\",\"layout\":\"col-center\",\"x\":351,\"y\":157,\"wires\":[]},{\"id\":\"f2406736.ccda68\",\"type\":\"ui_switch\",\"z\":\"98c1390a.706f18\",\"name\":\"\",\"label\":\"On/Off\",\"tooltip\":\"Turn Fan On/Off\",\"group\":\"11655475.b9d69c\",\"order\":3,\"width\":\"2\",\"height\":\"1\",\"passthru\":false,\"decouple\":\"false\",\"topic\":\"Livingroom/dimmer/dimvalue/set\",\"style\":\"\",\"onvalue\":\"128\",\"onvalueType\":\"num\",\"onicon\":\"\",\"oncolor\":\"\",\"offvalue\":\"0\",\"offvalueType\":\"num\",\"officon\":\"\",\"offcolor\":\"\",\"x\":350,\"y\":320,\"wires\":[[\"10c43b2c.29e575\",\"dd26b765.23d588\"]]},{\"id\":\"38f9a7dd.6340c8\",\"type\":\"ui_slider\",\"z\":\"98c1390a.706f18\",\"name\":\"\",\"label\":\"Fan Speed\",\"tooltip\":\"Adjust Fan Speed\",\"group\":\"11655475.b9d69c\",\"order\":4,\"width\":\"4\",\"height\":\"1\",\"passthru\":false,\"outs\":\"end\",\"topic\":\"Livingroom/dimmer/dimvalue/set\",\"min\":0,\"max\":\"128\",\"step\":1,\"x\":330,\"y\":360,\"wires\":[[\"10c43b2c.29e575\",\"dd26b765.23d588\"]]},{\"id\":\"a70013ed.e4d35\",\"type\":\"ui_numeric\",\"z\":\"98c1390a.706f18\",\"name\":\"\",\"label\":\"Fan\",\"tooltip\":\"Select Fan\",\"group\":\"11655475.b9d69c\",\"order\":2,\"width\":\"2\",\"height\":\"1\",\"passthru\":false,\"topic\":\"Livingroom/dimmer/pin/set\",\"format\":\"{{value}}\",\"min\":\"6\",\"max\":\"9\",\"step\":1,\"x\":350,\"y\":280,\"wires\":[[\"10c43b2c.29e575\",\"dd26b765.23d588\"]]},{\"id\":\"518f796b.e7faf8\",\"type\":\"ui_gauge\",\"z\":\"98c1390a.706f18\",\"name\":\"Humidity\",\"group\":\"11655475.b9d69c\",\"order\":10,\"width\":\"1\",\"height\":\"1\",\"gtype\":\"gage\",\"title\":\"Humidity\",\"label\":\"\",\"format\":\"{{value}} %\",\"min\":\"40\",\"max\":\"100\",\"colors\":[\"#00b500\",\"#e6e600\",\"#ca3838\"],\"seg1\":\"\",\"seg2\":\"\",\"x\":520,\"y\":160,\"wires\":[]},{\"id\":\"9ae91fc9.4bdaa\",\"type\":\"ui_gauge\",\"z\":\"98c1390a.706f18\",\"name\":\"Temperature\",\"group\":\"11655475.b9d69c\",\"order\":9,\"width\":\"1\",\"height\":\"1\",\"gtype\":\"gage\",\"title\":\"Temperature\",\"label\":\"\",\"format\":\"{{value}} F\",\"min\":\"45\",\"max\":\"90\",\"colors\":[\"#00b500\",\"#e6e600\",\"#ca3838\"],\"seg1\":\"\",\"seg2\":\"\",\"x\":530,\"y\":120,\"wires\":[]},{\"id\":\"9863844b.a6ad38\",\"type\":\"ui_gauge\",\"z\":\"98c1390a.706f18\",\"name\":\"Luminocity\",\"group\":\"11655475.b9d69c\",\"order\":12,\"width\":\"1\",\"height\":\"1\",\"gtype\":\"gage\",\"title\":\"Luminocity\",\"label\":\"\",\"format\":\"{{value}} Lux\",\"min\":0,\"max\":10,\"colors\":[\"#00b500\",\"#e6e600\",\"#ca3838\"],\"seg1\":\"\",\"seg2\":\"\",\"x\":530,\"y\":240,\"wires\":[]},{\"id\":\"fae4e6fd.bbfd78\",\"type\":\"ui_gauge\",\"z\":\"98c1390a.706f18\",\"name\":\"Pressure\",\"group\":\"11655475.b9d69c\",\"order\":11,\"width\":\"1\",\"height\":\"1\",\"gtype\":\"gage\",\"title\":\"Pressure\",\"label\":\"\",\"format\":\"{{value}} Kpa\",\"min\":0,\"max\":10,\"colors\":[\"#00b500\",\"#e6e600\",\"#ca3838\"],\"seg1\":\"\",\"seg2\":\"\",\"x\":520,\"y\":200,\"wires\":[]},{\"id\":\"62429c9e.e15b24\",\"type\":\"ui_switch\",\"z\":\"98c1390a.706f18\",\"name\":\"Alarm\",\"label\":\"On/Off\",\"tooltip\":\"Turn Alarm On/Off\",\"group\":\"11655475.b9d69c\",\"order\":14,\"width\":\"2\",\"height\":\"1\",\"passthru\":true,\"decouple\":\"false\",\"topic\":\"Livingroom/alarm/set\",\"style\":\"\",\"onvalue\":\"On\",\"onvalueType\":\"str\",\"onicon\":\"\",\"oncolor\":\"\",\"offvalue\":\"Off\",\"offvalueType\":\"str\",\"officon\":\"\",\"offcolor\":\"\",\"x\":330,\"y\":440,\"wires\":[[\"1a12314b.2a0a4f\",\"d23663bf.d68cd\"]]},{\"id\":\"3b17aa35.3b33b6\",\"type\":\"ui_text_input\",\"z\":\"98c1390a.706f18\",\"name\":\"Security\",\"label\":\"Security\",\"tooltip\":\"Watch for Security breach\",\"group\":\"11655475.b9d69c\",\"order\":13,\"width\":\"2\",\"height\":\"1\",\"passthru\":true,\"mode\":\"text\",\"delay\":300,\"topic\":\"Livingroom/breach/set\",\"x\":320,\"y\":400,\"wires\":[[\"10c43b2c.29e575\"]]},{\"id\":\"10c43b2c.29e575\",\"type\":\"join\",\"z\":\"98c1390a.706f18\",\"name\":\"Announce\",\"mode\":\"custom\",\"build\":\"string\",\"property\":\"payload\",\"propertyType\":\"msg\",\"key\":\"topic\",\"joiner\":\"\\n\",\"joinerType\":\"str\",\"accumulate\":false,\"timeout\":\"5\",\"count\":\"1\",\"reduceRight\":false,\"reduceExp\":\"\",\"reduceInit\":\"\",\"reduceInitType\":\"\",\"reduceFixup\":\"\",\"x\":540,\"y\":340,\"wires\":[[]]},{\"id\":\"1a12314b.2a0a4f\",\"type\":\"mqtt out\",\"z\":\"98c1390a.706f18\",\"name\":\"\",\"topic\":\"\",\"qos\":\"\",\"retain\":\"\",\"broker\":\"640a3afa.1e8d84\",\"x\":550,\"y\":380,\"wires\":[]},{\"id\":\"dd26b765.23d588\",\"type\":\"batch\",\"z\":\"98c1390a.706f18\",\"name\":\"2 Together\",\"mode\":\"count\",\"count\":\"2\",\"overlap\":0,\"interval\":10,\"allowEmptySequence\":false,\"topics\":[],\"x\":540,\"y\":300,\"wires\":[[\"1a12314b.2a0a4f\"]]},{\"id\":\"c83afd9d.d76fc\",\"type\":\"ping\",\"z\":\"98c1390a.706f18\",\"name\":\"Ken\",\"host\":\"10.1.10.27\",\"timer\":\"20\",\"x\":50,\"y\":340,\"wires\":[[\"3668d21f.32913e\"]]},{\"id\":\"3668d21f.32913e\",\"type\":\"switch\",\"z\":\"98c1390a.706f18\",\"name\":\"\",\"property\":\"payload\",\"propertyType\":\"msg\",\"rules\":[{\"t\":\"false\"}],\"checkall\":\"true\",\"repair\":false,\"outputs\":1,\"x\":170,\"y\":340,\"wires\":[[\"fedda170.a6d4b\"]]},{\"id\":\"cec78721.5e9228\",\"type\":\"rbe\",\"z\":\"98c1390a.706f18\",\"name\":\"Block \",\"func\":\"rbe\",\"gap\":\"\",\"start\":\"\",\"inout\":\"out\",\"property\":\"payload\",\"x\":670,\"y\":440,\"wires\":[[\"10c43b2c.29e575\"]]},{\"id\":\"d23663bf.d68cd\",\"type\":\"change\",\"z\":\"98c1390a.706f18\",\"name\":\"Alarm Status\",\"rules\":[{\"t\":\"change\",\"p\":\"payload\",\"pt\":\"msg\",\"from\":\"On\",\"fromt\":\"str\",\"to\":\"Alarm is set to On\",\"tot\":\"str\"},{\"t\":\"change\",\"p\":\"payload\",\"pt\":\"msg\",\"from\":\"Off\",\"fromt\":\"str\",\"to\":\"Alarm is set to Off\",\"tot\":\"str\"}],\"action\":\"\",\"property\":\"\",\"from\":\"\",\"to\":\"\",\"reg\":false,\"x\":510,\"y\":440,\"wires\":[[\"cec78721.5e9228\"]]},{\"id\":\"fedda170.a6d4b\",\"type\":\"change\",\"z\":\"98c1390a.706f18\",\"name\":\"Alarm On\",\"rules\":[{\"t\":\"change\",\"p\":\"payload\",\"pt\":\"msg\",\"from\":\"false\",\"fromt\":\"bool\",\"to\":\"On\",\"tot\":\"str\"}],\"action\":\"\",\"property\":\"\",\"from\":\"\",\"to\":\"\",\"reg\":false,\"x\":140,\"y\":440,\"wires\":[[\"62429c9e.e15b24\"]]},{\"id\":\"8ab04cbb.66453\",\"type\":\"debug\",\"z\":\"98c1390a.706f18\",\"name\":\"\",\"active\":true,\"tosidebar\":true,\"console\":false,\"tostatus\":false,\"complete\":\"false\",\"x\":350,\"y\":540,\"wires\":[]},{\"id\":\"9d5c4be4.4f4ce8\",\"type\":\"function\",\"z\":\"98c1390a.706f18\",\"name\":\"Sensors\",\"func\":\"var m1 = {payload : msg.payload.System.Build,topic:\\"build\\"};\nvar m2 = {payload:msg.payload.System.Plugins,topic:\\"plugins\\"};\nvar m3 = {payload:msg.payload.System[\\"Local time\\"],topic:\\"time\\"};\nvar m4 = {payload:msg.payload.System.Unit,topic:\\"unit\\"};\nvar m5 = {payload:msg.payload.System.Name,topic:\\"name\\"};\nvar m6 = {payload:msg.payload.System.Uptime,topic:\\"uptime\\"};\nvar m7 = {payload:msg.payload.System.Load,topic:\\"load\\"};\nvar m8 = {payload:msg.payload.System[\\"Free RAM\\"],topic:\\"ram\\"};\nvar m9 = {payload:msg.payload.WiFi.IP,topic:\\"ip\\"};\nvar m10 = {payload:msg.payload.WiFi[\\"MAC address\\"],topic:\\"mac\\"};\nvar m11 = {payload:msg.payload.WiFi.SSID,topic:\\"ssid\\"};\nvar m12 = {payload:msg.payload.WiFi.RSSI,topic:\\"rssi\\"};\nreturn [m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12];\",\"outputs\":12,\"noerr\":0,\"x\":140,\"y\":560,\"wires\":[[\"8ab04cbb.66453\"],[],[],[],[],[],[],[],[],[],[],[]]},{\"id\":\"7a8a3b21.378c34\",\"type\":\"ui_text_input\",\"z\":\"98c1390a.706f18\",\"name\":\"Oled\",\"label\":\"Messages\",\"tooltip\":\"\",\"group\":\"11655475.b9d69c\",\"order\":15,\"width\":0,\"height\":0,\"passthru\":true,\"mode\":\"text\",\"delay\":300,\"topic\":\"\",\"x\":330,\"y\":480,\"wires\":[[]]},{\"id\":\"d48225a8.7ba9f8\",\"type\":\"saveflow\",\"z\":\"98c1390a.706f18\",\"name\":\"\",\"path\":\"/home/pi/rpieasy/flows/\",\"enabled\":true,\"exporttype\":\"addflow\",\"x\":120,\"y\":60,\"wires\":[[]]},{\"id\":\"11655475.b9d69c\",\"type\":\"ui_group\",\"z\":\"\",\"name\":\"Livingroom\",\"tab\":\"47f3aa96.cda2b4\",\"order\":6,\"disp\":true,\"width\":\"4\",\"collapse\":true},{\"id\":\"640a3afa.1e8d84\",\"type\":\"mqtt-broker\",\"z\":\"\",\"name\":\"Eclipse\",\"broker\":\"iot.eclipse.org\",\"port\":\"1883\",\"clientid\":\"\",\"usetls\":false,\"compatmode\":true,\"keepalive\":\"60\",\"cleansession\":true,\"birthTopic\":\"\",\"birthQos\":\"0\",\"birthPayload\":\"\",\"closeTopic\":\"\",\"closeQos\":\"0\",\"closePayload\":\"\",\"willTopic\":\"\",\"willQos\":\"0\",\"willPayload\":\"\"},{\"id\":\"47f3aa96.cda2b4\",\"type\":\"ui_tab\",\"z\":\"\",\"name\":\"Home\",\"icon\":\"dashboard\",\"disabled\":false,\"hidden\":false}]\n//var outputMsgs = [];\n//var words = msg.payload.split(\" \");\n//for (var Type in words) {\n// outputMsgs.push({payload:words[Type]});\n//}\n//return [ outputMsgs ]; \n}]}\n\nreturn m5;\n//return [ m1, m2, m3, m4 ];\n//return [ outputMsgs ];\n\n\n","outputs":1,"noerr":0,"x":320,"y":640,"wires":[["d5c15318.add5a","69dd7691.348db8"]]},{"id":"b145279d.aa0228","type":"http request","z":"c0844d0e.ea02c","name":"","method":"GET","ret":"obj","url":"http://{{{payload}}}/json","tls":"","x":110,"y":640,"wires":[["82ac311.50e04d"]]},{"id":"9638f0fa.4b1b9","type":"ui_text_input","z":"c0844d0e.ea02c","name":"","label":"New Device","tooltip":"Enter new device IP","group":"11655475.b9d69c","order":1,"width":"0","height":"0","passthru":true,"mode":"text","delay":"0","topic":"ip","x":110,"y":600,"wires":[["b145279d.aa0228"]]},{"id":"a0fddb81.756a68","type":"inject","z":"c0844d0e.ea02c","name":"","topic":"","payload":"10.1.10.40:8008","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":680,"wires":[["b145279d.aa0228"]]},{"id":"e759f833.6ef4c8","type":"getflows","z":"c0844d0e.ea02c","name":"","x":500,"y":680,"wires":[[]]},{"id":"11655475.b9d69c","type":"ui_group","z":"","name":"Livingroom","tab":"47f3aa96.cda2b4","order":6,"disp":true,"width":"4","collapse":true},{"id":"47f3aa96.cda2b4","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

I also tried using you scene example flow but was unsuccessful to add flow from file because I did not understand file directory setting in first function node and file name setting in file node. I am using raspberry pi for node-red and my flow file is in /home/pi/ directory with file name flow1.flow. Can you give me hint how to set it up? error message I get is:

2/3/2019, 7:32:56 PMnode: 792dcba0.396e94 msg : error "Error: ENOENT: no such file or directory, open 'flow1.flow'"

I am sure I am doing something wrong here.My goal for this is to have dashboard activated flow creation so newbies like me do not have to go to editor to change settings or create flow from scratch.On input side I will have json file from esp8266 sending sensor setup to node-red.

Please help me figure this out.

Thanks Ken

btsimonh commented 5 years ago

Hi ken, unfortunately, the text paste above has killed the escaping of quotes, so the json is invalid, so I can't load your flow :( - you could create a gist or attach as a text file? but you may want to start with a simpler flow for diagnosing the issue....

I have pushed an examples folder :)

as for the errors: "TypeError: Cannot read property 'nodes' of undefined" sounds like the data in to the node is not present or invalid? Most likely, the msg.payload you are giving is a string, but is not valid JSON. Try diagnosing with a JSON node converting the string to a structure, and a debug node to see it.... and note the strucutre required at input (see below).

"Error: ENOENT: no such file or directory, open 'flow1.flow'" in the simplest case, set the filename in the file node to /home/pi/flow.flow :).

but do remember the 'flow' required on input to the addnode node is not identical to that produced by copying a flow to clipboard.

e.g. the clipboard for a simple flow: [{"id":"4129ba0c.082c84","type":"inject","z":"570dd9ad.86ac18","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":120,"wires":[["cc237afa.f8f718"]]},{"id":"cc237afa.f8f718","type":"function","z":"570dd9ad.86ac18","name":"simple","func":"msg.payload = \"hello\";\n\n\nreturn msg;","outputs":1,"noerr":0,"x":230,"y":120,"wires":[["35e921ba.b06abe"]]},{"id":"35e921ba.b06abe","type":"debug","z":"570dd9ad.86ac18","name":"","active":true,"console":"false","complete":"false","x":510,"y":120,"wires":[]}]

needs to be 'wrapped' in a structure with the flow name like so: {"label":"myflow", "id":"570dd9ad.86ac18", "nodes":[{"id":"4129ba0c.082c84","type":"inject","z":"570dd9ad.86ac18","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":120,"wires":[["cc237afa.f8f718"]]},{"id":"cc237afa.f8f718","type":"function","z":"570dd9ad.86ac18","name":"simple","func":"msg.payload = \"hello\";\n\n\nreturn msg;","outputs":1,"noerr":0,"x":230,"y":120,"wires":[["35e921ba.b06abe"]]},{"id":"35e921ba.b06abe","type":"debug","z":"570dd9ad.86ac18","name":"","active":true,"console":"false","complete":"false","x":510,"y":120,"wires":[]}] } (note: my 'info'' for the node indicates: 'id is optional, but if present, it must match the .z in the primary nodes.')

note also the escaping of quotes inside the function node function string! - "msg.payload = \"hello\";\n\n\nreturn msg;" I am guessing that you are modifying a template flow, so you may need to take this into account in any modification. In terms of flow modification, I JSON.parse the string, then iterate over the nodes, changing what I need. The other way I do simple modifications to flows is to put a placeholder (e.g. DEVICE) where i need to change something and do a simple string replace on the whole JSON string - this works well if you want to change settings on nodes, but don't want to dig in and find out how every setting is represented in a flow!.

p.s. there was a useful change a month or so ago which makes catch and another node which referenced node ids work - it's here in github, but I don't think I published to npm yet...

have fun, Simon

btsimonh commented 5 years ago

published the updates, plus hopefully examples :).

happytm commented 5 years ago

Your example flow work perfectly.Frankly I was not hoping this was even possible but this is going to be very helpful for my project. Following link have my room sensor flow I want to add automatically by just entering IP of esp8266 device on NR dashboard.

https://github.com/happytm/My-Node-Red-Flows/blob/master/Room%20Template.flow

ESP8266 will deliver a jason file which is below:

https://github.com/happytm/My-Node-Red-Flows/blob/master/espeasy.json

My goal is to use this json file to set up a flow like roomtemplate flow.

Please look these files and help me with example like you kindly provided soI can test it and report it back to you.

Thanks. Ken

happytm commented 5 years ago

After trying to set up automatic flow creation for hours with function node eventually I was able to implement it without help of function node and it was just as simple as changing syntax highlight setting in template node to mustache (It is same as your example flow) It is working perfectly with minimum effort. I have linked my example below if anyone wants to use it.

https://github.com/happytm/My-Node-Red-Flows/blob/master/Room%20Template.txt

Thank you for this great addition to node-red.

Ken

btsimonh commented 5 years ago

All Good :).