Hi Andrei, I took me a while before I could look at your proposed solution.... Thank you so much !!!
I can now modify one file for the behavior of many LEDS with text.
I discovered the mustache syntax...
Note: I put the ReadFile+set msg.template+template nodes in a subflow. Added the msg.filename in the preceeding function to set the parameters.
I also modify the id=blabla in the text file to id = {{ID}} to allow for different TextLEDs with different values.
thanks again for your patience and detailed explanation.
I now understand... by looking at the different debug stages why the msg.template has to be set.
the ReadFile puts the raw file in the msg.payload, gets copied to the msg.template, and an indication for the mustache syntax is put just before the </>template can be instantiated.
I will try to include my example flow just in case someone encounters the same problems I had.ThanksAndrei.txt (6.6 KB)
I try the infamous three backquotes to include the code...(does not seem to work anymore ??) (grrr...) I cannot find how to include images or codes properly in this forum.... Is this documented anywhere ? sorry...
[{"id":"2f87f2e.075dc0e","type":"subflow","name":"TextLed","info":"","in":[{"x":80,"y":80,"wires":[{"id":"ccdee70f.bcd108"}]}],"out":[{"x":780,"y":80,"wires":[{"id":"d21da5fa.73c138","port":0}]}]},{"id":"ccdee70f.bcd108","type":"file in","z":"2f87f2e.075dc0e","name":"Read file","filename":"","format":"utf8","chunk":false,"sendError":false,"x":220,"y":80,"wires":[["e3e1ba24.247838"]]},{"id":"e3e1ba24.247838","type":"change","z":"2f87f2e.075dc0e","name":"","rules":[{"t":"set","p":"template","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":80,"wires":[["d21da5fa.73c138"]]},{"id":"d21da5fa.73c138","type":"template","z":"2f87f2e.075dc0e","name":"Use Mustache","field":"template","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"","output":"str","x":620,"y":80,"wires":[[]]},{"id":"2c930137.26a03e","type":"tab","label":"ThanksAndrei","disabled":false,"info":"Trying to use a file instead of code in template node."},{"id":"a54070a4.bb245","type":"function","z":"2c930137.26a03e","name":"SetTextLed","func":"msg.color = (msg.payload === \"on\")?\"red\":\"lime\";\nmsg.textColor = \"white\";\nmsg.ID = \"blabla\";\nmsg.nameLabel =\"Text w LED\";\nmsg.filename=\"/home/pi/node-red-static/testTemplate.js\"\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":40,"wires":[["91e6991d.6918b8"]]},{"id":"f64ce53e.ecc4d8","type":"inject","z":"2c930137.26a03e","name":"","topic":"","payload":"anything else","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":80,"wires":[["8c13aa25.fc29e8"]]},{"id":"8c13aa25.fc29e8","type":"ui_button","z":"2c930137.26a03e","name":"","group":"75da5bf1.7a8244","order":2,"width":0,"height":0,"passthru":false,"label":"red1","color":"","bgcolor":"","icon":"fa-fire","payload":"on","payloadType":"str","topic":"","x":250,"y":80,"wires":[["a54070a4.bb245"]]},{"id":"115a9bec.935f74","type":"ui_template","z":"2c930137.26a03e","group":"75da5bf1.7a8244","name":"TemplateAndrei","order":3,"width":0,"height":0,"format":"<div ng-bind-html=\"msg.payload\"></div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":820,"y":180,"wires":[[]]},{"id":"4e8db3e4.e5765c","type":"file in","z":"2c930137.26a03e","name":"Read file","filename":"","format":"utf8","chunk":false,"sendError":false,"x":640,"y":40,"wires":[["37fc2068.51ac4"]]},{"id":"9a2af295.d030d","type":"template","z":"2c930137.26a03e","name":"Use Mustache","field":"template","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"","output":"str","x":1040,"y":40,"wires":[[]]},{"id":"37fc2068.51ac4","type":"change","z":"2c930137.26a03e","name":"","rules":[{"t":"set","p":"template","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":40,"wires":[["9a2af295.d030d"]]},{"id":"5d452461.766bcc","type":"function","z":"2c930137.26a03e","name":"SetTextLED","func":"msg.color = (msg.payload === \"on\")?\"red\":\"lime\";\nmsg.textColor = \"white\";\nmsg.ID = \"blabla2\";\nmsg.nameLabel =\"Text2 w LED\";\nmsg.filename=\"/home/pi/node-red-static/testTemplate.js\"\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":360,"wires":[["7a0b020d.98778c"]]},{"id":"9d88c36d.48e71","type":"ui_template","z":"2c930137.26a03e","group":"75da5bf1.7a8244","name":"TemplateAndrei2","order":6,"width":0,"height":0,"format":"<div ng-bind-html=\"msg.payload\"></div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":850,"y":440,"wires":[[]]},{"id":"28496c98.6a2fa4","type":"inject","z":"2c930137.26a03e","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":90,"y":320,"wires":[["da512f0b.8f26b"]]},{"id":"77acd785.629848","type":"inject","z":"2c930137.26a03e","name":"","topic":"","payload":"anything else","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":380,"wires":[["319b0339.9bbfec"]]},{"id":"da512f0b.8f26b","type":"ui_button","z":"2c930137.26a03e","name":"","group":"75da5bf1.7a8244","order":4,"width":0,"height":0,"passthru":false,"label":"green2","color":"","bgcolor":"","icon":"fa-fire","payload":"asdf","payloadType":"str","topic":"","x":260,"y":320,"wires":[["5d452461.766bcc"]]},{"id":"319b0339.9bbfec","type":"ui_button","z":"2c930137.26a03e","name":"","group":"75da5bf1.7a8244","order":5,"width":0,"height":0,"passthru":false,"label":"red2","color":"","bgcolor":"","icon":"fa-fire","payload":"on","payloadType":"str","topic":"","x":250,"y":380,"wires":[["5d452461.766bcc"]]},{"id":"c252c974.042508","type":"inject","z":"2c930137.26a03e","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":90,"y":40,"wires":[["1f980983.29f2a6"]]},{"id":"1f980983.29f2a6","type":"ui_button","z":"2c930137.26a03e","name":"","group":"75da5bf1.7a8244","order":1,"width":0,"height":0,"passthru":false,"label":"green1","color":"","bgcolor":"","icon":"fa-fire","payload":"asdf","payloadType":"str","topic":"","x":260,"y":40,"wires":[["a54070a4.bb245"]]},{"id":"c27a5f89.ff43a","type":"comment","z":"2c930137.26a03e","name":"3NodesInaSubFlow+Contents of Read file","info":"One could put the three nodes in subflow.\nI changed ID=blabla in the file for id={{ID}} to provide for \nmultiple templates with different values.\n\nContents of the read file..\n<style>\n\n#{{ID}} {\n stroke: none;\n fill: {{color}};\n}\n</style>\n\n<svg>\n <circle\n //style=\"CircleStyle\"\n id={{ID}}\n cx=\"120\"\n cy=\"15\"\n r=\"10\" />\n <g font-family=\"Verdana\" font-size=\"medium\" >\n <text x=\"1\" y=\"20\" fill={{color}}>\n{{nameLabel}}\n </text>\n </g>\n</svg>","x":760,"y":120,"wires":[]},{"id":"91e6991d.6918b8","type":"subflow:2f87f2e.075dc0e","z":"2c930137.26a03e","x":650,"y":180,"wires":[["115a9bec.935f74"]]},{"id":"f28b5361.69d1e","type":"template","z":"2c930137.26a03e","name":"Use Mustache","field":"template","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"","output":"str","x":980,"y":360,"wires":[["9d88c36d.48e71"]]},{"id":"8e092e42.adaba","type":"change","z":"2c930137.26a03e","name":"","rules":[{"t":"set","p":"template","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":360,"wires":[["f28b5361.69d1e"]]},{"id":"7a0b020d.98778c","type":"file in","z":"2c930137.26a03e","name":"Read file","filename":"","format":"utf8","chunk":false,"sendError":false,"x":580,"y":360,"wires":[["8e092e42.adaba"]]},{"id":"75da5bf1.7a8244","type":"ui_group","z":"","name":"Default","tab":"82aa62ad.00185","disp":true,"width":"6","collapse":false},{"id":"82aa62ad.00185","type":"ui_tab","z":"","name":"testsAndrei","icon":"dashboard"}]