Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [{"id":"6b333ae.0c170c4","type":"tab","label":"BC","disabled":false,"info":""},{"id":"98499b68.3e438","type":"tab","label":"FC F3","disabled":false,"info":""},{"id":"ded897e3.d4d918","type":"tab","label":"Brewfather","disabled":false,"info":""},{"id":"a46a4b2c.4606c","type":"tab","label":"Room temp","disabled":false,"info":""},{"id":"238efc0d.faa7ac","type":"subflow","name":"Process Simulation","info":"","in":[{"x":37,"y":103,"wires":[{"id":"bd4ff22e.9012f"}]}],"out":[{"x":728.5,"y":294,"wires":[{"id":"8e7ee575.fa952","port":0}]}]},{"id":"2beb7e94.9cf54a","type":"subflow","name":"Subflow 1","info":"","in":[],"out":[{"x":340,"y":80,"wires":[{"id":"9cb7466d.4384e8","port":0}]}]},{"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},{"id":"5e2624e4.7194ac","type":"ui_base","theme":{"name":"theme-light","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#097479","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"},"themeState":{"base-color":{"default":"#0094CE","value":"#0094CE","edited":false},"page-titlebar-backgroundColor":{"value":"#0094CE","edited":false},"page-backgroundColor":{"value":"#fafafa","edited":false},"page-sidebar-backgroundColor":{"value":"#ffffff","edited":false},"group-textColor":{"value":"#1bbfff","edited":false},"group-borderColor":{"value":"#ffffff","edited":false},"group-backgroundColor":{"value":"#ffffff","edited":false},"widget-textColor":{"value":"#111111","edited":false},"widget-backgroundColor":{"value":"#0094ce","edited":false},"widget-borderColor":{"value":"#ffffff","edited":false},"base-font":{"value":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"}},"angularTheme":{"primary":"indigo","accents":"blue","warn":"red","background":"grey"}},"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","lockMenu":"false","allowTempTheme":"true","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}}},{"id":"ff15852f.feb448","type":"key-value-store","z":"","filepath":"store.json","namespace":"","name":""},{"id":"b4285c31.47efb","type":"blynk-ws-client","z":"","name":"F3NR","path":"ws://blynk-cloud.com/websockets","key":"iX3OA1ihf97LFIo3m2U_Fs-2-javnVZU","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},{"id":"4a30623d.a91234","type":"http in","z":"ded897e3.d4d918","name":"","url":"/brewfather","method":"post","upload":false,"swaggerDoc":"","x":80,"y":80,"wires":[["aef5e427.e454a8","1d9001f8.ed4ace","a7d47b15.2958e","43fb2e72.a168c8"]]},{"id":"5aac28ef.ff36c","type":"function","z":"ded897e3.d4d918","name":"BF to BC","func":"flow.set('recipe' , msg.payload.recipe.fermentation)\nflow.set('fbeername' , msg.payload.recipe.name)\n\nfunction numberDes(a,b) {\n return b-a;\n }\n \nfunction stringsort(b,a) {\n return (Number(a.match(/(\\d+)/g)[0]) - Number((b.match(/(\\d+)/g)[0])));\n}\n \nfunction time_convert(num)\n { \n var hours = Math.floor(num / 60); \n var minutes = num % 60;\n return + hours + \":\" + minutes + \":00\"; \n}\nvar hopstandhoptime=[];\nvar hopstandhopname=[];\nvar hopstandhopamount=[];\nvar hopstand\nvar hopstandtemp\nif (msg.payload.recipe.hops.length > 0){\n if (msg.payload.recipe.hopStandMinutes > 0) {\n hopstand = true\n hopstandtemp = msg.payload.recipe.avgWeightedHopstandTemp\n for(var x=0; x<msg.payload.recipe.hops.length; x++){\n if (msg.payload.recipe.hops[x].use == \"Aroma\") {\n hopstandhoptime.push(msg.payload.recipe.hops[x].time)\n hopstandhopname.push(msg.payload.recipe.hops[x].name)\n hopstandhopamount.push(msg.payload.recipe.hops[x].amount)\n }\n }\n \n }\n}\nelse {\n hopstandtemp = 0\n hopstand = false\n}\n\nconst {\n dupstand\n} = hopstandhoptime.reduce(\n (acc, curr) => {\n acc.items[curr] = acc.items[curr] ? acc.items[curr] += 1 : 1\n if (acc.items[curr] === 2) acc.dupstand.push(curr)\n return acc\n }, {\n items: {},\n dupstand: []\n }\n)\n\nfor (x= 0; x<hopstandhoptime.length;x++){\n hopstandhopname[x] = hopstandhopamount[x]+\"g \"+hopstandhopname[x]\n}\n\n\nif (dupstand.length > 0) {\nfor (var i = 0; i<dupstand.length; i++) {\n for (x = (hopstandhoptime.indexOf(dupstand[i])); x < hopstandhoptime.lastIndexOf(dupstand[i]); x++) {\n hopstandhopname[hopstandhoptime.indexOf(dupstand[i])] += \" and \"+ hopstandhopname[x+1] \n delete hopstandhopname[x+1]\n delete hopstandhoptime[x+1]\n }\n} \n \n}\n\nfor (i=0; i<hopstandhoptime.length; i++) {\n if (hopstandhoptime[i] == null) {\n hopstandhoptime.splice(i,1);\n hopstandhopname.splice(i,1);\n i -= 1;\n }\n}\nfor (i=0; i<hopstandhoptime.length; i++) {\n hopstandhopname[i] = hopstandhoptime[i]+\"min \"+ hopstandhopname[i]\n}\n\nhopstandhoptime.sort(numberDes);\nhopstandhopname.sort(stringsort);\n\n\nhopstandhoptime.push(0,0,0,0,0,0,0,0,0,0)\nhopstandhoptime.length = 5\nhopstandhopname.push(\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\")\nhopstandhopname.length = 5\n//hopstandhoptime.push(msg.payload.recipe.hopStandMinutes,msg.payload.recipe.hopStandMinutes,msg.payload.recipe.hopStandMinutes,msg.payload.recipe.hopStandMinutes,msg.payload.recipe.hopStandMinutes);\n//hopstandhopname.push(\"NA\",\"NA\",\"NA\",\"NA\",\"NA\");\n//hopstandhopamount.push(0,0,0,0,0);\n//hopstandhoptime.length = 5\n//hopstandhopname.length = 5\n//hopstandhopamount.length = 5\n\n\nvar firstwort\nif (msg.payload.recipe.hops.length > 0){\nif (msg.payload.recipe.hops[0].use == \"First Wort\") {\n firstwort = true\n}\n}\nelse {\n firstwort = false\n}\n\n\nvar boilhoptime=[];\nvar boilhopname=[];\nvar boilhopamount=[];\nif (msg.payload.recipe.hops.length > 0){\nfor( x=0;x<msg.payload.recipe.hops.length;x++){\n if (msg.payload.recipe.hops[x].use == \"Boil\") {\n boilhoptime.push(msg.payload.recipe.hops[x].time);\n boilhopname.push(msg.payload.recipe.hops[x].name);\n boilhopamount.push(msg.payload.recipe.hops[x].amount);\n }\n} \n}\nif (msg.payload.batchMiscs.length > 0) {\n for ( x=0;x<msg.payload.batchMiscs.length;x++){\n if (msg.payload.batchMiscs[x].use == \"Boil\") {\n boilhoptime.push(msg.payload.batchMiscs[x].time)\n boilhopname.push(msg.payload.batchMiscs[x].name)\n boilhopamount.push(msg.payload.batchMiscs[x].amount)\n }\n }\n}\n\nconst {\n dup\n} = boilhoptime.reduce(\n (acc, curr) => {\n acc.items[curr] = acc.items[curr] ? acc.items[curr] += 1 : 1\n if (acc.items[curr] === 2) acc.dup.push(curr)\n return acc\n }, {\n items: {},\n dup: []\n }\n)\n\nfor (x= 0; x<boilhoptime.length;x++){\n boilhopname[x] = boilhopamount[x]+\"g \"+boilhopname[x]\n}\n\nif (dup.length > 0) {\nfor (var i = 0; i<dup.length; i++) {\n for (x = (boilhoptime.indexOf(dup[i])); x < boilhoptime.lastIndexOf(dup[i]); x++) {\n boilhopname[boilhoptime.indexOf(dup[i])] += \" and \"+ boilhopname[x+1] \n delete boilhopname[x+1]\n delete boilhoptime[x+1]\n }\n} \n}\n\nfor (i=0; i<boilhoptime.length; i++) {\n if (boilhoptime[i] == null) {\n boilhoptime.splice(i,1);\n boilhopname.splice(i,1);\n i -= 1;\n }\n}\nfor (i=0; i<boilhoptime.length; i++) {\n boilhopname[i] = boilhoptime[i]+\"min \"+ boilhopname[i]\n}\n\nboilhoptime.sort(numberDes);\nboilhopname.sort(stringsort);\n\n\nboilhoptime.push(0,0,0,0,0,0,0,0,0,0)\nboilhoptime.length = 10\nboilhopname.push(\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\")\nboilhopname.length = 10\n\nvar mashtime=[];\nfor(var y=0;y<msg.payload.mashStepsCount;y++){\n mashtime[y]= msg.payload.recipe.mash.steps[y].stepTime;\n }\nmashtime.push(0,0,0,0,0);\nmashtime.length = 5\n\nvar mashsteps = msg.payload.mashStepsCount - 1;\nvar mashtemp=[];\nfor(var z=0;z<msg.payload.mashStepsCount;z++){\n mashtemp[z]= msg.payload.recipe.mash.steps[z].stepTemp;\n }\nmashtemp.push(mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps])\nmashtemp.length = 6\n\nmsg.payload = [ \n\n{ \"Name\": \"Preboil volume\", \"Value\": msg.payload.recipe.boilSize } , \n{ \"Name\": \"HLT fillvolume\" , \"Value\": msg.payload.recipe.data.hltWaterAmount } , \n{ \"Name\": \"Sparge volume\" , \"Value\": msg.payload.recipe.data.spargeWaterAmount } , \n{ \"Name\": \"Strike temp\" , \"Value\": msg.payload.recipe.data.strikeTemp } , \n{ \"Name\": \"Mash volume\" , \"Value\": msg.payload.recipe.data.mashWaterAmount } , \n{ \"Name\": \"Mash temp\" , \"Value\": mashtemp[0] } ,\n{ \"Name\": \"Mash temp1\" , \"Value\": mashtemp[1] } , \n{ \"Name\": \"Mash temp2\" , \"Value\": mashtemp[2] } ,\n{ \"Name\": \"Mash temp3\" , \"Value\": mashtemp[3] } ,\n{ \"Name\": \"Mash temp4\" , \"Value\": mashtemp[4] } ,\n{ \"Name\": \"Mash temp5\" , \"Value\": mashtemp[5] } ,\n{ \"Name\": \"Mash time1\" , \"Value\": time_convert(mashtime[0]) } ,\n{ \"Name\": \"Mash time2\" , \"Value\": time_convert(mashtime[1]) } ,\n{ \"Name\": \"Mash time3\" , \"Value\": time_convert(mashtime[2]) } ,\n{ \"Name\": \"Mash time4\" , \"Value\": time_convert(mashtime[3]) } ,\n{ \"Name\": \"Mash time5\" , \"Value\": time_convert(mashtime[4]) } ,\n{ \"Name\": \"Hop time0\" , \"Value\": time_convert(boilhoptime[0]) } ,\n{ \"Name\": \"Hop time1\" , \"Value\": time_convert(boilhoptime[1]) } ,\n{ \"Name\": \"Hop time2\" , \"Value\": time_convert(boilhoptime[2]) } ,\n{ \"Name\": \"Hop time3\" , \"Value\": time_convert(boilhoptime[3]) } ,\n{ \"Name\": \"Hop time4\" , \"Value\": time_convert(boilhoptime[4]) } ,\n{ \"Name\": \"Hop time5\" , \"Value\": time_convert(boilhoptime[5]) } ,\n{ \"Name\": \"Hop time6\" , \"Value\": time_convert(boilhoptime[7]) } ,\n{ \"Name\": \"Hop time8\" , \"Value\": time_convert(boilhoptime[8]) } ,\n{ \"Name\": \"Hop time9\" , \"Value\": time_convert(boilhoptime[9]) } ,\n{ \"Name\": \"Boilhopname0\" , \"Value\": boilhopname[0] } ,\n{ \"Name\": \"Boilhopname1\" , \"Value\": boilhopname[1] } ,\n{ \"Name\": \"Boilhopname2\" , \"Value\": boilhopname[2] } ,\n{ \"Name\": \"Boilhopname3\" , \"Value\": boilhopname[3] } ,\n{ \"Name\": \"Boilhopname4\" , \"Value\": boilhopname[4] } ,\n{ \"Name\": \"Boilhopname5\" , \"Value\": boilhopname[5] } ,\n{ \"Name\": \"Boilhopname6\" , \"Value\": boilhopname[6] } ,\n{ \"Name\": \"Boilhopname7\" , \"Value\": boilhopname[7] } ,\n{ \"Name\": \"Boilhopname8\" , \"Value\": boilhopname[8] } ,\n{ \"Name\": \"Boilhopname9\" , \"Value\": boilhopname[9] } ,\n{ \"Name\": \"Boilsteps\" , \"Value\": msg.payload.boilSteps.length } ,\n{ \"Name\": \"Hopstandtime0\" , \"Value\": time_convert(hopstandhoptime[0])},\n{ \"Name\": \"Hopstandtime1\" , \"Value\": time_convert(hopstandhoptime[1])},\n{ \"Name\": \"Hopstandtime2\" , \"Value\": time_convert(hopstandhoptime[2])},\n{ \"Name\": \"Hopstandtime3\" , \"Value\": time_convert(hopstandhoptime[3])},\n{ \"Name\": \"Hopstandtime4\" , \"Value\": time_convert(hopstandhoptime[4])},\n{ \"Name\": \"Hopstandhopname1\" , \"Value\": hopstandhopname[0]},//String(hopstandhopamount[0]) +\"g\" +\" \" +String(hopstandhopname[0]) } ,\n{ \"Name\": \"Hopstandhopname2\" , \"Value\": hopstandhopname[1]},//String(hopstandhopamount[1]) +\"g\" +\" \" +String(hopstandhopname[1]) } ,\n{ \"Name\": \"Hopstandhopname3\" , \"Value\": hopstandhopname[2]},//String(hopstandhopamount[2]) +\"g\" +\" \" +String(hopstandhopname[2]) } ,\n{ \"Name\": \"Hopstandhopname4\" , \"Value\": hopstandhopname[3]},//String(hopstandhopamount[3]) +\"g\" +\" \" +String(hopstandhopname[3]) } ,\n{ \"Name\": \"Hopstandhopname5\" , \"Value\": hopstandhopname[4]},//String(hopstandhopamount[4]) +\"g\" +\" \" +String(hopstandhopname[4]) } ,\n{ \"Name\": \"Boil time\" , \"Value\": time_convert(msg. payload.recipe.boilTime) } ,\n{ \"Name\": \"Hopstand temp\" , \"Value\": hopstandtemp } ,\n{ \"Name\": \"First wort\" , \"Value\": firstwort } ,\n{ \"Name\": \"Status\" , \"Value\": new Date().toDateString()+\" \"+new Date().getHours()+\":\"+new Date().getMinutes()+\" \" +\"#\"+msg.topic+\" \"+msg.payload.recipe.name }\n\n];\n\nreturn msg;","outputs":1,"noerr":0,"x":580,"y":40,"wires":[["5b8a970c.1845a8","43fb2e72.a168c8"]]},{"id":"5b8a970c.1845a8","type":"http request","z":"ded897e3.d4d918","name":"","method":"PUT","ret":"txt","paytoqs":false,"url":"http://192.168.77.246:8000/globals","tls":"","persist":false,"proxy":"","authType":"","x":750,"y":40,"wires":[[]]},{"id":"aef5e427.e454a8","type":"http response","z":"ded897e3.d4d918","name":"","statusCode":"200","headers":{},"x":740,"y":80,"wires":[]},{"id":"c1ccb79e.8f3fd","type":"mqtt in","z":"a46a4b2c.4606c","name":"","topic":"shellies/#","qos":"2","datatype":"auto","broker":"7473ae41.ca29a","x":80,"y":120,"wires":[["fd06167.1cc2768","8aec9e6b.c8dda8","84740d55.6bc388"]]},{"id":"6d92cd06.4b3c5c","type":"mqtt out","z":"a46a4b2c.4606c","name":"BadVK","topic":"shellies/shelly1pm-BA095A/relay/0/command","qos":"","retain":"","broker":"7473ae41.ca29a","x":1100,"y":60,"wires":[]},{"id":"ba70ae7d.ac754","type":"mqtt out","z":"a46a4b2c.4606c","name":"Stueovn","topic":"shellies/shellyplug-s-0414A5/relay/0/command","qos":"","retain":"","broker":"7473ae41.ca29a","x":1100,"y":100,"wires":[]},{"id":"4b4adb5f.98b49c","type":"function","z":"a46a4b2c.4606c","name":"thermostat","func":"var temp = flow.get('temp')\nvar hysteresis = 0.5\nvar offsetpoint = flow.get('setpoint')\nvar onsetpoint = offsetpoint - hysteresis\n\n if (temp < onsetpoint) {\n msg.payload = \"on\"\n return msg;\n }\n if (temp > offsetpoint) {\n msg.payload = \"off\"\n return msg;\n }\n\n","outputs":1,"noerr":0,"x":830,"y":80,"wires":[["6d92cd06.4b3c5c","ba70ae7d.ac754"]]},{"id":"e9151d7c.9e06f8","type":"switch","z":"a46a4b2c.4606c","name":"temp","property":"topic","propertyType":"msg","rules":[{"t":"regex","v":"temperature","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":120,"wires":[["4c9b00b5.0395a8"]]},{"id":"2ddbeafd.748966","type":"switch","z":"a46a4b2c.4606c","name":"overtemp","property":"topic","propertyType":"msg","rules":[{"t":"regex","v":"overtemperature","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":1,"x":480,"y":240,"wires":[["c0708c40.2f54d8"]]},{"id":"c0708c40.2f54d8","type":"switch","z":"a46a4b2c.4606c","name":"overtemp","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":640,"y":240,"wires":[["14f56b22.574d95"]]},{"id":"fd06167.1cc2768","type":"switch","z":"a46a4b2c.4606c","name":"shellyht","property":"topic","propertyType":"msg","rules":[{"t":"regex","v":"shellyht","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":1,"x":260,"y":120,"wires":[["e9151d7c.9e06f8","4cb219a4.51f728","d81ddb6a.22946"]]},{"id":"4cb219a4.51f728","type":"switch","z":"a46a4b2c.4606c","name":"humid","property":"topic","propertyType":"msg","rules":[{"t":"regex","v":"humidity","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":160,"wires":[["e6d0d5e7.87f6c8"]]},{"id":"d81ddb6a.22946","type":"switch","z":"a46a4b2c.4606c","name":"battery","property":"topic","propertyType":"msg","rules":[{"t":"regex","v":"battery","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":200,"wires":[["f78e5de6.147858"]]},{"id":"e50b968b.39538","type":"blynk-ws-in-write","z":"a46a4b2c.4606c","name":"Setpoint","pin":"2","pin_all":0,"client":"44e1a68b.8d3478","x":480,"y":60,"wires":[["5cea4925.825058"]]},{"id":"5cea4925.825058","type":"change","z":"a46a4b2c.4606c","name":"store sp","rules":[{"t":"set","p":"setpoint","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":60,"wires":[["4b4adb5f.98b49c"]]},{"id":"4c9b00b5.0395a8","type":"change","z":"a46a4b2c.4606c","name":"store temp","rules":[{"t":"set","p":"temp","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":100,"wires":[["4b4adb5f.98b49c","ae937c82.43945"]]},{"id":"ae937c82.43945","type":"blynk-ws-out-write","z":"a46a4b2c.4606c","name":"temp","pin":"3","pinmode":0,"client":"44e1a68b.8d3478","x":810,"y":120,"wires":[]},{"id":"e6d0d5e7.87f6c8","type":"blynk-ws-out-write","z":"a46a4b2c.4606c","name":"humidity","pin":"4","pinmode":0,"client":"44e1a68b.8d3478","x":820,"y":160,"wires":[]},{"id":"f78e5de6.147858","type":"blynk-ws-out-write","z":"a46a4b2c.4606c","name":"battery","pin":"5","pinmode":0,"client":"44e1a68b.8d3478","x":820,"y":200,"wires":[]},{"id":"14f56b22.574d95","type":"change","z":"a46a4b2c.4606c","name":"off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":240,"wires":[["6d92cd06.4b3c5c"]]},{"id":"8aec9e6b.c8dda8","type":"switch","z":"a46a4b2c.4606c","name":"shelly1pm","property":"topic","propertyType":"msg","rules":[{"t":"regex","v":"shelly1pm","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":1,"x":260,"y":160,"wires":[["2ddbeafd.748966"]]},{"id":"84740d55.6bc388","type":"switch","z":"a46a4b2c.4606c","name":"shellyplug","property":"topic","propertyType":"msg","rules":[{"t":"regex","v":"shellyplug","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":1,"x":260,"y":200,"wires":[["43adf891.4e7dd8"]]},{"id":"43adf891.4e7dd8","type":"switch","z":"a46a4b2c.4606c","name":"overtemp","property":"topic","propertyType":"msg","rules":[{"t":"regex","v":"overtemperature","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":1,"x":480,"y":280,"wires":[["7ecca14d.4d1328"]]},{"id":"7ecca14d.4d1328","type":"switch","z":"a46a4b2c.4606c","name":"overtemp","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":640,"y":280,"wires":[["2a09031.e7bca7c"]]},{"id":"2a09031.e7bca7c","type":"change","z":"a46a4b2c.4606c","name":"off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":280,"wires":[["ba70ae7d.ac754"]]},{"id":"35862dea.842bda","type":"function","z":"238efc0d.faa7ac","name":"30 sec RC + 20","func":"// Applies a simple RC low pass filter to incoming payload values\nvar tc = 30*1000; // time constant in milliseconds\n\nvar lastValue = context.get('lastValue');\nif (typeof lastValue == \"undefined\") lastValue = msg.payload;\nvar lastTime = context.get('lastTime') || null;\nvar now = new Date();\nvar currentValue = msg.payload;\nif (lastTime === null) {\n // first time through\n newValue = currentValue;\n} else {\n var dt = now - lastTime;\n var newValue;\n \n if (dt > 0) {\n var dtotc = dt / tc;\n newValue = lastValue * (1 - dtotc) + currentValue * dtotc;\n } else {\n // no time has elapsed leave output the same as last time\n newValue = lastValue;\n }\n}\ncontext.set('lastValue', newValue);\ncontext.set('lastTime', now);\n\nmsg.payload = newValue + 20;\nreturn msg;","outputs":1,"noerr":0,"x":626.5,"y":207,"wires":[["8e7ee575.fa952"]]},{"id":"10323c91.ebbceb","type":"inject","z":"238efc0d.faa7ac","name":"Inject -0.2 at start","topic":"","payload":"-0.2","payloadType":"num","repeat":"","crontab":"","once":true,"x":134.5,"y":30,"wires":[["bd4ff22e.9012f"]]},{"id":"5b04738.d495d0c","type":"function","z":"238efc0d.faa7ac","name":"10 sec RC","func":"// Applies a simple RC low pass filter to incoming payload values\nvar tc = 10*1000; // time constant in milliseconds\n\nvar lastValue = context.get('lastValue');\nif (typeof lastValue == \"undefined\") lastValue = msg.payload;\nvar lastTime = context.get('lastTime') || null;\nvar now = new Date();\nvar currentValue = msg.payload;\nif (lastTime === null) {\n // first time through\n newValue = currentValue;\n} else {\n var dt = now - lastTime;\n var newValue;\n \n if (dt > 0) {\n var dtotc = dt / tc;\n newValue = lastValue * (1 - dtotc) + currentValue * dtotc;\n } else {\n // no time has elapsed leave output the same as last time\n newValue = lastValue;\n }\n}\ncontext.set('lastValue', newValue);\ncontext.set('lastTime', now);\n\nmsg.payload = newValue;\nreturn msg;","outputs":1,"noerr":0,"x":451,"y":207,"wires":[["35862dea.842bda"]]},{"id":"bd4ff22e.9012f","type":"delay","z":"238efc0d.faa7ac","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":268,"y":104,"wires":[["e448dace.aed4"]]},{"id":"bcea1598.53f26","type":"function","z":"238efc0d.faa7ac","name":"2 msg transport delay","func":"// stores messages in a fifo until the specified number have been received, \n// then releases them as new messages are received.\n// during the filling phase the earliest message is passed on each time \n// a message is received, but it is also left in the fifo\nvar fifoMaxLength = 2;\nvar fifo = context.get('fifo') || [];\n// push the new message onto the top of the array, messages are shifted down and\n// drop off the front\nvar length = fifo.push(msg); // returns new length\nif (length > fifoMaxLength) {\n newMsg = fifo.shift();\n} else {\n // not full yet, make a copy of the msg and pass it on\n var newMsg = JSON.parse(JSON.stringify(fifo[0]));\n}\ncontext.set('fifo', fifo);\nreturn newMsg;","outputs":1,"noerr":0,"x":258,"y":208,"wires":[["5b04738.d495d0c"]]},{"id":"8e7ee575.fa952","type":"function","z":"238efc0d.faa7ac","name":"Clear all except payload","func":"msg2 = {payload: msg.payload};\nreturn msg2;","outputs":1,"noerr":0,"x":545,"y":293,"wires":[[]]},{"id":"e448dace.aed4","type":"range","z":"238efc0d.faa7ac","minin":"0","maxin":"1","minout":"0","maxout":"100","action":"scale","round":false,"name":"","x":87,"y":208,"wires":[["bcea1598.53f26"]]},{"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 }\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 //for (i = 0; i < r.length; i++) {\n \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\nmsg.topic = \"tick\"\nmsg.payload = Date.now()\nreturn [ msg, null];\n \n \n\n","outputs":2,"noerr":0,"x":190,"y":580,"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)+\"pin\", u[i][2])\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)+\"delay\", u[i][5]*1000)\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)+\"pin\", u[i][2])\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 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) {\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 flow.set(String(pin)+\"config\", 99)\n flow.set(String(pin)+\"dcpower\", 0)\n flow.set(String(pin)+\"dctime\", 0)\n }\n \n if (previousconfig === 5) { //hysteresis\n flow.set(String(pin)+\"config\", config)\n //flow.set(String(pin)+\"pin\", 0)\n flow.set(String(pin)+\"setpoint\", 0)\n flow.set(String(pin)+\"setpoint2\", 0)\n flow.set(String(pin)+\"ondelay\", 0)\n msg.topic = pin\n msg.payload = 0\n node.send(msg);\n }\n \n \n if (previousconfig === 6) {\n flow.set(String(pin)+\"config\", 99)\n flow.set(String(u[i][2])+\"config\", 0)\n flow.set(String(u[i][2])+\"pin\", 0)\n flow.set(String(pin)+\"pin\", 0)\n flow.set(String(pin)+\"pid\", 0)\n flow.set(String(pin)+\"setpoint\", 0)\n flow.set(String(pin)+\"prop_band\", 0)\n flow.set(String(pin)+\"t_integral\", 0)\n flow.set(String(pin)+\"t_derivative\",0)\n flow.set(String(pin)+\"direction\", 0)\n flow.set(String(pin)+\"calctime\", 0)\n flow.set(String(pin)+\"outtime\", 0)\n flow.set(String(pin)+\"maxout\", 0)\n msg.topic = pin\n msg.enable = 0\n msg.payload = [msg.payload[0][0], msg.payload[0][1]]\n node.send(msg)\n }\n if (previousconfig === 7) { //pwm\n flow.set(String(pin)+\"config\", 99)\n flow.set(String(pin), 0)\n msg.topic = pin\n msg.payload = flow.get(String(pin))\n node.send(msg);\n }\n if (previousconfig === 8) { //analoginput\n flow.set(String(pin)+\"pollrate\", 0)\n flow.set(String(pin)+\"awgweight\", 0)\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":330,"y":580,"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":580,"wires":[["361a3004.4b084"]]},{"id":"e6c5affa.506c2","type":"tcp out","z":"6b333ae.0c170c4","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"","x":330,"y":640,"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":650,"y":640,"wires":[[],[],[],[],[],["71abf5aa.3186cc"],[],["3be9acbe.ed9974","27d335ad.da0b9a"],[],[],["3c7347ac.ddd05"],[],[],[],[],["10332a50.3a4f5e"],["342b38e.4fe84c8","daee8069.09aa7"]]},{"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":50,"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":50,"y":100,"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}],"checkall":"true","repair":false,"outputs":4,"x":190,"y":60,"wires":[["1c32ec5.e742914"],["4f7d669a.9593e"],["63999e79.8f04c"],["f30a2071.adbe58"]]},{"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"},{"t":"set","p":"4","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":20,"wires":[[]]},{"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"},{"t":"set","p":"8","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":60,"wires":[[]]},{"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"},{"t":"set","p":"11","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":100,"wires":[[]]},{"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"},{"t":"set","p":"16","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":140,"wires":[[]]},{"id":"ae2aff4e.1abb3","type":"change","z":"6b333ae.0c170c4","name":"17","rules":[{"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"},{"t":"set","p":"17","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":180,"wires":[[]]},{"id":"74f3ce1a.6b5d98","type":"mqtt in","z":"6b333ae.0c170c4","name":"Sensor","topic":"tele/+/SENSOR","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":50,"y":260,"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}],"checkall":"true","repair":false,"outputs":2,"x":230,"y":280,"wires":[["660cb740.453d78"],["d9ce9fc7.d6b4b"]]},{"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.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","76e10617.6856a8"]]},{"id":"10332a50.3a4f5e","type":"mqtt out","z":"6b333ae.0c170c4","name":"Cooler ctrl","topic":"cmnd/cooler/POWER","qos":"","retain":"","broker":"7473ae41.ca29a","x":1070,"y":760,"wires":[]},{"id":"3c7347ac.ddd05","type":"mqtt out","z":"6b333ae.0c170c4","name":"Freezer ctrl","topic":"cmnd/freezer/POWER","qos":"","retain":"","broker":"7473ae41.ca29a","x":1070,"y":700,"wires":[]},{"id":"1a5a5b63.40f1bd","type":"mqtt out","z":"6b333ae.0c170c4","name":"Fridge ctrl","topic":"shellies/F3/relay/0/command","qos":"","retain":"","broker":"7473ae41.ca29a","x":1060,"y":820,"wires":[]},{"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"]]},{"id":"61fe7ba9.54589c","type":"link out","z":"6b333ae.0c170c4","name":"","links":["4b91c95.9c9ddb8"],"x":835,"y":260,"wires":[]},{"id":"4b91c95.9c9ddb8","type":"link in","z":"6b333ae.0c170c4","name":"","links":["61fe7ba9.54589c","1a03dc0b.4ed044"],"x":235,"y":540,"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":1500,"y":60,"wires":[[]]},{"id":"9977ef80.f4948","type":"function","z":"6b333ae.0c170c4","name":"input","func":"if (typeof(msg.payload) !== \"undefined\") {\n\n var pin = msg.topic\n var value = msg.payload\n flow.set(pin,value)\n\n if (flow.get(String(pin)+\"config\") === 5 && pin >= 100 ){ //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 cooling = flow.get(String(outpin)+\"cooling\") || false\n var delay = flow.get(String(outpin)+\"delay\")\n var out = flow.get(String(outpin)+\"out\")\n \n \n if (value < setpoint) {\n if (cooling === true) {\n out = false\n } else {\n out = true\n }\n }\n if (value > setpoint2) {\n if (cooling === true) {\n out = true\n } else {\n out = false\n }\n }\n \n if (value === -12700) {\n out = false\n }\n \n if (config == 99) {\n out = false\n }\n if (out !== flow.get(String(outpin)+\"out\")) {\n flow.set(String(outpin)+\"out\", out)\n if (out === false) {\n context.set(String(outpin)+\"status\", Number(out))\n msg.topic = outpin\n msg.payload = Number(flow.get(String(outpin)+\"out\"))\n node.send(msg);\n }\n \n if (out === true && config !== 99 && value !== -12700) {\n setTimeout(start, delay)\n }\n }\n setTimeout(mismatch, 2000)\n}\n//PID\n if (flow.get(String(pin)+\"config\") === 6) {\n 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}\n\nfunction start() {\n if (config !== 99 && value !== -12700) {\n context.set(String(outpin)+\"status\", Number(flow.get(String(outpin)+\"out\")))\n msg.topic = outpin\n msg.payload = Number(flow.get(String(outpin)+\"out\"))\n node.send(msg);\n }\n \n}\n\nfunction mismatch() {\n if (context.get(String(outpin)+\"status\") !== flow.get(String(outpin)) ) {\n context.set(String(outpin)+\"status\", Number(flow.get(String(outpin)+\"out\")))\n if (Number(flow.get(String(outpin)+\"out\")) === 1 && config !== 99 && value !== -12700) {\n setTimeout(start, delay)\n }\n if (Number(flow.get(String(outpin)+\"out\")) === 0) {\n msg.payload = Number(flow.get(String(outpin)+\"out\"))\n msg.topic = outpin\n node.send(msg)\n }\n }\n}","outputs":1,"noerr":0,"x":330,"y":540,"wires":[["ac850891.101d28"]]},{"id":"d24fef0c.576368","type":"link out","z":"6b333ae.0c170c4","name":"influxDB","links":["86cb0eeb.f5f9d"],"x":135,"y":240,"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":415,"y":540,"wires":[]},{"id":"485dc52c.20a7fc","type":"link out","z":"6b333ae.0c170c4","name":"config","links":["49cd19c5.18d9b8"],"x":415,"y":580,"wires":[]},{"id":"49cd19c5.18d9b8","type":"link in","z":"6b333ae.0c170c4","name":"outputs","links":["485dc52c.20a7fc","ac850891.101d28","58d6778.cbf3088","4cda1db0.907e14"],"x":575,"y":640,"wires":[["cc4daea4.a165b8"]]},{"id":"90f16f36.e83e78","type":"link in","z":"6b333ae.0c170c4","name":"","links":["ac850891.101d28"],"x":1215,"y":60,"wires":[["5cd78344.cbf9dc"]]},{"id":"e1515b45.08edd","type":"debug","z":"6b333ae.0c170c4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1690,"y":80,"wires":[]},{"id":"383b13b6.f51a94","type":"blynk-ws-out-notify","z":"6b333ae.0c170c4","name":"","client":"44e1a68b.8d3478","queue":false,"rate":5,"x":1070,"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 = \"something\"\n}\nmsg.payload = msg.topic + \" went offline\"\nreturn msg;\n}","outputs":1,"noerr":0,"x":930,"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":1050,"y":640,"wires":[]},{"id":"436e273b.355ed8","type":"mqtt out","z":"6b333ae.0c170c4","name":"HEXout","topic":"cmnd/HEXout/CONFIG","qos":"","retain":"","broker":"7473ae41.ca29a","x":1060,"y":580,"wires":[]},{"id":"fb181c4d.6d24c","type":"mqtt in","z":"6b333ae.0c170c4","name":"HEXout","topic":"stat/HEXout/RESULT","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":230,"y":360,"wires":[["da247bbc.f94b98"]]},{"id":"71abf5aa.3186cc","type":"function","z":"6b333ae.0c170c4","name":"arduinoPID","func":"\nvar pin = msg.topic\n\nif (Array.isArray(msg.payload) && msg.topic === pin) {\n if (msg.payload[1] == 6) {\n context.set(\"inpin\", msg.payload[2])\n setTimeout(sendconfig, 500);\n}\nif (msg.payload[1] == 99) {\n flow.set(String(pin)+\"maxout\", 0)\n setTimeout(sendconfig, 500);\n}\n}\n\nif (msg.payload.hasOwnProperty('temp')) {\n var inpin = context.get(\"inpin\")\n if (typeof (context.get(\"inpin\")) !== 'undefined') {\n flow.set(String(pin), msg.payload.out)\n flow.set(String(inpin), msg.payload.temp)\n }\n}\n\nif (msg.payload.hasOwnProperty('start')) {\n setTimeout(sendconfig, 1000);\n}\n\nif (msg.payload.hasOwnProperty('newtunings')) {\n\nif (msg.payload.newtunings === \"tuning\") {\n node.status({fill:\"yellow\",shape:\"dot\",text:\"tuning\"});\n} \nif (msg.payload.newtunings === \"canceled\") {\n node.status({fill:\"red\",shape:\"dot\",text:\"tuning canceled\"});\n}\n\nif (Array.isArray(msg.payload.newtunings)) {\n flow.set(String(6)+\"tunings\", msg.payload.newtunings)\n node.status({fill:\"blue\",text:String(msg.payload.newtunings)});\n}\n}\n\nif (msg.payload.hasOwnProperty('autotune')) {\n msg.payload.autotune = 1\n node.send(msg)\n}\n\nfunction sendconfig() {\n var out = {};\n inpin = context.get(\"inpin\")\n out.Sp = flow.get(String(pin)+\"setpoint\") //|| 0\n out.Tuning = [flow.get(String(pin)+\"prop_band\"), flow.get(String(pin)+\"t_integral\"), flow.get(String(pin)+\"t_derivative\")]\n out.direction = flow.get(String(pin)+\"direction\")\n out.calctime = flow.get(String(pin)+\"calctime\")\n out.maxoutput = flow.get(String(pin)+\"maxout\")\n out.pollrate = flow.get(String(inpin)+\"pollrate\")\n out.awgweight = flow.get(String(inpin)+\"awgweight\")\n msg.payload = out\n node.send(msg)\n}","outputs":1,"noerr":0,"x":870,"y":600,"wires":[["436e273b.355ed8"]]},{"id":"a085147d.03e6f8","type":"inject","z":"6b333ae.0c170c4","name":"Autotune","topic":"6","payload":"{\"autotune\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":400,"wires":[["da247bbc.f94b98"]]},{"id":"c8ed24a3.4fc378","type":"change","z":"6b333ae.0c170c4","name":"Get tunings","rules":[{"t":"set","p":"payload","pt":"msg","to":"6tunings","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":40,"wires":[["99820b57.71ee28"]]},{"id":"d24bea89.5d2de8","type":"inject","z":"6b333ae.0c170c4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":700,"y":40,"wires":[["c8ed24a3.4fc378"]]},{"id":"99820b57.71ee28","type":"debug","z":"6b333ae.0c170c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1010,"y":40,"wires":[]},{"id":"4cda1db0.907e14","type":"link out","z":"6b333ae.0c170c4","name":"","links":["49cd19c5.18d9b8"],"x":555,"y":340,"wires":[]},{"id":"da247bbc.f94b98","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":340,"wires":[["4cda1db0.907e14"]]},{"id":"342b38e.4fe84c8","type":"debug","z":"6b333ae.0c170c4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":910,"y":860,"wires":[]},{"id":"6f8ded8f.aef164","type":"mqtt in","z":"6b333ae.0c170c4","name":"F3","topic":"shellies/F3/relay/0","qos":"2","datatype":"auto","broker":"7473ae41.ca29a","x":230,"y":180,"wires":[["ae2aff4e.1abb3"]]},{"id":"f0563082.b7ab6","type":"mqtt in","z":"6b333ae.0c170c4","name":"F3","topic":"F3","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":50,"y":380,"wires":[["34bd517c.371c1e","76e10617.6856a8"]]},{"id":"76e10617.6856a8","type":"debug","z":"6b333ae.0c170c4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":380,"wires":[]},{"id":"34bd517c.371c1e","type":"switch","z":"6b333ae.0c170c4","name":"topic","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"Temperature","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":230,"y":320,"wires":[["d46086dd.fb5d5"]]},{"id":"daee8069.09aa7","type":"change","z":"6b333ae.0c170c4","name":"17","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"on","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":820,"wires":[[]]},{"id":"e2d28b1c.c92368","type":"debug","z":"6b333ae.0c170c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":700,"y":140,"wires":[]},{"id":"736d6a3e.245534","type":"change","z":"6b333ae.0c170c4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"17","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":460,"wires":[["2cb84596.05382a"]]},{"id":"2cb84596.05382a","type":"debug","z":"6b333ae.0c170c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":700,"y":460,"wires":[]},{"id":"6b4d3ba6.05bf84","type":"inject","z":"6b333ae.0c170c4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":460,"wires":[["736d6a3e.245534"]]},{"id":"c954ed94.b0e9f","type":"key-value-write","z":"ded897e3.d4d918","store":"ff15852f.feb448","action":"set","key":"","keyvalue":"","name":"","x":430,"y":40,"wires":[["5aac28ef.ff36c"]]},{"id":"1d9001f8.ed4ace","type":"change","z":"ded897e3.d4d918","name":"set batchnumber","rules":[{"t":"set","p":"topic","pt":"msg","to":"$string(payload.batchNo)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":40,"wires":[["c954ed94.b0e9f"]]},{"id":"e1177be8.508e08","type":"key-value-read","z":"98499b68.3e438","store":"ff15852f.feb448","key":"","name":"","x":330,"y":340,"wires":[["ebc927e1.4df8a"]]},{"id":"91bef7d7.98a6d","type":"change","z":"98499b68.3e438","name":"set batchnumber","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":380,"wires":[["e1177be8.508e08"]]},{"id":"8826bc36.739ab8","type":"blynk-ws-in-write","z":"98499b68.3e438","name":"Batchno","pin":"8","pin_all":0,"client":"b4285c31.47efb","x":60,"y":320,"wires":[["b63232a7.2c928"]]},{"id":"d1138b3f.e3afd","type":"blynk-ws-in-write","z":"98499b68.3e438","name":"Button","pin":"9","pin_all":0,"client":"b4285c31.47efb","x":50,"y":280,"wires":[["3ed5ef4f.18f45"]]},{"id":"8689d276.8ff0d8","type":"inject","z":"98499b68.3e438","name":"start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"1","x":70,"y":160,"wires":[["759ea408.f3f454"]]},{"id":"ebc927e1.4df8a","type":"change","z":"98499b68.3e438","name":"store","rules":[{"t":"set","p":"fermentationStartDate","pt":"flow","to":"payload.fermentationStartDate","tot":"jsonata"},{"t":"set","p":"stepTemp","pt":"flow","to":"payload.recipe.fermentation.steps.stepTemp\t","tot":"jsonata"},{"t":"set","p":"stepTime","pt":"flow","to":"payload.recipe.fermentation.steps.stepTime","tot":"jsonata"},{"t":"set","p":"steps","pt":"flow","to":"$count(msg.payload.recipe.fermentation.steps)\t","tot":"jsonata"},{"t":"set","p":"finished","pt":"flow","to":"$sum(payload.recipe.fermentation.steps.stepTime)\t\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":340,"wires":[["bae475ec.c02178","a28572cc.837d58"]]},{"id":"9de84d6b.b025f","type":"inject","z":"98499b68.3e438","name":"now","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":true,"onceDelay":"5","x":730,"y":560,"wires":[["a1838381.085a18","b8a02bbc.1334a8"]]},{"id":"a1838381.085a18","type":"function","z":"98499b68.3e438","name":"Calc&store SP","func":"\nvar steptype\nvar pressuresp\n\nvar now = msg.payload / 1000 /3600 / 24\nvar start = flow.get('fermentationStartDate') / 1000 /3600 /24\nvar steps = flow.get('steps') - 1\nvar stepTemp = flow.get('stepTemp')\nvar stepTime = flow.get('stepTime')\nvar stepcounter = 0\nvar nextsteptime = start+stepTime[0]\nvar elapsed = now - start\nflow.set('elapsed', elapsed)\n\nfor (var i=1;i<=steps;i++) {\n if (now > nextsteptime) {\n stepcounter += 1;\n nextsteptime += stepTime[i];\n }\n}\n \n\nvar target = stepTemp[stepcounter]\nflow.set('target', target)\n\nsteptype = flow.get('steptype')\nsteptype = steptype[stepcounter]\nflow.set('stepcounter', stepcounter)\n\nif (global.get(\"F3pauto\") === true) {\n pressuresp = flow.get('pressuresp')\n pressuresp = pressuresp[stepcounter]\n if (pressuresp === null) {\n pressuresp = 0\n }\n} else {\n pressuresp = flow.get('newpressuresp')\n}\n\n\nmsg.payload = {\n //\"Stepcounter\": stepcounter,\n //\"Target\": target,\n //\"Start\": start,\n //\"Nextsteptime\": nextsteptime,\n //\"Now\": now,\n \"Steptype\": steptype,\n \"PressureSP\": pressuresp\n}\nmsg.pick = stepcounter\nreturn msg; \n","outputs":1,"noerr":0,"x":980,"y":560,"wires":[["f76488ea.bef49","c669a260.63b4","30769f4.13388e"]]},{"id":"3ed5ef4f.18f45","type":"blynk-ws-out-sync","z":"98499b68.3e438","name":"Batchno-sync","pin":"8","pinmode":0,"client":"b4285c31.47efb","x":280,"y":280,"wires":[]},{"id":"251c439.d8cd83c","type":"function","z":"98499b68.3e438","name":"thermostat","func":"var temp = flow.get('temp')||20\nvar hyst = 0.5\nvar ambient = flow.get('ambient')||20\nvar heat = flow.get('heat')||\"off\"\nvar cool = flow.get('cool')||\"off\"\nvar target\n\n\nif (global.get(\"F3tauto\") === true) {\n target = flow.get(\"target\")\n} else {\n target = flow.get(\"newtarget\")\n}\n\n//heat\nif (temp < target - hyst) {//&& (ambient < target)) {\n heat = \"on\"\n flow.set('heat', heat)\n }\nif (temp > target) {\n heat = \"off\"\n flow.set('heat', heat)\n}\n \n//cool\nif (temp > (target + hyst)) {\n cool = \"on\"\n flow.set('cool', cool)\n }\n\nif (temp < target) {\n cool = \"off\" \n flow.set('cool', cool)\n }\n \nif (flow.get('heatingstopped') === true) {\n heat = \"off\"\n flow.set('heat', heat)\n}\nif (flow.get('coolingstopped') === true) {\n cool = \"off\" \n flow.set('cool', cool)\n}\n\nmsg.topic = \"thermostat\"\nmsg.payload = { \"heat\": heat, \"cool\": cool}\n \nreturn msg;","outputs":1,"noerr":0,"x":590,"y":520,"wires":[["62973e8c.2a2b1","ae73a195.1ba24"]]},{"id":"30769f4.13388e","type":"blynk-ws-out-table","z":"98499b68.3e438","name":"table","pin":"5","client":"b4285c31.47efb","x":1150,"y":300,"wires":[]},{"id":"bae475ec.c02178","type":"change","z":"98499b68.3e438","name":"clear table","rules":[{"t":"set","p":"clear","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":300,"wires":[["30769f4.13388e"]]},{"id":"b52032e3.b386f","type":"function","z":"98499b68.3e438","name":"update table","func":"\nvar loadtable = [];\n\nfor (var i = 0; i < msg.payload.recipe.fermentation.steps.length; i++) {\n loadtable.push(\n [msg.payload.recipe.fermentation.steps[i].type+ \" for \"+ msg.payload.recipe.fermentation.steps[i].stepTime + \" days\" + \" @ \"+ msg.payload.recipe.fermentation.steps[i].pressure+ \" psi\", \n msg.payload.recipe.fermentation.steps[i].stepTemp + \" °C\"]\n )\n}\nmsg.loadtable = loadtable\nreturn msg;","outputs":1,"noerr":0,"x":970,"y":340,"wires":[["30769f4.13388e"]]},{"id":"e6b90c3e.5371","type":"delay","z":"98499b68.3e438","name":"limit","pauseType":"rate","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":730,"y":340,"wires":[["b52032e3.b386f","e7d2df51.180fb","2b5892c0.9b5c46"]]},{"id":"58a1cbc3.bed194","type":"blynk-ws-out-write","z":"98499b68.3e438","name":"beername","pin":"4","pinmode":0,"client":"b4285c31.47efb","x":1220,"y":420,"wires":[]},{"id":"e7d2df51.180fb","type":"function","z":"98499b68.3e438","name":"set beername","func":"var elapsed = Math.floor(flow.get('elapsed'))\n\nbeername = msg.payload.recipe.name + \" @ day \" + elapsed\nmsg.payload = beername\nreturn msg;","outputs":1,"noerr":0,"x":980,"y":420,"wires":[["58a1cbc3.bed194"]]},{"id":"b17e38b9.4fe148","type":"change","z":"98499b68.3e438","name":"cooling stop","rules":[{"t":"set","p":"coolingstopped","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":680,"wires":[[]]},{"id":"f0f2fe6f.18de9","type":"change","z":"98499b68.3e438","name":"cooling start","rules":[{"t":"set","p":"coolingstopped","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":720,"wires":[[]]},{"id":"fa21121b.8cce3","type":"change","z":"98499b68.3e438","name":"heating stop","rules":[{"t":"set","p":"heatingstopped","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":640,"wires":[[]]},{"id":"9efb284a.9a4a28","type":"change","z":"98499b68.3e438","name":"heating start","rules":[{"t":"set","p":"heatingstopped","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":600,"wires":[[]]},{"id":"47d7e018.389978","type":"mqtt in","z":"98499b68.3e438","name":"","topic":"F3","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":50,"y":420,"wires":[["e4c70a65.ef2898"]]},{"id":"9d22618c.741e18","type":"change","z":"98499b68.3e438","name":"temp","rules":[{"t":"set","p":"temp","pt":"flow","to":"payload.Temperature","tot":"msg"},{"t":"set","p":"ambient","pt":"flow","to":"payload.Ambient","tot":"msg"},{"t":"set","p":"pressure","pt":"flow","to":"payload.Pressure","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":460,"wires":[[]]},{"id":"62973e8c.2a2b1","type":"function","z":"98499b68.3e438","name":"set status","func":"\n\nvar status = \"Waiting\"\n\nif (msg.payload.heat == \"on\") {\n status = \"Heating\"\n}\n\nif (msg.payload.cool == \"on\") {\n status = \"Cooling\"\n}\n\nif (msg.payload.cool == \"off\" && msg.payload.heat == \"off\") {\n status = \"Idle\"\n}\n\nmsg.payload = status\nreturn msg;","outputs":1,"noerr":0,"x":960,"y":520,"wires":[["bcc14f67.93f54"]]},{"id":"bcc14f67.93f54","type":"blynk-ws-out-write","z":"98499b68.3e438","name":"status","pin":"2","pinmode":0,"client":"b4285c31.47efb","x":1210,"y":480,"wires":[]},{"id":"9c59efe0.26482","type":"blynk-ws-out-write","z":"98499b68.3e438","name":"temp","pin":"6","pinmode":0,"client":"b4285c31.47efb","x":570,"y":480,"wires":[]},{"id":"a7153630.bb8798","type":"mqtt in","z":"98499b68.3e438","name":"","topic":"Tilt","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":50,"y":120,"wires":[["16717f4f.d41361","fcf136db.305998"]]},{"id":"ba91348a.d76ff","type":"mqtt out","z":"98499b68.3e438","name":"","topic":"","qos":"","retain":"","broker":"7473ae41.ca29a","x":1390,"y":520,"wires":[]},{"id":"2b5892c0.9b5c46","type":"function","z":"98499b68.3e438","name":"Step type","func":"\nvar steptype = [];\n\nfor (var i = 0; i < msg.payload.recipe.fermentation.steps.length; i++) {\n steptype.push(\n msg.payload.recipe.fermentation.steps[i].type\n )\n}\nflow.set('steptype', steptype)\n\nvar pressuresp =[];\n\nfor (var x = 0; x < msg.payload.recipe.fermentation.steps.length; x++) {\n pressuresp.push(\n msg.payload.recipe.fermentation.steps[x].pressure\n )\n}\nflow.set('pressuresp', pressuresp)\n","outputs":1,"noerr":0,"x":960,"y":380,"wires":[[]]},{"id":"37cfe35e.cb3294","type":"blynk-ws-in-write","z":"98499b68.3e438","name":"Tiltselector","pin":"3","pin_all":0,"client":"b4285c31.47efb","x":60,"y":200,"wires":[["ac550f41.cc4808"]]},{"id":"ac550f41.cc4808","type":"change","z":"98499b68.3e438","name":"Tiltselector","rules":[{"t":"set","p":"F3tiltselector","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":200,"wires":[[]]},{"id":"e92b1ea2.ae45e","type":"blynk-ws-out-write","z":"98499b68.3e438","name":"Tilt value","pin":"10","pinmode":0,"client":"b4285c31.47efb","x":960,"y":100,"wires":[]},{"id":"16717f4f.d41361","type":"function","z":"98499b68.3e438","name":"Tiltselector","func":"if (msg.payload.Tilt == \"Red\") {\n flow.set('redtilt', msg.payload.Gravity)\n}\n\nif (msg.payload.Tilt == \"Yellow\") {\n flow.set('yellowtilt', msg.payload.Gravity)\n}\n\nif ((flow.get('F3tiltselector') == 1) && msg.payload.Tilt == \"Red\") {\n msg.payload = (msg.payload.Gravity + flow.get('redtiltcal'))\n msg.topic = msg.payload.Tilt\n return msg;\n}\nif ((flow.get('F3tiltselector') == 2) && msg.payload.Tilt == \"Yellow\") {\n msg.payload = (msg.payload.Gravity + flow.get('yellowtiltcal'))\n msg.topic = msg.payload.Tilt\n return msg;\n}\n\n","outputs":1,"noerr":0,"x":750,"y":120,"wires":[["e92b1ea2.ae45e"]]},{"id":"cb156366.aa89f","type":"switch","z":"98499b68.3e438","name":"","property":"payload","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"}],"checkall":"true","repair":false,"outputs":4,"x":410,"y":620,"wires":[["f0f2fe6f.18de9","9efb284a.9a4a28"],["b17e38b9.4fe148","9efb284a.9a4a28"],["f0f2fe6f.18de9","fa21121b.8cce3"],["b17e38b9.4fe148","fa21121b.8cce3"]]},{"id":"2d20953.e8bfc6a","type":"blynk-ws-in-write","z":"98499b68.3e438","name":"selector","pin":"11","pin_all":0,"client":"b4285c31.47efb","x":290,"y":520,"wires":[["251c439.d8cd83c","cb156366.aa89f"]]},{"id":"e4c70a65.ef2898","type":"switch","z":"98499b68.3e438","name":"","property":"payload.Temperature","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":170,"y":420,"wires":[["9d22618c.741e18","5929f8bb.67fbe8"]]},{"id":"3a5a661e.a0d872","type":"function","z":"98499b68.3e438","name":"tiltcal","func":"\nif (flow.get('F3tiltselector') == 1) {\nflow.set('redtiltcal', msg.payload)\nmsg.payload = \n{\"Tilt\": \"Red\",\n\"Gravity\": flow.get('redtilt')\n}\n}\n\nif (flow.get('F3tiltselector') == 2) {\nflow.set('yellowtiltcal', msg.payload)\nmsg.payload = \n\n{\"Tilt\": \"Yellow\",\n\"Gravity\": flow.get('yellowtilt')\n}\n}\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":240,"wires":[["16717f4f.d41361"]]},{"id":"853b7a40.a8765","type":"blynk-ws-in-write","z":"98499b68.3e438","name":"Tiltcal","pin":"0","pin_all":0,"client":"b4285c31.47efb","x":50,"y":240,"wires":[["14940641.15ba82"]]},{"id":"5929f8bb.67fbe8","type":"split","z":"98499b68.3e438","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":290,"y":420,"wires":[["c59c7987.3740d"]]},{"id":"c59c7987.3740d","type":"switch","z":"98499b68.3e438","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Pressure","vt":"str"},{"t":"eq","v":"Temperature","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":420,"wires":[["ef73f438.da9e48"],["251c439.d8cd83c","9c59efe0.26482"]]},{"id":"2cd2111d.ff7f86","type":"blynk-ws-out-write","z":"98499b68.3e438","name":"Pressure","pin":"7","pinmode":0,"client":"b4285c31.47efb","x":740,"y":400,"wires":[]},{"id":"14940641.15ba82","type":"json","z":"98499b68.3e438","name":"","property":"payload","action":"","pretty":false,"x":250,"y":240,"wires":[["3a5a661e.a0d872"]]},{"id":"fcf136db.305998","type":"switch","z":"98499b68.3e438","name":"","property":"payload.Tilt","propertyType":"msg","rules":[{"t":"eq","v":"Red","vt":"str"},{"t":"eq","v":"Yellow","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":110,"y":60,"wires":[["e1218a6.5ac1078"],["631884da.2db6c4"]]},{"id":"c95ca6a1.029948","type":"function","z":"98499b68.3e438","name":"red tilt timeout","func":"if (msg.payload == \"Unsafe\") {\n flow.set('redtilt', 0)\n msg.payload = {\"Tilt\": \"Red\",\n \"Gravity\": flow.get('redtilt')\n}\n return msg;\n}\n","outputs":1,"noerr":0,"x":460,"y":40,"wires":[["16717f4f.d41361"]]},{"id":"b28e284a.38d6a8","type":"function","z":"98499b68.3e438","name":"yellow tilt timeout","func":"if (msg.payload == \"Unsafe\") {\n flow.set('yellowtilt', 0)\n msg.payload = {\n \"Tilt\": \"Yellow\",\n \"Gravity\": flow.get('yellowtilt')\n}\n return msg;\n}\n","outputs":1,"noerr":0,"x":470,"y":80,"wires":[["16717f4f.d41361"]]},{"id":"e1218a6.5ac1078","type":"timeout","z":"98499b68.3e438","name":"Timeout","outtopic":"","outsafe":"Safe","outwarning":"Warning","outunsafe":"Unsafe","warning":"5","timer":"300","repeat":false,"again":false,"x":260,"y":40,"wires":[["c95ca6a1.029948"]]},{"id":"631884da.2db6c4","type":"timeout","z":"98499b68.3e438","name":"Timeout","outtopic":"","outsafe":"Safe","outwarning":"Warning","outunsafe":"Unsafe","warning":"5","timer":"300","repeat":false,"again":false,"x":260,"y":80,"wires":[["b28e284a.38d6a8"]]},{"id":"ae73a195.1ba24","type":"function","z":"98499b68.3e438","name":"heat/cool","func":"if (msg.topic == \"heat\") {\n flow.set(\"heatstatus\", msg.payload)\n}\nif (msg.topic == \"cool\") {\n flow.set(\"coolstatus\", msg.payload)\n}\n\nif (msg.topic == \"thermostat\") {\nif (msg.payload.heat == \"off\" && flow.get(\"heatstatus\") !== \"off\") {\n msg.topic = \"shellies/F3/relay/1/command\"\n msg.payload = \"off\"\n node.send(msg)\n}\nif (msg.payload.heat == \"on\" && flow.get(\"heatstatus\") !== \"on\") {\n msg.topic = \"shellies/F3/relay/1/command\"\n msg.payload = \"on\"\n node.send(msg)\n}\nif (msg.payload.cool == \"off\" && flow.get(\"coolstatus\") !== \"off\") {\n msg.topic = \"shellies/F3/relay/0/command\"\n msg.payload = \"off\"\n node.send(msg)\n}\nif (msg.payload.cool == \"on\"&& flow.get(\"coolstatus\") !== \"on\") {\n msg.topic = \"shellies/F3/relay/0/command\"\n msg.payload = \"on\"\n node.send(msg)\n}\n}\n","outputs":1,"noerr":0,"x":960,"y":640,"wires":[[]]},{"id":"9cb7466d.4384e8","type":"mqtt in","z":"2beb7e94.9cf54a","name":"fridge status","topic":"shellies/F3/relay/+","qos":"2","datatype":"auto","broker":"7473ae41.ca29a","x":190,"y":80,"wires":[[]]},{"id":"3fe9ce0f.a91caa","type":"change","z":"98499b68.3e438","name":"topic","rules":[{"t":"change","p":"topic","pt":"msg","from":"shellies/F3/relay/0","fromt":"str","to":"cool","tot":"str"},{"t":"change","p":"topic","pt":"msg","from":"shellies/F3/relay/1","fromt":"str","to":"heat","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":760,"wires":[["ae73a195.1ba24"]]},{"id":"b8a02bbc.1334a8","type":"function","z":"98499b68.3e438","name":"target","func":"//msg.payload = 0\nif (global.get(\"F3tauto\") === true) {\n msg.payload = flow.get(\"target\")\n} else\n{\n msg.payload = flow.get(\"newtarget\")\n}\n\nnode.send(msg)\n","outputs":1,"noerr":0,"x":950,"y":600,"wires":[["981b4b87.ba7e9","db4b4b51.89957"]]},{"id":"981b4b87.ba7e9","type":"blynk-ws-out-write","z":"98499b68.3e438","name":"temptarget","pin":"1","pinmode":0,"client":"b4285c31.47efb","x":1410,"y":600,"wires":[]},{"id":"db4b4b51.89957","type":"change","z":"98499b68.3e438","name":"store","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)\t","tot":"jsonata"},{"t":"set","p":"newtarget","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210,"y":700,"wires":[[]]},{"id":"c52df174.e25a78","type":"blynk-ws-in-write","z":"98499b68.3e438","name":"newtemptarget","pin":"1","pin_all":0,"client":"b4285c31.47efb","x":980,"y":720,"wires":[["db4b4b51.89957"]]},{"id":"c0982d8.4e58fd","type":"mqtt in","z":"98499b68.3e438","name":"","topic":"shellies/F3/relay/+","qos":"2","datatype":"auto","broker":"7473ae41.ca29a","x":570,"y":760,"wires":[["3fe9ce0f.a91caa"]]},{"id":"1e0dfeee.c8f5e9","type":"blynk-ws-in-write","z":"98499b68.3e438","name":"temp auto","pin":"12","pin_all":0,"client":"b4285c31.47efb","x":960,"y":180,"wires":[["b615a1a.7dcf5e"]]},{"id":"b615a1a.7dcf5e","type":"change","z":"98499b68.3e438","name":"store","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"str","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"2","fromt":"str","to":"false","tot":"bool"},{"t":"set","p":"F3tauto","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":180,"wires":[[]]},{"id":"24b68052.df199","type":"blynk-ws-in-write","z":"98499b68.3e438","name":"pressure auto","pin":"13","pin_all":0,"client":"b4285c31.47efb","x":970,"y":140,"wires":[["35ba30a2.18557"]]},{"id":"35ba30a2.18557","type":"change","z":"98499b68.3e438","name":"store","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"str","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"2","fromt":"str","to":"false","tot":"bool"},{"t":"set","p":"F3pauto","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":140,"wires":[[]]},{"id":"b5e46175.9df43","type":"blynk-ws-in-write","z":"98499b68.3e438","name":"newpressuretarget","pin":"14","pin_all":0,"client":"b4285c31.47efb","x":990,"y":680,"wires":[["491d30a.67f925"]]},{"id":"491d30a.67f925","type":"change","z":"98499b68.3e438","name":"store","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)\t","tot":"jsonata"},{"t":"set","p":"newpressuresp","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210,"y":660,"wires":[[]]},{"id":"1b9a7f6b.b308d1","type":"blynk-ws-out-write","z":"98499b68.3e438","name":"pressuretarget","pin":"14","pinmode":0,"client":"b4285c31.47efb","x":1420,"y":560,"wires":[]},{"id":"f76488ea.bef49","type":"change","z":"98499b68.3e438","name":"pressuretarget","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.PressureSP","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1240,"y":560,"wires":[["491d30a.67f925","1b9a7f6b.b308d1"]]},{"id":"ef73f438.da9e48","type":"change","z":"98499b68.3e438","name":"pressure cal","rules":[{"t":"set","p":"payload","pt":"msg","to":"msg.payload - 2683","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"msg.payload / 8000","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"msg.payload * 14.5","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$round(msg.payload, 1)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":400,"wires":[["2cd2111d.ff7f86"]]},{"id":"c669a260.63b4","type":"change","z":"98499b68.3e438","name":"pressure cal","rules":[{"t":"set","p":"payload.PressureSP","pt":"msg","to":"msg.payload.PressureSP / 14.5","tot":"jsonata"},{"t":"set","p":"payload.PressureSP","pt":"msg","to":"msg.payload.PressureSP * 8000","tot":"jsonata"},{"t":"set","p":"payload.PressureSP","pt":"msg","to":"msg.payload.PressureSP + 2683","tot":"jsonata"},{"t":"set","p":"payload.PressureSP","pt":"msg","to":"$round(msg.payload.PressureSP, 1)\t","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"F3","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":520,"wires":[["ba91348a.d76ff"]]},{"id":"759ea408.f3f454","type":"blynk-ws-out-sync","z":"98499b68.3e438","name":"","pin":"0","pinmode":"1","client":"b4285c31.47efb","x":280,"y":160,"wires":[]},{"id":"a28572cc.837d58","type":"delay","z":"98499b68.3e438","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":580,"y":340,"wires":[["e6b90c3e.5371"]]},{"id":"b63232a7.2c928","type":"delay","z":"98499b68.3e438","name":"limit","pauseType":"rate","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":110,"y":380,"wires":[["91bef7d7.98a6d"]]},{"id":"27d335ad.da0b9a","type":"debug","z":"6b333ae.0c170c4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":940,"y":520,"wires":[]},{"id":"43fb2e72.a168c8","type":"debug","z":"ded897e3.d4d918","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":160,"wires":[]},{"id":"fd24b5d3.417998","type":"inject","z":"ded897e3.d4d918","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":400,"wires":[["128ca9a4.f96886","795f9442.4624b4","8bda3e40.6c6ba8"]]},{"id":"e888052e.7d67f8","type":"debug","z":"ded897e3.d4d918","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":410,"y":400,"wires":[]},{"id":"128ca9a4.f96886","type":"function","z":"ded897e3.d4d918","name":"","func":"msg.payload = [1, 2, 2, 4, 3, 4].filter((e, i, a) => a.indexOf(e) === i) // [1, 2, 3, 4]\n\nreturn msg;","outputs":1,"noerr":0,"x":250,"y":340,"wires":[["e888052e.7d67f8"]]},{"id":"a7d47b15.2958e","type":"function","z":"ded897e3.d4d918","name":"","func":"var boilhoptime=[];\nvar boilhopname=[];\nvar boilhopamount=[];\nfor( x=0;x<msg.payload.recipe.hops.length;x++){\n if (msg.payload.recipe.hops[x].use == \"Boil\") {\n boilhoptime.push(msg.payload.recipe.hops[x].time);\n boilhopname.push(msg.payload.recipe.hops[x].name);\n boilhopamount.push(msg.payload.recipe.hops[x].amount);\n }\n}\n\nconst {\n dup\n} = boilhoptime.reduce(\n (acc, curr) => {\n acc.items[curr] = acc.items[curr] ? acc.items[curr] += 1 : 1\n if (acc.items[curr] === 2) acc.dup.push(curr)\n return acc\n }, {\n items: {},\n dup: []\n }\n)\n\nfor (x= 0; x<boilhoptime.length;x++){\n boilhopname[x] = boilhopamount[x]+\"g \"+boilhopname[x]\n}\n\nif (dup.length > 0) {\nfor (var i = 0; i<dup.length; i++) {\n for (x = (boilhoptime.indexOf(dup[i])); x < boilhoptime.lastIndexOf(dup[i]); x++) {\n boilhopname[boilhoptime.indexOf(dup[i])] += \" & \"+ boilhopname[x+1] \n delete boilhopname[x+1]\n delete boilhoptime[x+1]\n }\n} \n}\n\nfor (i=0; i<boilhoptime.length; i++) {\n if (!boilhoptime[i]) {\n boilhoptime.splice(i,1);\n boilhopname.splice(i,1);\n i -= 1;\n }\n}\n\nmsg.payload = [boilhoptime, boilhopname]\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":240,"wires":[[]]},{"id":"2d5828b0.bf861","type":"debug","z":"ded897e3.d4d918","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":240,"wires":[]},{"id":"795f9442.4624b4","type":"function","z":"ded897e3.d4d918","name":"","func":"\nvar arr = [15, 25, 67, 54, 15, 67]\nconst {\n dup\n} = arr.reduce(\n (acc, curr) => {\n acc.items[curr] = acc.items[curr] ? acc.items[curr] += 1 : 1\n if (acc.items[curr] === 2) acc.dup.push(curr)\n return acc\n }, {\n items: {},\n dup: []\n }\n)\n\nmsg.payload = dup\n// ['hi', 'bye']\nreturn msg;","outputs":1,"noerr":0,"x":250,"y":460,"wires":[["de4ab9e9.0ae43"]]},{"id":"de4ab9e9.0ae43","type":"debug","z":"ded897e3.d4d918","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":410,"y":460,"wires":[]},{"id":"8bda3e40.6c6ba8","type":"function","z":"ded897e3.d4d918","name":"","func":"var arr = [34,34,56,76]\n\nconst counts = arr.reduce((acc, value) => ({\n ...acc,\n [value]: (acc[value] || 0) + 1\n}), {});\nmsg.payload = counts\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":520,"wires":[["de4ab9e9.0ae43"]]}]
Add Comment
Please, Sign In to add comment