smort

nRBCflow

Dec 10th, 2019
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.50 KB | None | 0 0
  1. [{"id":"6b333ae.0c170c4","type":"tab","label":"BC","disabled":false,"info":""},{"id":"361a3004.4b084","type":"function","z":"6b333ae.0c170c4","name":"parse","func":"node.status({fill:\"green\",shape:\"dot\",text:\"connected\"});\n\nvar inp = msg.payload\nvar s =[];\nvar u = [];\nvar r = [];\nvar d = [];\nvar out = {};\n\nconst numberSorter = (([a, b], [c, d]) => a - c || d - b);\n\nif (inp.indexOf('!') != -1 || inp.indexOf('?') != -1 || inp.indexOf('/') != -1 ) {\n inp = inp.split(/(?=[?!;/])/g)\n\n for (var i = 0; i < inp.length; i++) {\n if (inp[i].indexOf('!') != -1) {\n inp[i] = inp[i].slice(inp[i].indexOf('!')+1)\n u.push (inp[i])\n }\n if (inp[i].indexOf('?') != -1) {\n inp[i] = inp[i].slice(inp[i].indexOf('?')+1)\n s.push (inp[i])\n }\n if (inp[i].indexOf('/') != -1) {\n inp[i] = inp[i].slice(inp[i].indexOf('/')+1)\n r.push (inp[i]+\",\"+\"99\")\n d.push (inp[i])\n }\n } \n\n for (i = 0; i < u.length; i++) {\n u[i] = u[i].split(\",\").map(Number);\n }\n for (i = 0; i < r.length; i++) {\n r[i] = r[i].split(\",\").map(Number);\n }\n for (i = 0; i < s.length; i++) {\n s[i] = s[i].split(\",\").map(Number);\n }\nu.sort(numberSorter)\n if (u.length > 0 ) {\n node.send([{payload:u}, null])\n }\nr.sort(numberSorter)\n if (r.length > 0 ) {\n out = r\n node.send([{payload:out}, null])\n }\ns.sort(numberSorter)\nsetTimeout(reply, 200);\n\n} else {\n if (inp.indexOf('*') != -1) {\n out = \"*;\"\n node.send([null, {payload: out}])\n }\n}\n\nfunction reply() {\n for (i = 0; i < s.length; i++) {\n if (isNaN(flow.get(String(s[i]))) === false) {\n s[i] = \"?\" + s[i] + \"=\" + flow.get(String(s[i]))\n }\n else {\n s[i] = \"?\" + s[i]\n }\n }\n\n for ( i = 0; i < u.length; i++) {\n u[i] = \"!\" + u[i]\n }\n for ( i = 0; i < d.length; i++) {\n d[i] = \"/\" + d[i]\n }\n\n u = u.join('')\n s = s.join('')\n out = s+u+d+\";\"\n node.send([null, {payload: out}])\n}\n\n \n \n \n\n","outputs":2,"noerr":0,"x":130,"y":1100,"wires":[["4219943.881ec6c"],["e6c5affa.506c2"]]},{"id":"4219943.881ec6c","type":"function","z":"6b333ae.0c170c4","name":"config","func":"\nvar u = msg.payload || []\nvar dcpins = flow.get(\"dcpins\") || []\nvar deadTime = 400; // number of milliseconds the valve (or whatever) takes to actuate, 30 seconds\nvar invert = false; \n\ndcpins = Array.from(new Set(dcpins))\ndcpins.sort(function(a, b){return a-b});\n\nfor (var i = 0; i < u.length; i++) {\n var config = u[i][1]\n var pin = u[i][0]\n \n if (config === 1) { //digital out\n flow.set(String(pin)+\"config\", config)\n msg.topic = pin\n msg.payload = u[i][2]\n node.send(msg);\n }\n\n if (config === 4) { //dutycycle\n flow.set(String(pin)+\"config\", config)\n flow.set(String(pin)+\"dcpower\", u[i][2]/100)\n flow.set(String(pin)+\"dctime\", u[i][3])\n dcpins.push(u[i][0]);\n }\n \n if (config === 5) { //hysteresis\n flow.set(String(pin)+\"config\", config)\n flow.set(String(u[i][2])+\"config\", config)\n flow.set(String(pin)+\"setpoint\", u[i][3])\n flow.set(String(pin)+\"setpoint2\", u[i][4])\n flow.set(String(u[i][2])+\"pin\", pin)\n var cooling\n if (u[i][3] < u[i][4]) {\n cooling = true\n } else {\n cooling = false\n }\n flow.set(String(pin)+\"cooling\", cooling)\n flow.set(String(pin)+\"ondelay\", u[i][5])\n msg.delay = u[i][5]*1000\n msg.topic = pin\n msg.payload = flow.get(String(pin))\n node.send(msg);\n }\n\n if (config == 6 ) { //PID\n flow.set(String(pin)+\"config\", config)\n flow.set(String(u[i][2])+\"config\", config)\n flow.set(String(u[i][2])+\"pin\", pin)\n flow.set(String(pin)+\"pid\", u[i][2])\n flow.set(String(pin)+\"setpoint\", u[i][3])\n flow.set(String(pin)+\"prop_band\", u[i][4] /100)\n flow.set(String(pin)+\"t_integral\", u[i][5] /100)\n flow.set(String(pin)+\"t_derivative\", u[i][6]/ 100)\n flow.set(String(pin)+\"direction\", u[i][7])\n flow.set(String(pin)+\"calctime\", u[i][8]*1000)\n flow.set(String(pin)+\"outtime\", u[i][9])\n flow.set(String(pin)+\"maxout\", u[i][11])\n msg.payload = [u[i][0],u[i][1],u[i][2],u[i][3],u[i][4],u[i][5],u[i][6],u[i][7],u[i][8],u[i][9],u[i][10],u[i][11]]//flow.get(String(u[i][2]))\n msg.topic = u[i][0]\n msg.enable = 1\n node.send(msg)\n }\n \n if (config === 7) { //pwm\n flow.set(String(pin)+\"config\", config)\n flow.set(String(pin), u[i][2])\n msg.topic = pin\n msg.payload = flow.get(String(pin))\n node.send(msg);\n }\n if (config === 8) { //analoginput\n flow.set(String(pin)+\"pollrate\", u[i][2])\n flow.set(String(pin)+\"awgweight\", u[i][3])\n if (flow.get(String(pin)+\"config\") === 5 || flow.get(String(pin)+\"config\") === 6) {\n msg.topic = flow.get(String(pin)+\"pin\")\n } else \n { msg.topic = pin }\n msg.payload = [pin, 8, u[i][2], u[i][3]]\n node.send(msg);\n }\n if (config === 99) { //disabled\n previousconfig = flow.get(String(pin)+\"config\") || 0\n flow.set(String(pin)+\"config\", config)\n \n if (previousconfig === 1 || previousconfig === 5 || previousconfig === 7) {\n msg.topic = pin\n msg.payload = 0\n node.send(msg)\n }\n if (previousconfig === 4) {\n for (i = 0; i < flow.get(\"dcpins\").length; i++) {\n \n if (pin === dcpins[i]) {\n dcpins.splice([i], 1)\n flow.set(String(pin)+\"dcdisabled\", true)\n msg.topic = pin\n msg.payload = 0\n node.send(msg)\n }\n }\n }\n \n if (previousconfig === 6) {\n flow.set(String(pin)+\"maxout\", 0)\n msg.topic = pin\n msg.enable = 0\n node.send(msg)\n }\n \n }\n}\n\ndcpins = Array.from(new Set(dcpins))\ndcpins.sort(function(a, b){return a-b});\n\nif (dcpins !== flow.get(\"dcpins\")) {\n flow.set(\"dcpins\", dcpins)\n}\n\nif (msg.topic === \"tick\") {\n for (i = 0; i < dcpins.length; i++) {\n msg.topic = dcpins[i]\n var power = flow.get(String(dcpins[i])+\"dcpower\");\n var dctime = flow.get(String(dcpins[i])+\"dctime\");\n var inn = msg.payload\n // yes, payload is timestamp, calc current wave value between 0 and 1\n var wave = inn % dctime/dctime; // fraction of way through cycle\n var direction;\n // determine direction of travel and convert to triangular wave\n if (wave < 0.5) {\n direction = 1; // on the way up\n wave = wave*2;\n } else {\n direction = -1; // on the way down\n wave = (1 - wave)*2;\n }\n var requestedPower = power || 0;\n // if a dead_time has been supplied for this o/p then adjust power accordingly\n if (deadTime > 0 && requestedPower > 0.0 && requestedPower < 1.0) {\n var dtop = deadTime/dctime;\n power = (1.0-2.0*dtop)*requestedPower + dtop;\n } else {\n power = requestedPower;\n }\n // cope with end cases in case values outside 0..1\n var opState;\n if (power <= 0.0) {\n opState = 0; // no heat\n } else if (power >= 1.0) {\n opState = 1; // full heat\n } else {\n // only allow power to come on on the way down and off on the way up, to reduce short pulses\n if (power >= wave && direction === -1) {\n opState = 1;\n } else if (power <= wave && direction === 1) {\n opState = 0;\n } else {\n // otherwise leave it as it is\n opState = flow.get(String(dcpins[i])+'opState') || 0;\n } \n }\n flow.set(String(dcpins[i])+'opState', opState);\n \n var out = invert ? (1-opState) : opState;\n if ((out !== flow.get(String(dcpins[i])+\"previousout\")) || (flow.get(String(dcpins[i])+\"dcdisabled\") === true)) {\n flow.set(String(dcpins[i])+\"previousout\", out)\n flow.set(String(dcpins[i])+\"dcdisabled\", false)\n flow.set(String(dcpins[i]), out)\n msg.payload = out\n msg.topic = dcpins[i]\n node.send(msg)\n }\n}\n}\n\n \n\n\n\n\n\n","outputs":1,"noerr":0,"x":270,"y":1080,"wires":[["485dc52c.20a7fc"]]},{"id":"d4d3454e.be83f","type":"tcp in","z":"6b333ae.0c170c4","name":"","server":"server","host":"","port":"5000","datamode":"stream","datatype":"utf8","newline":"","topic":"","base64":false,"x":60,"y":1180,"wires":[["361a3004.4b084","519e3d4c.81bdb4"]]},{"id":"e6c5affa.506c2","type":"tcp out","z":"6b333ae.0c170c4","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"","x":270,"y":1120,"wires":[]},{"id":"5cd78344.cbf9dc","type":"PID","z":"6b333ae.0c170c4","name":"","setpoint":21,"pb":"30","ti":9999,"td":0,"integral_default":0.5,"smooth_factor":3,"max_interval":600,"enable":1,"disabled_op":"1","x":1310,"y":60,"wires":[["8341876c.ee9438"]]},{"id":"cc4daea4.a165b8","type":"switch","z":"6b333ae.0c170c4","name":"out","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"},{"t":"eq","v":"4","vt":"str"},{"t":"eq","v":"5","vt":"str"},{"t":"eq","v":"6","vt":"str"},{"t":"eq","v":"7","vt":"str"},{"t":"eq","v":"8","vt":"str"},{"t":"eq","v":"9","vt":"str"},{"t":"eq","v":"10","vt":"str"},{"t":"eq","v":"11","vt":"str"},{"t":"eq","v":"12","vt":"str"},{"t":"eq","v":"13","vt":"str"},{"t":"eq","v":"14","vt":"str"},{"t":"eq","v":"15","vt":"str"},{"t":"eq","v":"16","vt":"str"},{"t":"eq","v":"17","vt":"str"}],"checkall":"true","repair":false,"outputs":17,"x":470,"y":960,"wires":[[],[],[],[],[],["71abf5aa.3186cc","4dbc963e.c178f8"],[],["3be9acbe.ed9974"],[],[],["9400f82a.44cae"],[],[],[],[],["100eb725.0a2301"],["3735ea8.a065e96"]]},{"id":"29f43b92.343e3c","type":"function","z":"6b333ae.0c170c4","name":"heat/cool","func":"\n/* A function designed to be used with node-red-contrib-pid in applications where both\n * heating and cooling are available to control the system.\n * The node is given a power value in msg.payload in the range 0 to 1, such as is produced by \n * node-red-contrib-pid and splits this into a heat power (o/p 1) and cool power (o/p 2) where\n * each is in the range 0 to 1. These can then be fed directly into an output device, if this\n * is continuously variable, or they may be passed to node-red-contrib-timeprop nodes to generate\n * time proportioned on/off outputs.\n * There are two particular issues to be dealt with in a heat/cool application. Firstly is the fact\n * that the cooling device may be more or less powerful than the heating device. It is necessary\n * therefore to be able to adjust the gain of the system separately for heating and cooling. Secondly\n * is the highly non-linear response of some devices, notably refrigerant systems, that can have a\n * large effect initially, then this tails off. To compensate for this it is useful to have an \n * overlap range where both heat and cool are slightly on.\n *\n * To allow for these requirements two variables can be set below. The value of the power input value\n * where the heating starts to come on is determined by the variable heatMin. Above this value the\n * heating will rise till it is fully on with an input of 1.\n * The cooling is fully on when value of the power input is 0, and falls till the cooling is fully\n * off at an input of coolMin.\n *\n * If the heating and cooling systems are of similar power then set heatMin and coolMin both to 0.5\n * in which case input values of 0.5 to 1.0 will map to heating outputs of 0.0 to 1.0,\n * and 0.5 down to 0.0 will map to cooling 0.0 to 1.0.\n * If, for example, the cooling system is more powerful than heating then they can both be set\n * to something like 0.7 which increases the gain in the heating region and reduces it\n * in the cooling region, to compensate for the different powers in the heating/cooling systems.\n * If some overlap is desired (so that both heat and cool are on slightly near the crossover\n * point) then overlap the two settings so that, for example, heatMin might be 0.45 and coolMin\n * might be 0.55\n */\n\nflow.set(String(msg.topic), Math. round(msg.payload*100))\n \n// set these as described above\nvar heatMin = 0.5; // the value of input corresponding to 0 heat o/p\nvar coolMin = 0.5; // the value of input corresponding to 0 cool o/p\n \nvar power = msg.payload;\nvar heat = (power - heatMin)/(1 - heatMin);\n// limit to range 0 to 1\nheat = Math.min(Math.max(heat, 0), 1);\nvar cool = (coolMin - power) / coolMin;\n// limit to range 0 to 1\ncool = Math.min(Math.max(cool, 0), 1);\n\nmsg.payload = [{payload: heat}, {payload: cool}];\nreturn msg;\n","outputs":2,"noerr":0,"x":1700,"y":40,"wires":[[],[]]},{"id":"aa94857f.8bc8b8","type":"trigger","z":"6b333ae.0c170c4","op1":"","op2":"-12700","op1type":"nul","op2type":"num","duration":"120","extend":true,"units":"s","reset":"","bytopic":"topic","name":"","x":730,"y":260,"wires":[["61fe7ba9.54589c","e71dd7d4.568a2"]]},{"id":"864bdbd5.8ac7a","type":"mqtt in","z":"6b333ae.0c170c4","name":"Result","topic":"stat/+/RESULT","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":70,"y":40,"wires":[["3f47ac74.dc063c"]]},{"id":"deed002b.0ca94","type":"mqtt in","z":"6b333ae.0c170c4","name":"State","topic":"tele/+/STATE","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":70,"y":80,"wires":[["3f47ac74.dc063c"]]},{"id":"3f47ac74.dc063c","type":"switch","z":"6b333ae.0c170c4","name":"topic","property":"topic","propertyType":"msg","rules":[{"t":"regex","v":"4ch","vt":"str","case":false},{"t":"regex","v":"steam","vt":"str","case":false},{"t":"regex","v":"freezer","vt":"str","case":false},{"t":"regex","v":"cooler","vt":"str","case":false},{"t":"regex","v":"Fridge1","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":5,"x":190,"y":60,"wires":[["1c32ec5.e742914"],["4f7d669a.9593e"],["63999e79.8f04c"],["f30a2071.adbe58"],["ae2aff4e.1abb3"]]},{"id":"1c32ec5.e742914","type":"change","z":"6b333ae.0c170c4","name":"4","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.POWER1","tot":"msg"},{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"OFF","fromt":"str","to":"0","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"4","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":20,"wires":[["61fe7ba9.54589c"]]},{"id":"4f7d669a.9593e","type":"change","z":"6b333ae.0c170c4","name":"8","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.POWER","tot":"msg"},{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"OFF","fromt":"str","to":"0","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"8","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":60,"wires":[["61fe7ba9.54589c"]]},{"id":"63999e79.8f04c","type":"change","z":"6b333ae.0c170c4","name":"11","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.POWER","tot":"msg"},{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"OFF","fromt":"str","to":"0","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"11","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":100,"wires":[["61fe7ba9.54589c"]]},{"id":"f30a2071.adbe58","type":"change","z":"6b333ae.0c170c4","name":"16","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.POWER","tot":"msg"},{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"OFF","fromt":"str","to":"0","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"16","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":140,"wires":[["61fe7ba9.54589c"]]},{"id":"ae2aff4e.1abb3","type":"change","z":"6b333ae.0c170c4","name":"17","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.POWER","tot":"msg"},{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"OFF","fromt":"str","to":"0","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"17","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":180,"wires":[["61fe7ba9.54589c"]]},{"id":"74f3ce1a.6b5d98","type":"mqtt in","z":"6b333ae.0c170c4","name":"Sensor","topic":"tele/+/SENSOR","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":50,"y":280,"wires":[["5315b288.1b42c4","d24fef0c.576368"]]},{"id":"5315b288.1b42c4","type":"switch","z":"6b333ae.0c170c4","name":"topic","property":"topic","propertyType":"msg","rules":[{"t":"regex","v":"cooler","vt":"str","case":false},{"t":"regex","v":"freezer","vt":"str","case":false},{"t":"regex","v":"Fridge1","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":3,"x":230,"y":280,"wires":[["660cb740.453d78"],["d9ce9fc7.d6b4b"],["d46086dd.fb5d5"]]},{"id":"660cb740.453d78","type":"change","z":"6b333ae.0c170c4","name":"200","rules":[{"t":"set","p":"payload","pt":"msg","to":"$floor(msg.payload.DS18B20.Temperature*100)","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"200","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":220,"wires":[["aa94857f.8bc8b8","61fe7ba9.54589c"]]},{"id":"d9ce9fc7.d6b4b","type":"change","z":"6b333ae.0c170c4","name":"201","rules":[{"t":"set","p":"payload","pt":"msg","to":"$floor(msg.payload.DS18B20.Temperature*100)\t","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"201","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":260,"wires":[["aa94857f.8bc8b8","61fe7ba9.54589c"]]},{"id":"d46086dd.fb5d5","type":"change","z":"6b333ae.0c170c4","name":"202","rules":[{"t":"set","p":"payload","pt":"msg","to":"$floor(msg.payload.DS18B20.Temperature*100)\t","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"202","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":300,"wires":[["aa94857f.8bc8b8","61fe7ba9.54589c"]]},{"id":"10332a50.3a4f5e","type":"mqtt out","z":"6b333ae.0c170c4","name":"Cooler ctrl","topic":"cmnd/cooler/POWER","qos":"","retain":"","broker":"7473ae41.ca29a","x":970,"y":1060,"wires":[]},{"id":"3c7347ac.ddd05","type":"mqtt out","z":"6b333ae.0c170c4","name":"Freezer ctrl","topic":"cmnd/freezer/POWER","qos":"","retain":"","broker":"7473ae41.ca29a","x":970,"y":1020,"wires":[]},{"id":"d2d46d2c.102ff8","type":"delay","z":"6b333ae.0c170c4","name":"ONdelay","pauseType":"delayv","timeout":"0","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":1060,"wires":[["3c7347ac.ddd05"]]},{"id":"1a5a5b63.40f1bd","type":"mqtt out","z":"6b333ae.0c170c4","name":"Fridge1 ctrl","topic":"cmnd/Fridge1/POWER","qos":"","retain":"","broker":"7473ae41.ca29a","x":970,"y":1120,"wires":[]},{"id":"e35434bf.783b58","type":"delay","z":"6b333ae.0c170c4","name":"ONdelay","pauseType":"delayv","timeout":"0","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":1100,"wires":[["10332a50.3a4f5e"]]},{"id":"6ebb2cf1.014ec4","type":"delay","z":"6b333ae.0c170c4","name":"ONdelay","pauseType":"delayv","timeout":"0","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":1140,"wires":[["1a5a5b63.40f1bd"]]},{"id":"9400f82a.44cae","type":"switch","z":"6b333ae.0c170c4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":670,"y":1060,"wires":[["3c7347ac.ddd05"],["d2d46d2c.102ff8"]]},{"id":"100eb725.0a2301","type":"switch","z":"6b333ae.0c170c4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":670,"y":1100,"wires":[["10332a50.3a4f5e"],["e35434bf.783b58"]]},{"id":"3735ea8.a065e96","type":"switch","z":"6b333ae.0c170c4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":670,"y":1140,"wires":[["1a5a5b63.40f1bd"],["6ebb2cf1.014ec4"]]},{"id":"8686deda.83794","type":"inject","z":"6b333ae.0c170c4","name":"","topic":"","payload":"start","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"3","x":230,"y":220,"wires":[["d9ce9fc7.d6b4b","d46086dd.fb5d5","660cb740.453d78","c1eea67a.38b4f"]]},{"id":"1a2dbda3.fc9f7a","type":"inject","z":"6b333ae.0c170c4","name":"0.2 sec","topic":"tick","payload":"","payloadType":"date","repeat":"0.2","crontab":"","once":true,"onceDelay":"3","x":120,"y":1060,"wires":[["4219943.881ec6c"]]},{"id":"61fe7ba9.54589c","type":"link out","z":"6b333ae.0c170c4","name":"","links":["4b91c95.9c9ddb8"],"x":855,"y":100,"wires":[]},{"id":"4b91c95.9c9ddb8","type":"link in","z":"6b333ae.0c170c4","name":"","links":["61fe7ba9.54589c"],"x":195,"y":1160,"wires":[["9977ef80.f4948"]]},{"id":"8341876c.ee9438","type":"change","z":"6b333ae.0c170c4","name":"100 -> 1","rules":[{"t":"set","p":"topic","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1440,"y":60,"wires":[["29f43b92.343e3c","58d6778.cbf3088","e1515b45.08edd"]]},{"id":"9977ef80.f4948","type":"function","z":"6b333ae.0c170c4","name":"input","func":"if (typeof(msg.payload) != \"undefined\") {\n\nvar pin = msg.topic\nvar value = msg.payload\nflow.set(pin,value)\n\nif (flow.get(String(pin)+\"config\") === 5) { //hysteresis\n var outpin = flow.get(String(pin)+\"pin\") || 0\n var setpoint = flow.get(String(outpin)+\"setpoint\") || 0\n var setpoint2 = flow.get(String(outpin)+\"setpoint2\") || 0\n var config = flow.get(String(outpin)+\"config\") || 99\n var out = Boolean(flow.get(String(outpin))) || false\n var cooling = flow.get(String(outpin)+\"cooling\") || false\n\n if (value < setpoint){\n if (cooling === true) {\n out = false\n } else {\n out = true\n }\n } else {\n if (value > setpoint2) {\n if (cooling === true) {\n out = true\n } else {\n out = false\n }\n }\n }\n \n if (config === 99) {\n out = false\n }\n if (value === -12700) {\n out = false\n }\n out = Number(out)\n if (out !== flow.get(String(outpin))) {\n flow.set(String(outpin), out)\n msg.topic = outpin\n msg.payload = out \n node.send(msg);\n }\n}\n\n\n//PID\nif (flow.get(String(pin)+\"config\") === 6) {\n var outpin = flow.get(String(pin)+\"pin\") || 0\n //var config = flow.get(String(outpin)+\"config\") || 99\n var pidsetpoint = flow.get(String(outpin)+\"setpoint\")\n var prop_band = flow.get(String(outpin)+\"prop_band\")\n var t_integral = flow.get(String(outpin)+\"t_integral\")\n var t_derivative = flow.get(String(outpin)+\"t_derivative\")\n \n if (flow.get(String(outpin)+\"config\") === 99 || flow.get(String(pin)) === -12700) {\n msg.topic = pin\n var maxout = flow.get(String(pin)+\"maxout\")\n flow.set(String(pin)+\"oldmaxout\", maxout)\n flow.set(String(pin)+\"maxout\", 0)\n msg.enable = 0\n msg.disabled_op = 0\n node.send(msg)\n }\n \n else {\n var oldmaxout = flow.get(String(pin)+\"oldmaxout\")\n flow.set(String(pin)+\"maxout\", oldmaxout)\n msg.enable = 1\n msg.topic = pin\n msg.payload = flow.get(String(pin))\n msg.setpoint = pidsetpoint\n msg.prop_band = prop_band\n msg.t_integral = t_integral\n msg.t_derivative = t_derivative\n node.send(msg)\n }\n}\n\nif (flow.get(String(pin)+\"config\") === 99) {\n msg.payload = 0\n node.send(msg);\n}\n}\n","outputs":1,"noerr":0,"x":270,"y":1160,"wires":[["ac850891.101d28"]]},{"id":"d24fef0c.576368","type":"link out","z":"6b333ae.0c170c4","name":"influxDB","links":["86cb0eeb.f5f9d"],"x":135,"y":260,"wires":[]},{"id":"534bc321.36c5d4","type":"change","z":"6b333ae.0c170c4","name":"influxdb","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.DS18B20.Temperature","tot":"msg"},{"t":"set","p":"measurement","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1300,"y":200,"wires":[["b1f7513b.f9e528"]]},{"id":"b1f7513b.f9e528","type":"delay","z":"6b333ae.0c170c4","name":"","pauseType":"queue","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":1470,"y":200,"wires":[["c4f7fb34.7cf768"]]},{"id":"c4f7fb34.7cf768","type":"influxdb out","z":"6b333ae.0c170c4","influxdb":"2778b469.9fa82c","name":"influxDB","measurement":"","precision":"","retentionPolicy":"","x":1640,"y":200,"wires":[]},{"id":"86cb0eeb.f5f9d","type":"link in","z":"6b333ae.0c170c4","name":"","links":["d24fef0c.576368"],"x":1215,"y":200,"wires":[["534bc321.36c5d4"]]},{"id":"ac850891.101d28","type":"link out","z":"6b333ae.0c170c4","name":"input","links":["49cd19c5.18d9b8","90f16f36.e83e78"],"x":355,"y":1160,"wires":[]},{"id":"485dc52c.20a7fc","type":"link out","z":"6b333ae.0c170c4","name":"config","links":["49cd19c5.18d9b8"],"x":355,"y":1080,"wires":[]},{"id":"49cd19c5.18d9b8","type":"link in","z":"6b333ae.0c170c4","name":"outputs","links":["485dc52c.20a7fc","ac850891.101d28","58d6778.cbf3088"],"x":395,"y":960,"wires":[["cc4daea4.a165b8"]]},{"id":"90f16f36.e83e78","type":"link in","z":"6b333ae.0c170c4","name":"","links":["ac850891.101d28"],"x":1215,"y":60,"wires":[["5cd78344.cbf9dc"]]},{"id":"58d6778.cbf3088","type":"link out","z":"6b333ae.0c170c4","name":"","links":["49cd19c5.18d9b8"],"x":1555,"y":20,"wires":[]},{"id":"e1515b45.08edd","type":"debug","z":"6b333ae.0c170c4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1550,"y":140,"wires":[]},{"id":"383b13b6.f51a94","type":"blynk-ws-out-notify","z":"6b333ae.0c170c4","name":"","client":"44e1a68b.8d3478","queue":false,"rate":5,"x":1050,"y":260,"wires":[]},{"id":"e71dd7d4.568a2","type":"function","z":"6b333ae.0c170c4","name":"offline alarm","func":"if (msg.payload == -12700) {\nswitch(msg.topic) {\n case \"200\":\n msg.topic = \"cooler\"\n break;\n case \"201\":\n msg.topic = \"freezer\"\n break;\n case \"202\":\n msg.topic = \"fridge\"\n break;\n case \"100\":\n msg.topic = \"HEXout\"\n break;\n default:\n msg.topic = \"unknown\"\n}\nmsg.payload = msg.topic + \" went offline\"\nreturn msg;\n}","outputs":1,"noerr":0,"x":910,"y":260,"wires":[["383b13b6.f51a94"]]},{"id":"3be9acbe.ed9974","type":"mqtt out","z":"6b333ae.0c170c4","name":"Steam","topic":"cmnd/steam/POWER","qos":"","retain":"","broker":"7473ae41.ca29a","x":950,"y":980,"wires":[]},{"id":"c1eea67a.38b4f","type":"change","z":"6b333ae.0c170c4","name":"101","rules":[{"t":"set","p":"payload","pt":"msg","to":"msg.payload.temp","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"101","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":340,"wires":[["aa94857f.8bc8b8","61fe7ba9.54589c"]]},{"id":"436e273b.355ed8","type":"mqtt out","z":"6b333ae.0c170c4","name":"HEXout","topic":"cmnd/HEXout/CONFIG","qos":"","retain":"","broker":"7473ae41.ca29a","x":960,"y":900,"wires":[]},{"id":"fb181c4d.6d24c","type":"mqtt in","z":"6b333ae.0c170c4","name":"HEXout","topic":"stat/HEXout/RESULT","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":50,"y":400,"wires":[["45f3cbcd.bc06d4"]]},{"id":"71abf5aa.3186cc","type":"function","z":"6b333ae.0c170c4","name":"arduinoPID","func":"var pin = msg.topic\nvar inpin = flow.get(String(pin)+\"pid\")\nvar out = {};\nout.Sp = flow.get(String(pin)+\"setpoint\") //|| 0\nout.Tuning = [flow.get(String(pin)+\"prop_band\"), flow.get(String(pin)+\"t_integral\"), flow.get(String(pin)+\"t_derivative\")]\nout.direction = flow.get(String(pin)+\"direction\")\nout.calctime = flow.get(String(pin)+\"calctime\")\nout.maxoutput = flow.get(String(pin)+\"maxout\")\nout.pollrate = flow.get(String(inpin)+\"pollrate\")\nout.awgweight = flow.get(String(inpin)+\"awgweight\")\nmsg.payload = out\n\nreturn msg;\n\n\n\n\n\n//var input = msg.payload\n//out.Sp = input[3] \n//out.Tuning = [input[4]/100, input[5]/100, input[6]/100] \n//out.direction = input[7]\n//out.calctime = input[8]*1000 \n//out.maxoutput = input[11] \n//out.pollrate = 200\n//out.pwm = 255\n//out.awgweight = 80\n\n//msg.topic=null;\n\n \n\n \n \n","outputs":1,"noerr":0,"x":750,"y":900,"wires":[["436e273b.355ed8","4dbc963e.c178f8"]]},{"id":"45f3cbcd.bc06d4","type":"switch","z":"6b333ae.0c170c4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"temp","vt":"str"},{"t":"hask","v":"out","vt":"str"},{"t":"hask","v":"start","vt":"str"},{"t":"hask","v":"newtunings","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":230,"y":400,"wires":[["c1eea67a.38b4f"],["e2e6d3a3.ae9b5","50a6d71e.c3c5e8"],["f9e823e1.298ea"],["124b63e1.a0cf2c"]]},{"id":"e2e6d3a3.ae9b5","type":"change","z":"6b333ae.0c170c4","name":"6","rules":[{"t":"set","p":"6","pt":"flow","to":"payload.out","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":380,"wires":[[]]},{"id":"f9e823e1.298ea","type":"change","z":"6b333ae.0c170c4","name":"6","rules":[{"t":"set","p":"topic","pt":"msg","to":"6","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":420,"wires":[["22844d22.69d532"]]},{"id":"22844d22.69d532","type":"delay","z":"6b333ae.0c170c4","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":600,"y":420,"wires":[["e0bc6ca6.098e3"]]},{"id":"4dbc963e.c178f8","type":"debug","z":"6b333ae.0c170c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":970,"y":860,"wires":[]},{"id":"e0bc6ca6.098e3","type":"link out","z":"6b333ae.0c170c4","name":"","links":["575010d.0b496f"],"x":715,"y":420,"wires":[]},{"id":"575010d.0b496f","type":"link in","z":"6b333ae.0c170c4","name":"","links":["e0bc6ca6.098e3"],"x":595,"y":860,"wires":[["71abf5aa.3186cc"]]},{"id":"a085147d.03e6f8","type":"inject","z":"6b333ae.0c170c4","name":"Autotune","topic":"","payload":"{\"autotune\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":760,"y":860,"wires":[["436e273b.355ed8"]]},{"id":"50a6d71e.c3c5e8","type":"debug","z":"6b333ae.0c170c4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":460,"wires":[]},{"id":"124b63e1.a0cf2c","type":"change","z":"6b333ae.0c170c4","name":"tunings","rules":[{"t":"set","p":"6newtunings","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":460,"wires":[["50a6d71e.c3c5e8"]]},{"id":"519e3d4c.81bdb4","type":"debug","z":"6b333ae.0c170c4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":220,"y":980,"wires":[]},{"id":"7473ae41.ca29a","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"2778b469.9fa82c","type":"influxdb","z":"","hostname":"192.168.88.30","port":"8086","protocol":"http","database":"brewery","name":"","usetls":false,"tls":""},{"id":"44e1a68b.8d3478","type":"blynk-ws-client","z":"","name":"","path":"ws://blynk-cloud.com/websockets","key":"d-6jb2u_ohwit0qU0PxxwN0npAYwa0KT","dbg_all":false,"dbg_read":false,"dbg_write":false,"dbg_notify":false,"dbg_mail":false,"dbg_prop":false,"dbg_sync":false,"dbg_bridge":false,"dbg_low":false,"dbg_pins":"","multi_cmd":false,"proxy_type":"no","proxy_url":"","enabled":true}]
Add Comment
Please, Sign In to add comment