-
Notifications
You must be signed in to change notification settings - Fork 4
/
raspberry-interface.flow
1 lines (1 loc) · 8.21 KB
/
raspberry-interface.flow
1
[{"id":"c57c6663.a9d81","type":"mqtt in","z":"1a2e60e0.a3ea37","name":"","topic":"solar_power","qos":"2","broker":"3256e0e9.783578","x":170,"y":280,"wires":[["d16a9ab.bd9cd68","c9bbf4cf.8eecb8"]]},{"id":"4cbf21b4.8e65c","type":"function","z":"1a2e60e0.a3ea37","name":"Convert for Screen","func":"\nmsg.payload = {size:2,x:1,y:1,text: \"Solar (W):\"}\n\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":320,"wires":[["cfa6640a.2bfe2"]]},{"id":"bcd8568a.15811","type":"function","z":"1a2e60e0.a3ea37","name":"Display W","func":"const val = Math.floor(msg.payload)\nconst watts = isNaN(val) ? 0 : val\nlet wattsString = \"\"\n\nif( watts < -10 ){\n wattsString = \" \" + watts + \" \"\n}else if( watts < 0 ){\n wattsString = \" \" + watts + \" \"\n}else if( watts < 10 ){\n wattsString = \" \" + watts + \" \"\n}else if(watts < 100 ){\n wattsString = \" \" + watts + \" \"\n}else if(watts < 1000 ){\n wattsString = \" \" + watts + \" \"\n}else{\n wattsString = \" \" + watts + \" \"\n}\n\nmsg.payload = {size:3,x:1,y:30,text: wattsString}\nreturn msg;","outputs":1,"noerr":0,"x":760,"y":360,"wires":[["b7c03b4d.b7eb88"]]},{"id":"141bee41.76576a","type":"rpi-gpio in","z":"1a2e60e0.a3ea37","name":"Button","pin":"40","intype":"up","debounce":"25","read":false,"x":410,"y":700,"wires":[["44c5ff4.7bbcf"]]},{"id":"78bdc5a6.895f54","type":"function","z":"1a2e60e0.a3ea37","name":"Convert for Screen","func":"\nmsg.payload = {size:2,x:1,y:1,text: \"Today (Wh):\"}\n\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":400,"wires":[["d7a0efce.7acb18"]]},{"id":"7ce49a5c.7eea3c","type":"debug","z":"1a2e60e0.a3ea37","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":960,"y":700,"wires":[]},{"id":"c7e95c13.261388","type":"inject","z":"1a2e60e0.a3ea37","name":"At startup","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":420,"y":100,"wires":[["9df61e88.6b6648","4cbf21b4.8e65c","78bdc5a6.895f54"]]},{"id":"9df61e88.6b6648","type":"function","z":"1a2e60e0.a3ea37","name":"Init screen state","func":"const screen_no = 0\nconst screen_count = 2\nflow.set('screen_no',screen_no)\nflow.set('screen_count',screen_count)\nmsg.payload = {\n 'screen_no': screen_no,\n 'screen_count': screen_count\n}\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":100,"wires":[["aac71f.8277b0e"]]},{"id":"d16a9ab.bd9cd68","type":"switch","z":"1a2e60e0.a3ea37","name":"Get Screen No","property":"screen_no","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":400,"y":280,"wires":[["4cbf21b4.8e65c","bcd8568a.15811"],["20264582.02d62a"]]},{"id":"44c5ff4.7bbcf","type":"function","z":"1a2e60e0.a3ea37","name":"Set screen no","func":"\nif(msg.payload === 0){\n const screen_no = flow.get(\"screen_no\") || 0\n const screen_count = flow.get(\"screen_count\") || 1\n\n if( screen_no < screen_count-1){\n flow.set(\"screen_no\",screen_no+1)\n }else{\n flow.set(\"screen_no\",0)\n }\n \n}\n\nmsg.payload = {\n 'screen_no': flow.get('screen_no'),\n 'screen_count': flow.get('screen_count')\n}\n\nreturn msg;\n\n\n\n","outputs":1,"noerr":0,"x":680,"y":700,"wires":[["7ce49a5c.7eea3c","e673da4.4e63c28","2b293438.f7eab4","9f8ed8f9.fb19d8"]]},{"id":"7cab2015.5a01e","type":"inject","z":"1a2e60e0.a3ea37","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":450,"y":860,"wires":[["385c2fb4.7fe22"]]},{"id":"385c2fb4.7fe22","type":"function","z":"1a2e60e0.a3ea37","name":"get screen no","func":"msg.payload = flow.get(\"screen_no\")\nreturn msg;","outputs":1,"noerr":0,"x":670,"y":860,"wires":[["b7c27261.b220b8"]]},{"id":"b7c27261.b220b8","type":"debug","z":"1a2e60e0.a3ea37","name":"Screen No","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":860,"y":860,"wires":[]},{"id":"c9bbf4cf.8eecb8","type":"debug","z":"1a2e60e0.a3ea37","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":780,"y":240,"wires":[]},{"id":"86a5987b.f8df9","type":"function","z":"1a2e60e0.a3ea37","name":"Display Wh","func":"const watts = Math.floor(msg.payload*1000)\nlet wattsString = \"\"\n\n\nif( watts < -10 ){\n wattsString = \" \" + watts + \" \"\n}else if( watts < 0 ){\n wattsString = \" \" + watts + \" \"\n}else if( watts < 10 ){\n wattsString = \" \" + watts + \" \"\n}else if(watts < 100 ){\n wattsString = \" \" + watts + \" \"\n}else if(watts < 1000 ){\n wattsString = \" \" + watts + \" \"\n}else{\n wattsString = \" \" + watts + \" \"\n}\n\nmsg.payload = {size:3,x:1,y:30,text: wattsString}\nreturn msg;","outputs":1,"noerr":0,"x":770,"y":440,"wires":[["64cc6b6a.ead3dc"]]},{"id":"c90d2bc6.e9b46","type":"mqtt in","z":"1a2e60e0.a3ea37","name":"","topic":"solar/energy","qos":"2","broker":"3256e0e9.783578","x":170,"y":380,"wires":[["ae16f7e3.d3d41","522ba5e2.efc914"]]},{"id":"ae16f7e3.d3d41","type":"switch","z":"1a2e60e0.a3ea37","name":"Get Screen No","property":"screen_no","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":380,"y":380,"wires":[["86a5987b.f8df9","78bdc5a6.895f54"],["1006ffa7.16bb38"]]},{"id":"aac71f.8277b0e","type":"persist in","z":"1a2e60e0.a3ea37","name":"screen_state","storageNode":"713680c7.a7fe8","x":850,"y":100,"wires":[]},{"id":"e673da4.4e63c28","type":"persist in","z":"1a2e60e0.a3ea37","name":"screen_state","storageNode":"713680c7.a7fe8","x":970,"y":760,"wires":[]},{"id":"9e0b3fdb.3e5ce8","type":"persist out","z":"1a2e60e0.a3ea37","name":"screen_state","storageNode":"713680c7.a7fe8","x":430,"y":160,"wires":[["ba806664.8eb888"]]},{"id":"ba806664.8eb888","type":"function","z":"1a2e60e0.a3ea37","name":"Restore screen state","func":"const screen_no = msg.payload.screen_no || 0\nconst screen_count = msg.payload.screen_count || 2\n\nflow.set('screen_no',screen_no)\nflow.set('screen_count',screen_count)\n\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":160,"wires":[["4cbf21b4.8e65c","78bdc5a6.895f54"]]},{"id":"2b293438.f7eab4","type":"function","z":"1a2e60e0.a3ea37","name":"Get energy","func":"msg.payload = flow.get('solar/energy') || 0\nreturn msg;","outputs":1,"noerr":0,"x":170,"y":440,"wires":[["ae16f7e3.d3d41"]]},{"id":"9f8ed8f9.fb19d8","type":"function","z":"1a2e60e0.a3ea37","name":"Zero power","func":"msg.payload = 0\nreturn msg;","outputs":1,"noerr":0,"x":170,"y":340,"wires":[["d16a9ab.bd9cd68"]]},{"id":"522ba5e2.efc914","type":"function","z":"1a2e60e0.a3ea37","name":"Save","func":"flow.set(\"solar/energy\",msg.payload)\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":440,"wires":[[]]},{"id":"b7c03b4d.b7eb88","type":"String","z":"1a2e60e0.a3ea37","name":"Watts","display":"2d826bc5.9ceb1c","x":990,"y":360,"wires":[]},{"id":"cfa6640a.2bfe2","type":"String","z":"1a2e60e0.a3ea37","name":"Solar Power","display":"2d826bc5.9ceb1c","x":1010,"y":320,"wires":[]},{"id":"d7a0efce.7acb18","type":"String","z":"1a2e60e0.a3ea37","name":"Today kWh","display":"ec9303e4.6a20b","x":1010,"y":400,"wires":[]},{"id":"64cc6b6a.ead3dc","type":"String","z":"1a2e60e0.a3ea37","name":"Wh","display":"ec9303e4.6a20b","x":990,"y":440,"wires":[]},{"id":"20264582.02d62a","type":"Clear","z":"1a2e60e0.a3ea37","name":"Clear Screen","display":"2d826bc5.9ceb1c","x":770,"y":500,"wires":[]},{"id":"1006ffa7.16bb38","type":"Clear","z":"1a2e60e0.a3ea37","name":"Clear Screen","display":"ec9303e4.6a20b","x":770,"y":540,"wires":[]},{"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":"713680c7.a7fe8","type":"persist-store","z":"","filename":"/etc/nodered-persist.json","interval":"60"},{"id":"2d826bc5.9ceb1c","type":"oled-config","z":"1a2e60e0.a3ea37","name":"Screen 1","width":"128","height":"64","address":"3c"},{"id":"ec9303e4.6a20b","type":"oled-config","z":"1a2e60e0.a3ea37","name":"Screen2","width":"128","height":"64","address":"3d"}]