Snippets

Peter Scargill Nod-Red Stat attempt 1

Created by Peter Scargill
[{"id":"8be635ca.03e038","type":"ui_template","z":"c552e8d2.712b48","group":"37f2a2e2.88cc6e","name":"css etc","order":7,"width":"0","height":"0","format":"<style>\n  .filled { \n      height: 100% !important;\n\n      padding: 0 !important;\n      margin: 0 !important;\n  }\n  .nr-dashboard-template {\n      padding: 0;\n      margin: 0;\n  }\n  \n  .rounded {\n  border-radius: 12px 12px 12px 12px;\n}\n \n   .bigfont {\n  font-size: 18px;\n}\n\n   .smallfont {\n  font-size: 12px;\n}\n  \n</style>\n\n<script>\nvar current=1;\n\n$('.vibrate').on('click', function() {\n  navigator.vibrate(100);\n});\n\nfunction restore_bg(x) {\n            $(this).css(\"background-color\", x);\n    };\n\n$('.touched').on('mousedown', function() {\n    \n    var x= $(this).css(\"background-color\");\n    $(this).css(\"background-color\", \"yellow\");\n    \n    setTimeout(restore_bg.bind(this,x),50);\n    navigator.vibrate(80);\n    });\n    \n</script>","storeOutMessages":true,"fwdInMessages":true,"x":280,"y":80,"wires":[[]]},{"id":"8815a1ed.fca9b","type":"ui_template","z":"c552e8d2.712b48","group":"37f2a2e2.88cc6e","name":"Settings page","order":1,"width":"6","height":"7","format":"<script>\nvar thedays=[\"SUNDAY\",\"MONDAY\",\"TUESDAY\",\"WEDNESDAY\",\"THURSDAY\",\"FRIDAY\",\"SATURDAY\"];\n\nvar last=1;\n\nfunction bar(mm,val)\n{\nif (val==1) { $(mm).height(\"25%\"); $(mm).css('background-color', 'blue'); }\nif (val==2) { $(mm).height(\"50%\"); $(mm).css('background-color', 'green'); }\nif (val==3) { $(mm).height(\"75%\"); $(mm).css('background-color', 'orange'); }\nif (val==4) { $(mm).height(\"100%\"); $(mm).css('background-color','red'); }\n}\n\nfunction selec(val,sta)\n{\nvar w=\"#td\"+val;\n if (sta) $(w).css('background-color','magenta'); else $(w).css('background-color','black');\n}\n\n    (function(scope){\n        scope.$watch('msg', function(msg) {\n            selec(last,0); last=msg.selector; selec(last,1);\n            for (var x=0; x<24; x++) { var w=\"#t\"+x; bar(w,msg.timing[((msg.days-1)*24)+x]+1); } \n            for (var x=0; x<4; x++) { var w=\"#s\"+x; $(w).text(msg.timing[168+x]); }\n             $(\"#d0\").text(thedays[msg.days-1]);\n        });\n \n    })(scope);\n      \n\n</script>\n<table width=\"100%\">\n    \n    <tr>\n        <td colspan=3><center><span style=\"color:black;font-size:80%\">Stdby</span></center></td>\n        <td colspan=3><center><span style=\"color:black;font-size:80%\">Off-Peak</span></center></td>\n        <td colspan=3><center><span style=\"color:black;font-size:80%\">Normal</span></center></td>\n        <td colspan=3><center><span style=\"color:black;font-size:80%\">Extra</span></center></td>\n    </tr>\n   \n    <tr>\n        <td ng-click=\"send({payload: '1'})\" colspan=3><center><span id=\"s0\" style=\"color:blue;font-size:150%\">14</span></center></td>\n        <td ng-click=\"send({payload: '2'})\" colspan=3><center><span id=\"s1\" style=\"color:green;font-size:150%\">20</span></center></td>\n        <td ng-click=\"send({payload: '3'})\" colspan=3><center><span id=\"s2\" style=\"color:orange;font-size:150%\">23</span></center></td>\n        <td ng-click=\"send({payload: '4'})\" colspan=3><center><span id=\"s3\" style=\"color:red;font-size:150%\">25</span></center></td>\n    </tr>\n    <tr style=\"height:2px\">\n        <td id=\"td1\" colspan=3 style=\"background-color:black;height:2px;width:24%\"></td>\n        <td id=\"td2\" colspan=3 style=\"background-color:black;height:2px;width:24%\"></td>\n        <td id=\"td3\" colspan=3 style=\"background-color:black;height:2px;width:24%\"></td>\n        <td id=\"td4\" colspan=3 style=\"background-color:black;height:2px;width:24%\"></td>\n    </tr>      \n    \n    <tr>\n        <td ng-click=\"send({payload: '5'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t0\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '6'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t1\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '7'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t2\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '8'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t3\" ng-click=\"send({payload: '8'})\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '9'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t4\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '10'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t5\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '11'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t6\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '12'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t7\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '13'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t8\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '14'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t9\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '15'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t10\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '16'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t11\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n\n    </tr>    \n    <tr style=\"height:2px\">\n        <td id=\"td5\" style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td6\" style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td7\" style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td8\" style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td9\" style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td10\" style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td11\" style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td12\" style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td13\" style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td14\" style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td15\" style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td16\" style=\"background-color:black;height:2px;width:8%\"></td>\n    </tr>    \n        <tr>\n        <td>0</td>\n        <td>1</td>\n        <td>2</td>\n        <td>3</td>\n        <td>4</td>\n        <td>5</td>\n        <td>6</td>\n        <td>7</td>\n        <td>8</td>\n        <td>9</td>\n        <td>10</td>\n        <td>11</td>\n    </tr> \n      <tr>\n        <td ng-click=\"send({payload: '17'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t12\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '18'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t13\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '19'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t14\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '20'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t15\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '21'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t16\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '22'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t17\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '23'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t18\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '24'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t19\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '25'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t20\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '26'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t21\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '27'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t22\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n        <td ng-click=\"send({payload: '28'})\" style=\"vertical-align:bottom;height:30px; width:8%\"><div id=\"t23\" style=\"width:100%;height:0%;color:blue; background-color:green\"></div></td>\n    </tr>    \n    <tr style=\"height:2px\">\n        <td id=\"td17\"  style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td18\"  style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td19\"  style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td20\"  style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td21\"  style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td22\"  style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td23\"  style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td24\"  style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td25\"  style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td26\"  style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td27\"  style=\"background-color:black;height:2px;width:8%\"></td>\n        <td id=\"td28\"  style=\"background-color:black;height:2px;width:8%\"></td>\n\n    </tr>    \n        <tr>\n        <td>12</td>\n        <td>13</td>\n        <td>14</td>\n        <td>15</td>\n        <td>16</td>\n        <td>17</td>\n        <td>18</td>\n        <td>19</td>\n        <td>20</td>\n        <td>21</td>\n        <td>22</td>\n        <td>23</td>\n    </tr> \n    \n    <tr>\n        <td ng-click=\"send({payload: '29'})\" colspan=12><center><span id=\"d0\" style=\"color:black;font-size:200%\">MONDAY</span></center></td>\n    </tr>\n\n    <tr><td  id=\"td29\" colspan=12 style=\"background-color:black;height:2px;width:100%\"></td></tr>\n\n    <tr><td  colspan=12 style=\"height:10px;width:100%\"></td></tr>\n\n    <tr style=\"height:48px\">\n        <td colspan=2>\n            <md-button  class=\"vibrate filled touched smallfont rounded\" style=\"background-color:#dddddd; width:48px\" ng-click=\"send({payload: 'd'})\"> \n                <img style=\"outline : none;\" \n                             ng-src=\"{{(msg.payload)?'/myicons/png/48x48/actions/arrow-left-double-2.png':'/myicons/png/48x48/actions/arrow-left-double-2.png'}}\" \n                              height=\"36px\"\n                />\n            </md-button> \n        </td>\n\n        <td colspan=2>\n            <md-button  class=\"vibrate filled touched smallfont rounded\" style=\"background-color:#dddddd; width:48px\" ng-click=\"send({payload: 'u'})\"> \n                <img style=\"outline : none;\" \n                             ng-src=\"{{(msg.payload)?'/myicons/png/48x48/actions/arrow-right-double-2.png':'/myicons/png/48x48/actions/arrow-right-double-2.png'}}\" \n                              height=\"36px\"\n                />\n            </md-button> \n        </td>\n\n        <td colspan=2>\n            <md-button  class=\"vibrate filled touched smallfont rounded\" style=\"background-color:#dddddd; width:48px\" ng-click=\"send({payload: 'r'})\"> \n                <img style=\"outline : none;\" \n                             ng-src=\"{{(msg.payload)?'/myicons/png/48x48/actions/edit-copy-4.png':'/myicons/png/48x48/actions/edit-copy-4.png'}}\" \n                              height=\"36px\"\n                />\n            </md-button> \n        </td>\n\n        <td colspan=2>\n        </td>\n\n        <td colspan=2>\n            <md-button  class=\"vibrate filled touched smallfont rounded\" style=\"background-color:#dddddd; width:48px\" ng-click=\"send({payload: 's'})\"> \n                <img style=\"outline : none;\" \n                             ng-src=\"{{(msg.payload)?'/myicons/png/48x48/actions/document-save-5.png':'/myicons/png/48x48/actions/document-save-5.png'}}\" \n                              height=\"36px\"\n                />\n            </md-button> \n        </td>\n\n        <td colspan=2>\n            <md-button  class=\"vibrate filled touched smallfont rounded\" style=\"background-color:#dddddd; width:48px\" ng-click=\"send({payload: 'c'})\"> \n                <img style=\"outline : none;\" \n                             ng-src=\"{{(msg.payload)?'/myicons/png/48x48/actions/dialog-cancel-5.png':'/myicons/png/48x48/actions/dialog-cancel-5.png'}}\" \n                              height=\"36px\"\n                />\n            </md-button> \n        </td>\n\n        <td colspan=1></td>\n    </tr>\n</table>","storeOutMessages":false,"fwdInMessages":false,"x":500,"y":80,"wires":[["aba7c9ce.0b6c28"]]},{"id":"aba7c9ce.0b6c28","type":"function","z":"c552e8d2.712b48","name":"Process controls","func":"if ( typeof context.days == 'undefined' ) context.days=1;\nif ( typeof context.selector == 'undefined' ) context.selector=1;\nif ( typeof context.saving == 'undefined' ) context.saving=0;\n\nif ( typeof context.global.timing == 'undefined' ) \n    {\n        context.global.timing=[\n                        14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,\n                        14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,\n                        14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,\n                        14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,\n                        14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,\n                        14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,\n                        14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,\n                        14,20,23,26\n                        ];\n        context.saving=0;                    \n    }\nvar timing=global.get(\"timing\");\n\nswitch (msg.payload)\n    {\n    case \"u\" :  if ((context.selector>4)&&(context.selector<29))\n                {\n                    timing[((context.days-1)*24)+context.selector-5]++; timing[((context.days-1)*24)+context.selector-5]&=3; \n                }\n                if (context.selector<5) { if (timing[168+(context.selector-1)]<26) timing[168+(context.selector-1)]++; }\n                if (context.selector==29) { if (context.days<7)context.days++; }\n                break;\n    case \"d\" :  if ((context.selector>4)&&(context.selector<29))\n                {\n                    timing[((context.days-1)*24)+context.selector-5]--; timing[((context.days-1)*24)+context.selector-5]&=3; \n                }\n                if (context.selector<5) { if (timing[168+(context.selector-1)]>12) timing[168+(context.selector-1)]--; }\n                if (context.selector==29) { if (context.days>1)context.days--; }\n                break;\n    case 'r' :  if ((context.selector>=5)&&(context.selector<28))\n                        {\n                         timing[((context.days-1)*24)+context.selector-4]=timing[((context.days-1)*24)+context.selector-5];   \n                         context.selector++;\n                        }\n                if ((context.selector==29)&&(context.days<7))\n                        {\n                         for (var a=0;a<24;a++)\n                            {\n                             timing[((context.days)*24)+a]=timing[((context.days-1)*24)+a];   \n                            }\n                         context.days++;\n                        }\n                break;\n    case 's': context.saving=0; break;\n    case '1':\n    case '2':\n    case '3':\n    case '4':\n    case '5':\n    case '6':\n    case '7':\n    case '8':\n    case '9':\n    case '10':\n    case '11':\n    case '12':\n    case '13':\n    case '14':\n    case '15':\n    case '16':\n    case '17':\n    case '18':\n    case '19':\n    case '20':\n    case '21':\n    case '22':\n    case '23':\n    case '24':\n    case '25':\n    case '26':\n    case '27':\n    case '28':\n    case '29': context.selector=parseInt(msg.payload); break;\n    case 'c' : msg.payload=\"anything\";  node.send([null,null,msg]); return;\n    }\n\nmsg.temperatures=context.temperatures;\nmsg.timing=timing;\nmsg.days=context.days;\nmsg.selector=context.selector;\n\nnode.send([msg,null,null]);\n\nif (context.saving===0) \n    { \n       msg.topic=\"\";\n        msg.timing=\"\";\n        msg.payload=JSON.stringify(timing);\n        node.send([null,msg,null]); \n        context.saving=1;\n    }","outputs":"3","noerr":0,"x":510,"y":160,"wires":[["8815a1ed.fca9b"],["9f13095d.38ba18"],["8421f1bf.f6286"]]},{"id":"945f3b38.6cc9c8","type":"inject","z":"c552e8d2.712b48","name":"Once only","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"x":280,"y":160,"wires":[["aba7c9ce.0b6c28","8421f1bf.f6286"]]},{"id":"85124520.008c78","type":"debug","z":"c552e8d2.712b48","name":"","active":true,"console":"false","complete":"true","x":710,"y":240,"wires":[]},{"id":"13c303be.55f94c","type":"inject","z":"c552e8d2.712b48","name":"Every minute","topic":"","payload":"","payloadType":"str","repeat":"60","crontab":"","once":false,"x":300,"y":240,"wires":[["7f0331f4.5b289"]]},{"id":"7f0331f4.5b289","type":"function","z":"c552e8d2.712b48","name":"Process heat","func":"var timing=global.get(\"timing\");\nvar now = new Date();\nvar h = now.getHours();\nvar day = now.getDay();\nvar t;\nt=timing[168+timing[(day*24)+h]];\nmsg.payload=t;\nnode.status({fill:\"blue\",shape:\"dot\",text:\"Set point \" + t + \"c\"});\nreturn msg;\n\n","outputs":1,"noerr":0,"x":490,"y":240,"wires":[["85124520.008c78"]]},{"id":"9f13095d.38ba18","type":"file","z":"c552e8d2.712b48","name":"backup","filename":"/home/pi/petesstatlog.log","appendNewline":true,"createDir":true,"overwriteFile":"true","x":720,"y":160,"wires":[]},{"id":"8421f1bf.f6286","type":"file in","z":"c552e8d2.712b48","name":"Restore","filename":"/home/pi/petesstatlog.log","format":"utf8","x":320,"y":320,"wires":[["5efea5f0.dec25c"]]},{"id":"5efea5f0.dec25c","type":"function","z":"c552e8d2.712b48","name":"Restore data from SD","func":"var timing=global.get(\"timing\");\ntiming=JSON.parse(msg.payload);\nmsg.payload=\"\";\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":320,"wires":[["aba7c9ce.0b6c28"]]},{"id":"37f2a2e2.88cc6e","type":"ui_group","z":"","name":"Stat","tab":"c675fdae.9cea1","disp":false,"width":"6"},{"id":"c675fdae.9cea1","type":"ui_tab","z":"","name":"Stat","icon":"dashboard"}]

Comments (0)