hi i'm working on a dropdown with options so basically i want to write some equations and save it in a database to use and then recover it on a dropdown like new options and when i choose for example equation 1 send this equation as a variable like varequation 1 = (5/1023) *
and use it in a second variable calling var equation 1 = 5/1023 var1 = msg.payload
var result equation 1 = 5/1023* var1;
so i'm having problems with the step between recover it and send it to the dropdown.
i will put my flow.
[{"id":"2a76abae.3cb354","type":"inject","z":"217dd16.38f122e","name":"Daily backup","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"00 02 * * *","once":false,"onceDelay":"","x":260,"y":540,"wires":[["404e5869.289af8"]]},{"id":"404e5869.289af8","type":"function","z":"217dd16.38f122e","name":"Prep data","func":"// global variables separated by semicolon to be saved\nvar globallist = \"equa;timeminute\"\nvar mylist = globallist.split(\";\");\n\nvar outputs = [];\n\nfor (i=0; i<mylist.length; i++) {\n outputs.push({ key : mylist[i], type: typeof global.get(mylist[i]), value: global.get(mylist[i])});\n}\n \n \nmsg.payload = outputs;\nreturn msg;\n\n//msg.payload=typeof global.get(\"torrent_keywords\");\n","outputs":1,"noerr":0,"x":440,"y":540,"wires":[["796ae060.2571d"]]},{"id":"722bde30.b4061","type":"comment","z":"217dd16.38f122e","name":"Save global variables","info":"","x":252,"y":495,"wires":[]},{"id":"82ed5561.8ea6c8","type":"comment","z":"217dd16.38f122e","name":"Restore global variables","info":"","x":280,"y":626,"wires":[]},{"id":"623cfee.c4562","type":"inject","z":"217dd16.38f122e","name":"Startup","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":240,"y":680,"wires":[["ec4e4dad.53165"]]},{"id":"3cf22d71.3cf902","type":"file","z":"217dd16.38f122e","name":"","filename":"/home/pi/global.json","appendNewline":true,"createDir":false,"overwriteFile":"true","x":760,"y":540,"wires":[["41a8df7d.8a1b2"]]},{"id":"ec4e4dad.53165","type":"file in","z":"217dd16.38f122e","name":"","filename":"/home/pi/global.json","format":"utf8","x":440,"y":680,"wires":[["cc306e1f.95de2"]]},{"id":"baebe8d4.f4d4e8","type":"function","z":"217dd16.38f122e","name":"Restore","func":"var output = [];\n\nfor (var i=0; i<msg.payload.length; i++) {\n switch (msg.payload[i].type) {\n case 'undefined': \n // the global variable probably had no value, nothing needs to be restored\n output.push(msg.payload[i].key + \" is undefined.\");\n break;\n case 'number':\n if (msg.payload[i].value===\"NaN\") {\n // there is no valid value to be restored, skip this variable\n output.push(msg.payload[i].key + \" is NaN.\");\n } else {\n if (msg.payload[i].value.toString().indexOf(\".\")>-1) {\n // the value appears to be a float\n global.set(msg.payload[i].key,parseFloat(msg.payload[i].value));\n output.push(msg.payload[i].key + \" is restored to \" + msg.payload[i].value);\n } else {\n global.set(msg.payload[i].key,parseInt(msg.payload[i].value));\n output.push(msg.payload[i].key + \" is restored to \" + msg.payload[i].value);\n }\n }\n break;\n case 'string':\n global.set(msg.payload[i].key,msg.payload[i].value);\n output.push(msg.payload[i].key + \" is restored to \" + msg.payload[i].value);\n break;\n case 'boolean':\n global.set(msg.payload[i].key,msg.payload[i].value===\"true\");\n output.push(msg.payload[i].key + \" is restored to \" + msg.payload[i].value);\n break;\n }\n}\n\nmsg.payload = output;\nreturn msg;","outputs":1,"noerr":0,"x":780,"y":680,"wires":[["5bc9e96f.723ff8","f7213c41.3124"]]},{"id":"796ae060.2571d","type":"json","z":"217dd16.38f122e","name":"","x":590,"y":540,"wires":[["3cf22d71.3cf902"]]},{"id":"cc306e1f.95de2","type":"json","z":"217dd16.38f122e","name":"","x":630,"y":680,"wires":[["baebe8d4.f4d4e8"]]},{"id":"5bc9e96f.723ff8","type":"function","z":"217dd16.38f122e","name":"Irrigation hour restore","func":"msg.topic = \"equa\";\nmsg.payload = global.get(\"equa\");\nreturn msg;","outputs":1,"noerr":0,"x":980,"y":640,"wires":[["376f6bb1.5aa224","93af67ea.420c68"]]},{"id":"f7213c41.3124","type":"function","z":"217dd16.38f122e","name":"Irrigation minute restore","func":"msg.topic = \"timeminute\";\nmsg.payload = global.get(\"timeminute\");\nreturn msg;","outputs":1,"noerr":0,"x":990,"y":720,"wires":[["89b5d8a5.bdc828"]]},{"id":"41a8df7d.8a1b2","type":"debug","z":"217dd16.38f122e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":950,"y":540,"wires":[]},{"id":"376f6bb1.5aa224","type":"debug","z":"217dd16.38f122e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1230,"y":540,"wires":[]},{"id":"89b5d8a5.bdc828","type":"debug","z":"217dd16.38f122e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1230,"y":840,"wires":[]},{"id":"43e0e95c.6cc1b8","type":"ui_text_input","z":"217dd16.38f122e","name":"","label":"","tooltip":"","group":"d656deff.eac3b","order":1,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"","x":220,"y":380,"wires":[["b751f9f3.add038"]]},{"id":"cef3b486.eb6f88","type":"debug","z":"217dd16.38f122e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":380,"wires":[]},{"id":"b751f9f3.add038","type":"function","z":"217dd16.38f122e","name":"","func":"var equa = msg.payload;\n\nglobal.set('equa',equa);\n\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":380,"wires":[["cef3b486.eb6f88"]]},{"id":"73bebdc6.3a46b4","type":"ui_dropdown","z":"217dd16.38f122e","name":"","label":"","tooltip":"","place":"Select option","group":"679f2509.be684c","order":0,"width":0,"height":0,"passthru":true,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":1500,"y":640,"wires":[["810a2cc2.b603c"]]},{"id":"810a2cc2.b603c","type":"ui_toast","z":"217dd16.38f122e","position":"top right","displayTime":"3","highlight":"","outputs":0,"ok":"OK","cancel":"","topic":"","name":"","x":1530,"y":480,"wires":[]},{"id":"93af67ea.420c68","type":"function","z":"217dd16.38f122e","name":"transform data to correct format","func":"//as per info panel, the data needs to be formatted\n//as [ \"Choice 1\", \"Choice 2\", {\"Choice 3\":\"3\"} ]\n//and sent in msg.options.\nmsg.options = [];//create empty array\nfor(let i = 0; i < msg.payload.length; i++){\n let row = msg.payload[i]; //get the row\n let opt = {};//make new opt object\n opt[row[0]] = row[1]; //add a propery to object called row[0] & set its value to row[1]\n msg.options.push(opt);//add the opt to array \n}\nreturn msg;","outputs":1,"noerr":0,"x":1270,"y":640,"wires":[["73bebdc6.3a46b4"]]},{"id":"d656deff.eac3b","type":"ui_group","z":"","name":"Default","tab":"8f4c42b3.c0e6","disp":true,"width":"6","collapse":false},{"id":"679f2509.be684c","type":"ui_group","z":"","name":"Default","tab":"658319a6.10c4d8","disp":true,"width":"6","collapse":false},{"id":"8f4c42b3.c0e6","type":"ui_tab","z":"","name":"dropdown","icon":"dashboard","order":1,"disabled":false,"hidden":false},{"id":"658319a6.10c4d8","type":"ui_tab","z":"","name":"Menu","icon":"fa-tachometer","order":1,"disabled":false,"hidden":false}]