-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwvc-inverter-monitor.flow
1 lines (1 loc) · 13.9 KB
/
wvc-inverter-monitor.flow
1
[{"id":"9d2e4344.c1c19","type":"ui_dropdown","z":"5ba2fca6.c16fbc","name":"Model","label":"","place":"Select model...","group":"7b515734.43c238","order":2,"width":"4","height":"1","passthru":true,"options":[{"label":"WVC295","value":"295","type":"str"},{"label":"WVC300","value":"300","type":"str"},{"label":"WVC350","value":"350","type":"str"},{"label":"WVC600","value":"600","type":"str"},{"label":"WVC800","value":"800","type":"str"},{"label":"WVC1200","value":"1200","type":"str"}],"payload":"","topic":"","x":130,"y":380,"wires":[["dc872d89.8c7b98"]]},{"id":"c663e6e5.c1a6b","type":"ui_button","z":"5ba2fca6.c16fbc","name":"","group":"7b515734.43c238","order":4,"width":"4","height":"1","passthru":false,"label":"Add","color":"","bgcolor":"","icon":"","payload":"add","payloadType":"str","topic":"","x":130,"y":460,"wires":[["ac7d486.869d438"]]},{"id":"beb348b.2fbe4b8","type":"ui_text","z":"5ba2fca6.c16fbc","group":"7b515734.43c238","order":1,"width":"12","height":"1","name":"","label":"Add Inverter","format":"{{msg.payload}}","layout":"row-spread","x":150,"y":340,"wires":[]},{"id":"9e4f7adc.122d6","type":"function","z":"5ba2fca6.c16fbc","name":"Get ID","func":"const str = msg.payload\nconst match = str.match(/[0-9A-Fa-f]{4}/)\nif(match && match[0] ){\n flow.set('new_id',match[0].toLowerCase())\n msg.payload = \"\"\n}else{\n msg.payload = \"Inverter ID incorrect format.\"\n}\nreturn msg","outputs":1,"noerr":0,"x":310,"y":420,"wires":[["f6b2def6.4aa2d8"]]},{"id":"dc872d89.8c7b98","type":"function","z":"5ba2fca6.c16fbc","name":"Get Model","func":"flow.set('new_model',msg.payload)\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":380,"wires":[[]]},{"id":"ac7d486.869d438","type":"function","z":"5ba2fca6.c16fbc","name":"Save","func":"const flow_id = flow.get('new_id')\nconst new_model = flow.get('new_model')\nlet message = \"Saved inverter!\"\nconst new_id = flow_id.substring(0,2) + ' ' + flow_id.substring(2,4)\nif(new_model && new_id){\n msg.topic = \"inverters\"\n msg.payload = {\n id: new_id,\n model: new_model\n }\n flow.set('new_id',null)\n flow.set('new_model',null)\n return [msg,{payload: message}]\n}else{\n message = \"\"\n if(!new_id){\n message += \" Inverter id missing.\"\n }\n if(!new_model){\n message += \" Model missing.\"\n }\n msg.payload = null\n return [msg,{payload: message}]\n}\n","outputs":2,"noerr":0,"x":310,"y":460,"wires":[["69925ae1.b64e1c","8edb0ab.0de4cf8"],["f6b2def6.4aa2d8"]]},{"id":"69925ae1.b64e1c","type":"function","z":"5ba2fca6.c16fbc","name":"Reset","func":"if(msg.payload){\n msg.payload = \"\"\n return msg;\n}","outputs":1,"noerr":0,"x":130,"y":540,"wires":[["21a12621.af09fa","f6b2def6.4aa2d8"]]},{"id":"21a12621.af09fa","type":"ui_text_input","z":"5ba2fca6.c16fbc","name":"","label":"Inverter ID","group":"7b515734.43c238","order":3,"width":"4","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":150,"y":420,"wires":[["9e4f7adc.122d6"]]},{"id":"8edb0ab.0de4cf8","type":"bigmongo in","z":"5ba2fca6.c16fbc","service":"_ext_","configNode":"e7706f11.1fe1c","name":"Save to db","collection":"inverters","operation":"insertOne","x":530,"y":460,"wires":[["9cc567bd.d69c28","7a62552.8d7022c"],[]]},{"id":"f6b2def6.4aa2d8","type":"ui_text","z":"5ba2fca6.c16fbc","group":"7b515734.43c238","order":0,"width":"12","height":"1","name":"Status","label":"","format":"{{msg.payload}}","layout":"row-spread","x":510,"y":540,"wires":[]},{"id":"df55cf69.5276f","type":"bigmongo in","z":"5ba2fca6.c16fbc","service":"_ext_","configNode":"e7706f11.1fe1c","name":"Find inverters","collection":"inverters","operation":"find.toArray","x":340,"y":220,"wires":[["e3dff42.49a4e88","118c496b.88a29f"],["ce5c50e7.1426a8"]]},{"id":"f0909ef8.7084","type":"inject","z":"5ba2fca6.c16fbc","name":"","topic":"","payload":"{}","payloadType":"json","repeat":"60","crontab":"","once":true,"onceDelay":"60","x":150,"y":120,"wires":[["f5f7c43c.88101"]]},{"id":"e3dff42.49a4e88","type":"function","z":"5ba2fca6.c16fbc","name":"Set global","func":"const arr = msg.payload\nconst associated = {}\nconst existingInverters = global.get('inverters') || {}\n//Clean up duplicates\nfor( let n in arr ){\n const el = arr[n]\n associated[el.id] = el\n}\n\nconst cleanedArr = Object.getOwnPropertyNames(associated).map( n => associated[n] )\n//Copy over data from the existing global inverters\nfor( let n in cleanedArr){\n const inv = cleanedArr[n]\n associated[inv.id] = Object.assign(associated[inv.id],existingInverters[inv.id])\n}\nglobal.set('inverters',associated)\n\nif(cleanedArr.length !== arr.length){\n msg.payload = \"...\"\n return msg\n}\n\n//If we have a list with no duplicates\n\n\nmsg.payload = arr\nreturn msg\n\n","outputs":1,"noerr":0,"x":140,"y":280,"wires":[["a9ab3784.601b58"]]},{"id":"f79cc8be.e817f","type":"bigmongo in","z":"5ba2fca6.c16fbc","service":"_ext_","configNode":"e7706f11.1fe1c","name":"Save array","collection":"inverters","operation":"insertMany","x":990,"y":280,"wires":[["3b8c16f1.ccfafa","7a62552.8d7022c"],[]]},{"id":"15cee605.7e28c2","type":"bigmongo in","z":"5ba2fca6.c16fbc","service":"_ext_","configNode":"e7706f11.1fe1c","name":"Drop collection","collection":"inverters","operation":"drop","x":600,"y":280,"wires":[["4e92722b.75806c"],[]]},{"id":"4e92722b.75806c","type":"function","z":"5ba2fca6.c16fbc","name":"Inject inverters","func":"const inverters = global.get('inverters')\n//Embed in an array, otherwise the inverter array will be split up in arguments for the insert function.\nmsg.payload = [inverters]\nreturn msg;","outputs":1,"noerr":0,"x":800,"y":280,"wires":[["f79cc8be.e817f"]]},{"id":"3b8c16f1.ccfafa","type":"debug","z":"5ba2fca6.c16fbc","name":"Array Saved","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1190,"y":280,"wires":[]},{"id":"9cc567bd.d69c28","type":"debug","z":"5ba2fca6.c16fbc","name":"Save","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":790,"y":540,"wires":[]},{"id":"a9ab3784.601b58","type":"switch","z":"5ba2fca6.c16fbc","name":"DB Reload Check","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"string","vt":"string"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":280,"wires":[["15cee605.7e28c2"],["ef4c1851.eeaf2"]]},{"id":"ef4c1851.eeaf2","type":"ui_template","z":"5ba2fca6.c16fbc","group":"7b515734.43c238","name":"Inverter List","order":0,"width":0,"height":0,"format":"<div class=\"inverter-list\">\n<div layout=\"row\" layout-align=\"start center\">\n <span flex>ID</span>\n <span flex>Model</span>\n <span flex>Lim</span>\n <span flex>Pwr</span>\n <span flex>DC Voltage</span>\n <span flex>AC Voltage</span>\n <span flex>Temp</span>\n <span flex> </span>\n</div>\n<div layout=\"row\" layout-align=\"start center\" ng-repeat=\"inverter in msg.payload\">\n <span flex style=\"color: {{inverter.active==='1' ? 'green' : 'red'}}\">{{inverter.id}}{{inverter.fake ? 'Fake' : '' }}</span>\n <span flex style=\"color: #111111\">{{inverter.model}}</span>\n <span flex style=\"color: #111111\">{{inverter.powerGrade===100 ? '' : (inverter.powerGrade/100*inverter.model).toPrecision(3)+'W'}}</span>\n <span flex style=\"color: #111111\">{{inverter.active==='1' ? inverter.dcPower.toPrecision(3) : '--' }}W</span>\n <span flex style=\"color: #111111\">{{inverter.active==='1' ? inverter.dcVoltage.toPrecision(3) : '--' }}V</span>\n <span flex style=\"color: #111111\">{{inverter.active==='1' ? inverter.acVoltage.toPrecision(3) : '--' }}V</span>\n <span flex style=\"color: #111111\">{{inverter.active==='1' ? inverter.temperature : '--' }}°C</span>\n <span flex>\n <md-button class=\"vibrate filled touched bigfont rounded\" style=\"background-color:rgba(192, 0, 0, 0.61); font-weight: bolder;\" ng-click=\"send({payload: {_id : inverter._id}})\">\n\n\n X\n\n </md-button>\n </span>\n</div>\n</div>","storeOutMessages":true,"fwdInMessages":false,"templateScope":"local","x":590,"y":340,"wires":[["ec94b039.2bb56"]]},{"id":"7a62552.8d7022c","type":"function","z":"5ba2fca6.c16fbc","name":"Inject {}","func":"\nmsg.payload = {}\nreturn msg;","outputs":1,"noerr":0,"x":1240,"y":460,"wires":[["df55cf69.5276f"]]},{"id":"41353380.e8df74","type":"function","z":"5ba2fca6.c16fbc","name":"Make query","func":"if(!Array.isArray(msg.payload)){\n msg.payload = {'_id': msg.payload._id }\n return msg;\n}","outputs":1,"noerr":0,"x":930,"y":340,"wires":[["6edd9121.c7aa08"]]},{"id":"6edd9121.c7aa08","type":"bigmongo in","z":"5ba2fca6.c16fbc","service":"_ext_","configNode":"e7706f11.1fe1c","name":"Delete object","collection":"inverters","operation":"deleteOne","x":1110,"y":340,"wires":[["7a62552.8d7022c"],[]]},{"id":"ec94b039.2bb56","type":"objectid","z":"5ba2fca6.c16fbc","name":"Make id","selectedProperty":"_id","x":780,"y":340,"wires":[["41353380.e8df74"]]},{"id":"9e8e01df.8738f8","type":"mqtt in","z":"5ba2fca6.c16fbc","name":"Inverter MQTT","topic":"modems/+/inverters/#","qos":"2","broker":"3256e0e9.783578","x":150,"y":660,"wires":[["d49b823a.61f3"]]},{"id":"d49b823a.61f3","type":"function","z":"5ba2fca6.c16fbc","name":"Parse MQTT","func":"const topicParts = msg.topic.split(\"/\")\nconst spacedHex = (unspaced) => unspaced.split(/(?=(?:..)*$)/).join(' ')\n\n\nif(topicParts.length===5){\n const [modemsTopic,modemId,invertersTopic,inverterId,value] = topicParts\n const spacedInverterId = spacedHex(inverterId)\n const inverter = global.get(\"inverters\")[spacedInverterId]\n \n if(inverter){\n \n if(value!=='active'){\n inverter.lastUpdate = Date.now()\n inverter[value] = Math.round(parseFloat(msg.payload)*10)/10\n }\n else\n inverter[value] = msg.payload\n \n msg.payload = global.get(\"inverters\")\n return msg\n }\n \n}\n\n","outputs":1,"noerr":0,"x":360,"y":660,"wires":[["ef4c1851.eeaf2"]]},{"id":"d291e121.9603","type":"ui_template","z":"5ba2fca6.c16fbc","group":"f01a36c8.66f9b","name":"Header","order":0,"width":0,"height":0,"format":"<style>\n\n body.nr-dashboard-theme{\n background-image: linear-gradient(to bottom right, #FDFDFF, #C3D0D8);\n }\n \n .nr-dashboard-cardcontainer>.visible{\n overflow: visible;\n }\n \n .md-toolbar-tools{\n background-image: url('/img/logo.png');\n background-size: auto 175%;\n background-repeat: no-repeat;\n background-position: right -25px;\n margin-left: -7px;\n height: 100px;\n }\n \n .md-toolbar-tools h1{\n color: #1f2954;\n }\n \n ng-md-icon{\n color: #1f2954;\n }\n \n .nr-dashboard-theme ui-card-panel{\n background-color: rgba(0, 0, 0, 0);\n box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);\n }\n \n body.nr-dashboard-theme md-content md-card{\n background-color: rgba(197, 197, 212, 0.15);\n }\n \n #WVC_Inverter_Control_Micro_Inverters .nr-dashboard-template {\n height: auto!important;\n }\n \n #Energy_Summary_Energy_Summary_cards:nt-child(1){\n z-index: 1;\n }\n</style>\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"global","x":140,"y":80,"wires":[[]]},{"id":"118c496b.88a29f","type":"debug","z":"5ba2fca6.c16fbc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":180,"wires":[]},{"id":"ce5c50e7.1426a8","type":"debug","z":"5ba2fca6.c16fbc","name":"2nd output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":550,"y":220,"wires":[]},{"id":"f5f7c43c.88101","type":"function","z":"5ba2fca6.c16fbc","name":"Check If Inverters Initialized","func":"const inverters = global.get('inverters')\nif(inverters && typeof inverters === 'object' && Object.keys(inverters).length > 0){\n msg.payload = null //Do not initialize\n}else{\n msg.payload = {}\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":360,"y":120,"wires":[["30fc1c42.305004"]]},{"id":"30fc1c42.305004","type":"switch","z":"5ba2fca6.c16fbc","name":"Check if need to initialize","property":"payload","propertyType":"msg","rules":[{"t":"nnull"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":190,"y":180,"wires":[["df55cf69.5276f"],[]],"outputLabels":["Initialize","Do NOT Initialize"]},{"id":"1c25e3b9.e651cc","type":"comment","z":"5ba2fca6.c16fbc","name":"Test","info":"","x":130,"y":780,"wires":[]},{"id":"1044781a.dd1e3","type":"inject","z":"5ba2fca6.c16fbc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":840,"wires":[["d254248a.ffc92"]]},{"id":"d254248a.ffc92","type":"function","z":"5ba2fca6.c16fbc","name":"Get Inverters","func":"msg.payload = global.get('inverters')\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":840,"wires":[["b3ddc59b.9cc378"]]},{"id":"b3ddc59b.9cc378","type":"debug","z":"5ba2fca6.c16fbc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":840,"wires":[]},{"id":"7b515734.43c238","type":"ui_group","z":"","name":"Micro Inverters","tab":"b4280182.3801e","disp":true,"width":"12","collapse":false},{"id":"e7706f11.1fe1c","type":"bigmongo","z":"","uri":"mongodb://localhost:27017/solar","name":"solar","options":"","parallelism":"-1","warncodes":"","ignoredcodes":""},{"id":"3256e0e9.783578","type":"mqtt-broker","z":"","name":"local_mqtt","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""},{"id":"f01a36c8.66f9b","type":"ui_group","z":"","name":"Solar Power Plant Status","tab":"4419e762.4f55a","order":1,"disp":true,"width":"12","collapse":false},{"id":"b4280182.3801e","type":"ui_tab","z":"","name":"WVC Inverter Control","icon":"dashboard","order":4},{"id":"4419e762.4f55a","type":"ui_tab","z":"","name":"Power Flow","icon":"dashboard","order":3}]