Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [{"id":"6b333ae.0c170c4","type":"tab","label":"BC","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":"46921707.070ee","type":"tab","label":"Flow 2","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":"5fec9a11.37a164","type":"ui_base","theme":{"name":"theme-custom","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":false,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#097479","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"customTheme":{"name":"","default":"#4B7930","baseColor":"#666666","baseFont":"Tahoma,Geneva,sans-serif","reset":false},"themeState":{"base-color":{"default":"#4B7930","value":"#4B7930","edited":false},"page-titlebar-backgroundColor":{"value":"#666666","edited":false},"page-backgroundColor":{"value":"#111111","edited":false},"page-sidebar-backgroundColor":{"value":"#000000","edited":false},"group-textColor":{"value":"#8c8c8c","edited":false},"group-borderColor":{"value":"#555555","edited":false},"group-backgroundColor":{"value":"#333333","edited":false},"widget-textColor":{"value":"#eeeeee","edited":false},"widget-backgroundColor":{"value":"#666666","edited":false},"widget-borderColor":{"value":"#333333","edited":false},"base-font":{"value":"Tahoma,Geneva,sans-serif"}},"angularTheme":{"primary":"indigo","accents":"blue","warn":"red","background":"grey"}},"site":{"name":"Room","hideToolbar":"false","allowSwipe":"false","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":53,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":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":"366500a5.06556","type":"ui_group","z":"","name":"ShellyHT","tab":"","order":1,"disp":true,"width":"12","collapse":false},{"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":"abd2b4b9.930e68","type":"ui_tab","name":"Tab 1","icon":"dashboard","order":1},{"id":"4592b0d4.7d6eb","type":"ui_group","name":"Group 1","tab":"abd2b4b9.930e68","order":1,"disp":true,"width":6},{"id":"1f03b438.03ab7c","type":"ui_group","z":"","name":"PID","tab":"78c2012b.197418","disp":true,"width":"6"},{"id":"78c2012b.197418","type":"ui_tab","z":"","name":"Home","icon":"dashboard"},{"id":"c17bace6.f7f03","type":"mqtt-broker","z":"46921707.070ee","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"2d0af3e2.b3137c","type":"mqtt-broker","z":"46921707.070ee","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"4a30623d.a91234","type":"http in","z":"ded897e3.d4d918","name":"","url":"/brewfather","method":"post","upload":false,"swaggerDoc":"","x":80,"y":20,"wires":[["5aac28ef.ff36c","aef5e427.e454a8","a1f12a48.2e92f8"]]},{"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\n\nfunction time_convert(num)\n { \n var hours = Math.floor(num / 60); \n var minutes = num % 60;\n return + hours + \":\" + minutes + \":00\"; \n}\n\nvar hopstand\nvar hopstandtemp\nif (msg.payload.recipe.hopStandMinutes > 0) {\n hopstand = true\n hopstandtemp = msg.payload.recipe.avgWeightedHopstandTemp\n}\nelse {\n hopstandtemp = 0\n hopstand = false\n}\n\n\nvar firstwort\nif (msg.payload.recipe.hops[0].use == \"First Wort\") {\n firstwort = true\n} \nelse {\n firstwort = false\n}\n\n\nvar hoptime=[];\nfor(var x=0;x<msg.payload.recipe.hops.length;x++){\n if (msg.payload.recipe.hops[x].use == \"Boil\") {\n hoptime[x]= msg.payload.recipe.hops[x].time;\n }\n}\nhoptime.push(0,0,0,0,0,0,0,0,0,0);\nhoptime.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(hoptime[0]) } ,\n{ \"Name\": \"Hop time1\" , \"Value\": time_convert(hoptime[1]) } ,\n{ \"Name\": \"Hop time2\" , \"Value\": time_convert(hoptime[2]) } ,\n{ \"Name\": \"Hop time3\" , \"Value\": time_convert(hoptime[3]) } ,\n{ \"Name\": \"Hop time4\" , \"Value\": time_convert(hoptime[4]) } ,\n{ \"Name\": \"Hop time5\" , \"Value\": time_convert(hoptime[5]) } ,\n{ \"Name\": \"Hop time6\" , \"Value\": time_convert(hoptime[7]) } ,\n{ \"Name\": \"Hop time8\" , \"Value\": time_convert(hoptime[8]) } ,\n{ \"Name\": \"Hop time9\" , \"Value\": time_convert(hoptime[9]) } ,\n{ \"Name\": \"Hopstand time\" , \"Value\": time_convert(msg.payload.recipe.hopStandMinutes) } ,\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\": \"Recipe received\" , \"Value\": msg.payload._timestamp } ,\n{ \"Name\": \"Status\" , \"Value\": msg.payload.recipe.name }\n\n];\n\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":40,"wires":[["5b8a970c.1845a8","a1f12a48.2e92f8"]]},{"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":"","proxy":"","authType":"basic","x":450,"y":40,"wires":[["a1f12a48.2e92f8"]]},{"id":"335b502.4ee8e3","type":"http in","z":"ded897e3.d4d918","name":"","url":"/Fermenter","method":"get","upload":false,"swaggerDoc":"","x":80,"y":60,"wires":[["2c61da97.912afe","b7c769b3.45c3d8"]]},{"id":"aef5e427.e454a8","type":"http response","z":"ded897e3.d4d918","name":"","statusCode":"200","headers":{},"x":460,"y":80,"wires":[]},{"id":"2c61da97.912afe","type":"function","z":"ded897e3.d4d918","name":"Fermenter","func":"msg.payload = [flow.get('recipe'),flow.get('fbeername')]\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":80,"wires":[["aef5e427.e454a8"]]},{"id":"fdaf8bdc.203198","type":"split","z":"ded897e3.d4d918","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":350,"y":140,"wires":[["18670c0.05e6df4"]]},{"id":"de329c07.e6fff","type":"inject","z":"ded897e3.d4d918","name":"Fusion config","topic":"fusion-configuration","payload":"{\"outputTopic\":\"F1\",\"inputTopics\":[\"beer\",\"name\",\"temp\",\"ext_temp\",\"aux_temp\",\"temp_unit\",\"pressure\",\"pressure_unit\",\"gravity\",\"tilttemperature\",\"comment\"],\"allowUndefined\":true,\"onlyPayloads\":true}","payloadType":"json","repeat":"","crontab":"","once":true,"onceDelay":"2","x":100,"y":180,"wires":[["18670c0.05e6df4"]]},{"id":"18670c0.05e6df4","type":"fusion","z":"ded897e3.d4d918","name":"","x":530,"y":140,"wires":[["1ec71569.eaad0b"]]},{"id":"1ec71569.eaad0b","type":"delay","z":"ded897e3.d4d918","name":"limit","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"8","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":670,"y":140,"wires":[["aa7e714a.60a358"]]},{"id":"7bf9bb98.296e84","type":"debug","z":"ded897e3.d4d918","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":340,"wires":[]},{"id":"a1f12a48.2e92f8","type":"debug","z":"ded897e3.d4d918","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":650,"y":20,"wires":[]},{"id":"b7c769b3.45c3d8","type":"debug","z":"ded897e3.d4d918","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":60,"wires":[]},{"id":"56f7f002.6e376","type":"split","z":"ded897e3.d4d918","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":350,"y":220,"wires":[["2635f65c.cc3fb2"]]},{"id":"807cef9b.8ca018","type":"inject","z":"ded897e3.d4d918","name":"Fusion config","topic":"fusion-configuration","payload":"{\"outputTopic\":\"F2\",\"inputTopics\":[\"beer\",\"name\",\"temp\",\"ext_temp\",\"aux_temp\",\"temp_unit\",\"pressure\",\"pressure_unit\",\"gravity\",\"tilttemperature\",\"comment\"],\"allowUndefined\":true,\"onlyPayloads\":true}","payloadType":"json","repeat":"","crontab":"","once":true,"onceDelay":"2","x":100,"y":260,"wires":[["2635f65c.cc3fb2"]]},{"id":"2635f65c.cc3fb2","type":"fusion","z":"ded897e3.d4d918","name":"","x":530,"y":220,"wires":[["354ab4ad.7420e4"]]},{"id":"354ab4ad.7420e4","type":"delay","z":"ded897e3.d4d918","name":"limit","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"8","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":670,"y":220,"wires":[["aa7e714a.60a358"]]},{"id":"aa7e714a.60a358","type":"http request","z":"ded897e3.d4d918","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"http://log.brewfather.net/stream?id=MJCu9dsSiGKwJr","tls":"","proxy":"","authType":"basic","x":990,"y":300,"wires":[["7bf9bb98.296e84"]]},{"id":"dee0a605.bba82","type":"http in","z":"ded897e3.d4d918","name":"","url":"/tiltbridge","method":"post","upload":false,"swaggerDoc":"","x":80,"y":720,"wires":[["17b9e549.1fabd3","c0b5406b.47576"]]},{"id":"17b9e549.1fabd3","type":"http response","z":"ded897e3.d4d918","name":"","statusCode":"","headers":{},"x":270,"y":680,"wires":[]},{"id":"c0b5406b.47576","type":"switch","z":"ded897e3.d4d918","name":"Color","property":"payload.tilts","propertyType":"msg","rules":[{"t":"regex","v":"Yellow","vt":"str","case":true},{"t":"regex","v":"Red","vt":"str","case":true}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":720,"wires":[["7ee41115.caff1","7bf9bb98.296e84"],["f44192e1.e9b59"]]},{"id":"7ee41115.caff1","type":"change","z":"ded897e3.d4d918","name":"Yellow","rules":[{"t":"delete","p":"payload.mdns_id","pt":"msg"},{"t":"set","p":"payload.tilts.Yellow.gravity","pt":"msg","to":"$number(payload.tilts.Yellow.gravity)","tot":"jsonata"},{"t":"set","p":"payload.tilts.Yellow.gravity","pt":"msg","to":"msg.payload.tilts.Yellow.gravity - 0.000","tot":"jsonata"},{"t":"set","p":"payload.tilts.Yellow.temp","pt":"msg","to":"(payload.tilts.Yellow.temp -32) * (5/9)","tot":"jsonata"},{"t":"move","p":"payload.tilts.Yellow.temp","pt":"msg","to":"payload.tilttemperature","tot":"msg"},{"t":"move","p":"payload.tilts.Yellow.gravity","pt":"msg","to":"payload.gravity","tot":"msg"},{"t":"set","p":"payload.comment","pt":"msg","to":"$now()","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":680,"wires":[["968b3705.4ed078","7bf9bb98.296e84"]]},{"id":"f44192e1.e9b59","type":"change","z":"ded897e3.d4d918","name":"Red","rules":[{"t":"set","p":"payload.tilts.Red.gravity","pt":"msg","to":"$number(payload.tilts.Red.gravity)","tot":"jsonata"},{"t":"set","p":"payload.tilts.Red.gravity","pt":"msg","to":"msg.payload.tilts.Red.gravity - 0.000","tot":"jsonata"},{"t":"set","p":"payload.tilts.Red.temp","pt":"msg","to":"(payload.tilts.Red.temp -32) * (5/9)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":720,"wires":[["6ab5a6ae.5b7468"]]},{"id":"968b3705.4ed078","type":"split","z":"ded897e3.d4d918","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":670,"y":680,"wires":[["2635f65c.cc3fb2"]]},{"id":"6ab5a6ae.5b7468","type":"split","z":"ded897e3.d4d918","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":670,"y":720,"wires":[[]]},{"id":"bbeade50.2d3a5","type":"change","z":"ded897e3.d4d918","name":"psi","rules":[{"t":"set","p":"payload.pressure","pt":"msg","to":"payload.pressure *14.5","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":220,"wires":[["56f7f002.6e376"]]},{"id":"7ab9d3c0.d0ce84","type":"mqtt in","z":"ded897e3.d4d918","name":"","topic":"F1","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":50,"y":140,"wires":[["fbb0d4c0.4babf8"]]},{"id":"981f917c.bef748","type":"mqtt in","z":"ded897e3.d4d918","name":"","topic":"F2","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":50,"y":220,"wires":[["bbeade50.2d3a5"]]},{"id":"fbb0d4c0.4babf8","type":"change","z":"ded897e3.d4d918","name":"psi","rules":[{"t":"set","p":"payload.pressure","pt":"msg","to":"payload.pressure *14.5","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":140,"wires":[["fdaf8bdc.203198"]]},{"id":"b7504ef7.4656a","type":"mqtt in","z":"ded897e3.d4d918","name":"","topic":"F4","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":50,"y":380,"wires":[["f6424999.5e6248"]]},{"id":"f6424999.5e6248","type":"change","z":"ded897e3.d4d918","name":"psi","rules":[{"t":"set","p":"payload.pressure","pt":"msg","to":"payload.pressure *14.5","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":380,"wires":[["1805ceba.356881"]]},{"id":"1805ceba.356881","type":"split","z":"ded897e3.d4d918","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":350,"y":380,"wires":[["857c5a5e.3ccff"]]},{"id":"857c5a5e.3ccff","type":"fusion","z":"ded897e3.d4d918","name":"","x":530,"y":380,"wires":[["a9df38c7.5828c"]]},{"id":"a9df38c7.5828c","type":"delay","z":"ded897e3.d4d918","name":"limit","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"8","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":670,"y":380,"wires":[["aa7e714a.60a358"]]},{"id":"d3e090a8.8c4cc","type":"inject","z":"ded897e3.d4d918","name":"Fusion config","topic":"fusion-configuration","payload":"{\"outputTopic\":\"F4\",\"inputTopics\":[\"beer\",\"name\",\"temp\",\"ext_temp\",\"aux_temp\",\"temp_unit\",\"pressure\",\"pressure_unit\",\"gravity\",\"tilttemperature\",\"comment\"],\"allowUndefined\":true,\"onlyPayloads\":true}","payloadType":"json","repeat":"","crontab":"","once":true,"onceDelay":"2","x":80,"y":420,"wires":[["857c5a5e.3ccff"]]},{"id":"c33c3961.bca8c8","type":"mqtt in","z":"ded897e3.d4d918","name":"","topic":"F3","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":50,"y":300,"wires":[["5aa2bbf2.b4c4bc"]]},{"id":"5aa2bbf2.b4c4bc","type":"change","z":"ded897e3.d4d918","name":"psi","rules":[{"t":"set","p":"payload.pressure","pt":"msg","to":"payload.pressure *14.5","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":300,"wires":[["a7421b50.239ed"]]},{"id":"a7421b50.239ed","type":"split","z":"ded897e3.d4d918","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":350,"y":300,"wires":[["c2701ec6.357a9"]]},{"id":"c2701ec6.357a9","type":"fusion","z":"ded897e3.d4d918","name":"","x":530,"y":300,"wires":[["79b10a40.79bc2c"]]},{"id":"79b10a40.79bc2c","type":"delay","z":"ded897e3.d4d918","name":"limit","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"8","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":670,"y":300,"wires":[["7bf9bb98.296e84","aa7e714a.60a358"]]},{"id":"592bfc52.81cf2c","type":"inject","z":"ded897e3.d4d918","name":"Fusion config","topic":"fusion-configuration","payload":"{\"outputTopic\":\"F3\",\"inputTopics\":[\"beer\",\"name\",\"temp\",\"ext_temp\",\"aux_temp\",\"temp_unit\",\"pressure\",\"pressure_unit\",\"gravity\",\"tilttemperature\",\"comment\"],\"allowUndefined\":true,\"onlyPayloads\":true}","payloadType":"json","repeat":"","crontab":"","once":true,"onceDelay":"2","x":80,"y":340,"wires":[["c2701ec6.357a9"]]},{"id":"2cefefc1.df4e28","type":"mqtt in","z":"ded897e3.d4d918","name":"RFbridge","topic":"tele/RFbridge/RESULT","qos":"2","datatype":"json","broker":"7473ae41.ca29a","x":70,"y":520,"wires":[["ac2a4959.01d14"]]},{"id":"ac2a4959.01d14","type":"debug","z":"ded897e3.d4d918","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":300,"y":520,"wires":[]},{"id":"8c66f4f0.2910d","type":"http request","z":"ded897e3.d4d918","name":"Red tilt","method":"GET","ret":"obj","paytoqs":false,"url":"http://192.168.77.246:8000/global/Redtilt","tls":"","proxy":"","authType":"basic","x":260,"y":820,"wires":[["8cd04dca.db4ab"]]},{"id":"a13da565.e835c8","type":"inject","z":"ded897e3.d4d918","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":780,"wires":[["8c66f4f0.2910d"]]},{"id":"8cd04dca.db4ab","type":"debug","z":"ded897e3.d4d918","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":820,"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 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 u.push (inp[i]+\",\"+\"99\")\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 < 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 }\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\n u = u.join('')\n s = s.join('')\n out = s+u+\";\"\n node.send([null, {payload: out}])\n}\n\n\n\n","outputs":2,"noerr":0,"x":90,"y":660,"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])+\"hys\", 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)+\"outtime\", u[i][9])\n flow.set(String(pin)+\"outtime\", u[i][9])\n msg.payload = flow.get(String(u[i][2]))\n msg.topic = u[i][2]\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 === 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 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 msg.payload = out\n msg.topic = dcpins[i]\n node.send(msg)\n }\n}\n}\n\n\n\n","outputs":1,"noerr":0,"x":230,"y":640,"wires":[["42a373e3.140344","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":720,"wires":[["361a3004.4b084"]]},{"id":"e6c5affa.506c2","type":"tcp out","z":"6b333ae.0c170c4","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"","x":230,"y":680,"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":730,"y":560,"wires":[["6e5abb4e.85551c"],[],[],[],[],[],[],[],[],[],["9400f82a.44cae"],[],[],["92064297.1ce1a8"],[],["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":1620,"y":60,"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":650,"y":260,"wires":[["61fe7ba9.54589c"]]},{"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":"freezer","vt":"str","case":false},{"t":"regex","v":"Fridge1","vt":"str","case":false},{"t":"regex","v":"cooler","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":3,"x":210,"y":280,"wires":[["d9ce9fc7.d6b4b"],["d46086dd.fb5d5"],["660cb740.453d78","507b515b.be0858"]]},{"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":300,"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":220,"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":260,"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":1230,"y":600,"wires":[]},{"id":"3c7347ac.ddd05","type":"mqtt out","z":"6b333ae.0c170c4","name":"Freezer ctrl","topic":"cmnd/freezer/POWER","qos":"","retain":"","broker":"7473ae41.ca29a","x":1230,"y":540,"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":1060,"y":600,"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":1230,"y":660,"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":1060,"y":640,"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":1060,"y":680,"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":930,"y":600,"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":930,"y":640,"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":930,"y":680,"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"]]},{"id":"5be974f6.69899c","type":"function","z":"46921707.070ee","name":"Timeprop","func":"// A node that can be used to generate a time proportioned on/off signal\n// from a power requirement value in the range 0 to 1\n// So for example with a cycle time period (set below) of 10 minutes and\n// a power requirement of 0.2 the output will be on for 2 minutes in every\n// ten minutes.\n// In addition to passing in messages with the payload set to the current\n// power requirement (floating point 0.0 to 1.0), provide an input from a \n// repeating inject node with the topic set to 'tick' and the payload \n// containing the current timestamp. The frequency of this will depend upon \n// the cycle time required. For a cycle time period of 10 minutes I use an inject\n// repeat of 5 seconds.\n\n// Set these three variables as required\nvar period = 0.1*60*1000; // On/off cycle time period millisecs, 10 minutes\nvar deadTime = 15*1000; // number of milliseconds the valve (or whatever) takes to actuate, 30 seconds\nvar invert = false; // set true for active low output, so the output will go low\n // when the valve should actuate, this is the usual case on a\n // pi feeding a relay to drive the actuator\n\n// is this a tick message?\nif (msg.topic !== \"tick\") {\n // no, so it should be a power value, save it and exit\n var power = msg.payload;\n context.set('topic', msg.topic);\n context.set('power', msg.payload);\n msg = null;\n} else {\n // yes, payload is timestamp, calc current wave value between 0 and 1\n var wave = (msg.payload % period)/period; // 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 = context.get('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/period;\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 = context.get('opState') || 0;\n } \n }\n context.set('opState', opState);\n msg.topic = context.get('topic')\n msg.payload = invert ? (1-opState) : opState;\n}\nreturn msg;","outputs":1,"noerr":0,"x":495.5,"y":219,"wires":[["2fd2fc9.7c96804"]]},{"id":"f8af8e6a.c9f6d","type":"inject","z":"46921707.070ee","name":"1 sec","topic":"tick","payload":"","payloadType":"date","repeat":"1","crontab":"","once":true,"x":350,"y":120,"wires":[["5be974f6.69899c"]]},{"id":"2fd2fc9.7c96804","type":"debug","z":"46921707.070ee","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":700,"y":180,"wires":[]},{"id":"cb5ebc23.16f248","type":"inject","z":"46921707.070ee","name":"","topic":"45","payload":"0.5","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":220,"wires":[["5be974f6.69899c"]]},{"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":80,"y":620,"wires":[["4219943.881ec6c"]]},{"id":"92064297.1ce1a8","type":"debug","z":"6b333ae.0c170c4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":970,"y":520,"wires":[]},{"id":"61fe7ba9.54589c","type":"link out","z":"6b333ae.0c170c4","name":"","links":["4b91c95.9c9ddb8"],"x":715,"y":160,"wires":[]},{"id":"4b91c95.9c9ddb8","type":"link in","z":"6b333ae.0c170c4","name":"","links":["61fe7ba9.54589c"],"x":155,"y":720,"wires":[["9977ef80.f4948"]]},{"id":"507b515b.be0858","type":"change","z":"6b333ae.0c170c4","name":"100","rules":[{"t":"set","p":"payload","pt":"msg","to":"$floor(msg.payload.DS18B20.Temperature*100)","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"100","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":340,"wires":[["aa94857f.8bc8b8","61fe7ba9.54589c"]]},{"id":"42a373e3.140344","type":"debug","z":"6b333ae.0c170c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":390,"y":680,"wires":[]},{"id":"6e5abb4e.85551c","type":"debug","z":"6b333ae.0c170c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":870,"y":460,"wires":[]},{"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"]]},{"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)+\"hys\") || 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 out = true\n }\n if (value >= setpoint2) {\n out = false\n }\n if (cooling === true) {\n out = !out\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\nif (flow.get(String(pin)+\"config\") === 6) { //PID\n outpin = flow.get(String(pin)+\"pin\") || 0\n 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 (config === 99 || flow.get(String(pin)) === -12700) {\n msg.topic = pin\n msg.enable = 0\n msg.disabled_op = 0\n node.send(msg)\n }\n \n else {\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":230,"y":720,"wires":[["ac850891.101d28","42a373e3.140344"]]},{"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":1140,"y":880,"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":1310,"y":880,"wires":[["c4f7fb34.7cf768"]]},{"id":"c4f7fb34.7cf768","type":"influxdb out","z":"6b333ae.0c170c4","influxdb":"2778b469.9fa82c","name":"influxDB","measurement":"","precision":"","retentionPolicy":"","x":1480,"y":880,"wires":[]},{"id":"86cb0eeb.f5f9d","type":"link in","z":"6b333ae.0c170c4","name":"","links":["d24fef0c.576368"],"x":1055,"y":880,"wires":[["534bc321.36c5d4"]]},{"id":"ac850891.101d28","type":"link out","z":"6b333ae.0c170c4","name":"input","links":["49cd19c5.18d9b8","90f16f36.e83e78"],"x":315,"y":720,"wires":[]},{"id":"485dc52c.20a7fc","type":"link out","z":"6b333ae.0c170c4","name":"config","links":["49cd19c5.18d9b8"],"x":315,"y":640,"wires":[]},{"id":"49cd19c5.18d9b8","type":"link in","z":"6b333ae.0c170c4","name":"outputs","links":["485dc52c.20a7fc","ac850891.101d28","58d6778.cbf3088"],"x":655,"y":560,"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":[]}]
Add Comment
Please, Sign In to add comment