Skip to content

Instantly share code, notes, and snippets.

@smadds
Last active March 17, 2018 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smadds/0d9f1038185796899ccc836d272f3e3d to your computer and use it in GitHub Desktop.
Save smadds/0d9f1038185796899ccc836d272f3e3d to your computer and use it in GitHub Desktop.
Weekly Timer
[
{
"id": "26556dc.dad5892",
"type": "ui_template",
"z": "ea4a330a.bb7e6",
"group": "151be4a4.2a40bb",
"name": "css etc",
"order": 2,
"width": "0",
"height": "0",
"format": "<style>\n\n.filled { height: 48px !important;padding: 0 !important; margin: 0 !important;}\n.nr-dashboard-template { padding: 0; margin: 0;}\n.rounded { border-radius: 12px 12px 12px 12px;}\n.bigfont { font-size: 18px;}\n.smallfont { font-size: 12px;}\n.thedays { cursor:pointer; vertical-align:bottom; height:48px; }\n.the2px { background-color: #9E9E9E; height:2px; }\n.theblocks {width:100%; height:0%; background-color:#4CAF50; }\n.greybuttons { background-color:#009688 !important; width:48px; border: none;}\n.thetemps { cursor:pointer; font-size:70%; color:#9E9E9E !important; }\n.smallheadings { color:gray; font-size:80%; }\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": false,
"fwdInMessages": true,
"templateScope": "local",
"x": 400,
"y": 140,
"wires": [
[]
]
},
{
"id": "9e4471f8.504c9",
"type": "ui_template",
"z": "ea4a330a.bb7e6",
"group": "151be4a4.2a40bb",
"name": "Settings page",
"order": 1,
"width": "6",
"height": "6",
"format": "<script>\nvar thedays=[\"SUNDAY\",\"MONDAY\",\"TUESDAY\",\"WEDNESDAY\",\"THURSDAY\",\"FRIDAY\",\"SATURDAY\"];\nvar ID = \"AA\";\n\nvar last=29;\n\nfunction bar(mm,val)\n{\nif (val==14) { $(mm).height(\"12%\"); $(mm).css('background-color', '#1E88E5'); } //blue\nif (val==15) { $(mm).height(\"16%\"); $(mm).css('background-color', '#039BE5'); }\nif (val==16) { $(mm).height(\"20%\"); $(mm).css('background-color', '#00ACC1'); } \nif (val==17) { $(mm).height(\"24%\"); $(mm).css('background-color', '#039BE5'); } // cyan\nif (val==18) { $(mm).height(\"28%\"); $(mm).css('background-color', '#00ACC1'); }\nif (val==19) { $(mm).height(\"32%\"); $(mm).css('background-color', '#00897B'); } \nif (val==20) { $(mm).height(\"36%\"); $(mm).css('background-color', '#388E3C'); } // green\nif (val==21) { $(mm).height(\"40%\"); $(mm).css('background-color', '#689F38'); }\nif (val==22) { $(mm).height(\"44%\"); $(mm).css('background-color', '#C0CA33'); }\nif (val==23) { $(mm).height(\"48%\"); $(mm).css('background-color', '#FDD835'); } // yellow\nif (val==24) { $(mm).height(\"52%\"); $(mm).css('background-color', '#FBC02D'); }\nif (val==25) { $(mm).height(\"56%\"); $(mm).css('background-color', '#FFA000'); }\nif (val==26) { $(mm).height(\"60%\"); $(mm).css('background-color','#E64A19'); } // red\n \n}\n\nfunction stat(text)\n{\n$(\"#info\"+ID).text(text);\nvar tm=setTimeout(function(){ $(\"#info\"+ID).text(\"Ok\"); clearTimeout(tm);}, 3000);\n}\n\nfunction selec(val,sta)\n{\nvar w=\"#td\"+val+ID;\n if (sta) $(w).css('background-color','#4CAF50'); else $(w).css('background-color','#FFC107');\n}\n\n (function(scope){\n scope.ID = ID;\n scope.send({payload: '29'})\n scope.$watch('msg', function(msg) {\n selec(last,0); last=msg.selector; selec(last,1);\n for (var x=0; x<24; x++) \n { \n var w=\"#t\"+x+ID; bar(w,msg.timing[((msg.days-1)*24)+x]); \n var v=\"#v\"+x+ID; $(v).text(msg.timing[((msg.days-1)*24)+x]+\"°\")\n } \n for (var x=0; x<2; x++) { var w=\"#s\"+x+ID; $(w).text(msg.timing[168+x]); }\n $(\"#d0\"+ID).text(thedays[msg.days-1]);\n if ((last>4) &&(last<29))\n $(\"#current\"+ID).text(msg.timing[((msg.days-1)*24)+last-5] + \"°\");\n else\n $(\"#current\"+ID).text(\"-\");\n \n if (msg.foryou!=\"\") { stat(msg.foryou); }\n \n \n });\n \n })(scope);\n \n\n</script>\n<table width=\"100%\">\n \n <tr>\n <td colspan=24><center><span class=\"smallheadings\" >Day</span></center></td>\n <!--<td colspan=3><center><span class=\"smallheadings\">Clima</span></center></td>\n <td colspan=3><center><span class=\"smallheadings\">Fuori casa</span></center></td>-->\n </tr>\n \n <tr>\n <td ng-click=\"send({payload: '29'})\" colspan=24><center><span id=\"{{ 'd0' + ID }}\" style=\"cursor:pointer;font-size:120%\">MONDAY</span></center></td>\n <!--<td ng-click=\"send({payload: '1'})\" colspan=3><center><span id=\"s0\" style=\"font-size:120%\">14</span></center></td>\n <td ng-click=\"send({payload: '2'})\" colspan=3><center><span id=\"s1\" style=\"font-size:120%\">20</span></center></td>-->\n </tr>\n \n <tr style=\"height:2px\">\n <td id=\"{{ 'td29' + ID }}\" colspan=24 style=\"background-color:#9E9E9E;height:2px;\"></td> \n <!-- <td id=\"td1\" colspan=3 style=\"background-color:#9E9E9E;height:2px;\"></td>\n <td id=\"td2\" colspan=3 style=\"background-color:#9E9E9E;height:2px;\"></td>-->\n </tr> \n\n <tr>\n <td ng-click=\"send({payload: '5'})\" class=\"thedays\"><span id=\"{{ 'v0' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't0' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '6'})\" class=\"thedays\"><span id=\"{{ 'v1' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't1' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '7'})\" class=\"thedays\"><span id=\"{{ 'v2' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't2' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '8'})\" class=\"thedays\"><span id=\"{{ 'v3' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't3' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '9'})\" class=\"thedays\"><span id=\"{{ 'v4' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't4' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '10'})\" class=\"thedays\"><span id=\"{{ 'v5' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't5' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '11'})\" class=\"thedays\"><span id=\"{{ 'v6' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't6' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '12'})\" class=\"thedays\"><span id=\"{{ 'v7' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't7' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '13'})\" class=\"thedays\"><span id=\"{{ 'v8' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't8' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '14'})\" class=\"thedays\"><span id=\"{{ 'v9' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't9' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '15'})\" class=\"thedays\"><span id=\"{{ 'v10' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't10' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '16'})\" class=\"thedays\"><span id=\"{{ 'v11' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't11' + ID }}\" class=\"theblocks\"></div></td>\n </tr> \n \n <tr style=\"height:2px\">\n <td id=\"{{ 'td5' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td6' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td7' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td8' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td9' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td10' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td11' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td12' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td13' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td14' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td15' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td16' + ID }}\" class=\"the2px\"></td>\n </tr> \n \n <tr>\n <td align=\"center\">0</td>\n <td align=\"center\">1</td>\n <td align=\"center\">2</td>\n <td align=\"center\">3</td>\n <td align=\"center\">4</td>\n <td align=\"center\">5</td>\n <td align=\"center\">6</td>\n <td align=\"center\">7</td>\n <td align=\"center\">8</td>\n <td align=\"center\">9</td>\n <td align=\"center\">10</td>\n <td align=\"center\">11</td>\n </tr> \n \n <tr>\n <td ng-click=\"send({payload: '17'})\" class=\"thedays\"><span id=\"{{ 'v12' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't12' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '18'})\" class=\"thedays\"><span id=\"{{ 'v13' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't13' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '19'})\" class=\"thedays\"><span id=\"{{ 'v14' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't14' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '20'})\" class=\"thedays\"><span id=\"{{ 'v15' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't15' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '21'})\" class=\"thedays\"><span id=\"{{ 'v16' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't16' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '22'})\" class=\"thedays\"><span id=\"{{ 'v17' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't17' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '23'})\" class=\"thedays\"><span id=\"{{ 'v18' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't18' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '24'})\" class=\"thedays\"><span id=\"{{ 'v19' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't19' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '25'})\" class=\"thedays\"><span id=\"{{ 'v20' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't20' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '26'})\" class=\"thedays\"><span id=\"{{ 'v21' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't21' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '27'})\" class=\"thedays\"><span id=\"{{ 'v22' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't22' + ID }}\" class=\"theblocks\"></div></td>\n <td ng-click=\"send({payload: '28'})\" class=\"thedays\"><span id=\"{{ 'v23' + ID }}\" class=\"thetemps\"></span><div id=\"{{ 't23' + ID }}\" class=\"theblocks\"></div></td>\n </tr> \n \n <tr style=\"height:2px\">\n <td id=\"{{ 'td17' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td18' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td19' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td20' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td21' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td22' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td23' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td24' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td25' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td26' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td27' + ID }}\" class=\"the2px\"></td>\n <td id=\"{{ 'td28' + ID }}\" class=\"the2px\"></td>\n </tr> \n \n <tr>\n <td align=\"center\">12</td>\n <td align=\"center\">13</td>\n <td align=\"center\">14</td>\n <td align=\"center\">15</td>\n <td align=\"center\">16</td>\n <td align=\"center\">17</td>\n <td align=\"center\">18</td>\n <td align=\"center\">19</td>\n <td align=\"center\">20</td>\n <td align=\"center\">21</td>\n <td align=\"center\">22</td>\n <td align=\"center\">23</td>\n </tr> \n \n <tr height=\"20px\">\n <td colspan=2 class=\"smallheadings\">Action:</td>\n\n <td colspan=10 ><center><span id=\"{{ 'info' + ID }}\" class=\"smallheadings\" ></span></center></td>\n\n </tr>\n \n <tr height=\"10px\">\n <td colspan=\"12\"></td>\n </tr>\n\n <tr style=\"height:48px\">\n <td colspan=2>\n <button class=\"vibrate filled touched smallfont rounded greybuttons\" ng-click=\"send({payload: 'd'})\"> \n <ng-md-icon style=\"color: #fff;\" icon=\"keyboard_arrow_down\">\n <md-tooltip md-direction=\"bottom\">Decrease</md-tooltip>\n </ng-md-icon>\n </button> \n </td>\n \n <td colspan=2><center><span id=\"{{ 'current' + ID }}\" style=\"font-size:120%\">-</span></center></td>\n\n <td colspan=2>\n <button class=\"vibrate filled touched smallfont rounded greybuttons\" ng-click=\"send({payload: 'u'})\"> \n <ng-md-icon style=\"color: #fff;\" icon=\"keyboard_arrow_up\">\n <md-tooltip md-direction=\"bottom\">Increase</md-tooltip>\n </ng-md-icon>\n </button> \n </td>\n\n <td colspan=2>\n <button class=\"vibrate filled touched smallfont rounded greybuttons\" ng-click=\"send({payload: 'r'})\"> \n <ng-md-icon style=\"color: #fff;\" icon=\"content_copy\">\n <md-tooltip md-direction=\"bottom\">Copy</md-tooltip>\n </ng-md-icon>\n </button> \n </td>\n\n\n <td colspan=2>\n <button class=\"vibrate filled touched smallfont rounded greybuttons\" ng-click=\"send({payload: 's'})\"> \n <ng-md-icon style=\"color: #fff;\" icon=\"save\">\n <md-tooltip md-direction=\"bottom\">Save</md-tooltip>\n </ng-md-icon>\n </button> \n </td>\n\n <td colspan=2>\n <button class=\"vibrate filled touched smallfont rounded greybuttons\" ng-click=\"send({payload: 'c'})\"> \n <ng-md-icon style=\"color: #fff;\" icon=\"cancel\">\n <md-tooltip md-direction=\"bottom\">Cancel</md-tooltip>\n </ng-md-icon>\n </button> \n </td>\n <td colspan=1></td>\n </tr>\n\n</table>",
"storeOutMessages": false,
"fwdInMessages": false,
"templateScope": "local",
"x": 680,
"y": 140,
"wires": [
[
"685115e8.a7daec"
]
]
},
{
"id": "685115e8.a7daec",
"type": "function",
"z": "ea4a330a.bb7e6",
"name": "Process controls",
"func": "if ( typeof context.days == 'undefined' ) context.days=1;\nif ( typeof context.selector == 'undefined' ) context.selector=29;\nif ( typeof context.saving == 'undefined' ) context.saving=1;\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 6,14\n ];\n context.saving=1; \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]++; \n if (timing[((context.days-1)*24)+context.selector-5]>26){ timing[((context.days-1)*24)+context.selector-5]=26; msg.foryou=\"Limite raggiunto\";}\n else msg.foryou=\"Temperatura aumentata\";\n }\n if (context.selector==1) { if (timing[168+(context.selector-1)]<26) { timing[168+(context.selector-1)]++; msg.foryou=\"Temperatura clima aumentata di 1°C\"; } else msg.foryou=\"Limite raggiunto\"; }\n if (context.selector==2) { if (timing[168+(context.selector-1)]<26) { timing[168+(context.selector-1)]++; msg.foryou=\"Temperatura fuori casa aumentata di 1°C\"; } else msg.foryou=\"Limite raggiunto\"; }\n if (context.selector==29) { msg.foryou=\"Next day\"; context.days++; if (context.days>7) { context.days = 1; } }\n break;\n case \"d\" : if ((context.selector>4)&&(context.selector<29))\n {\n timing[((context.days-1)*24)+context.selector-5]--; \n if (timing[((context.days-1)*24)+context.selector-5]<10){ timing[((context.days-1)*24)+context.selector-5]=14; msg.foryou=\"Limite raggiunto\";}\n else msg.foryou=\"Temperatura decrementata\";\n }\n if (context.selector==1) { if (timing[168+(context.selector-1)]>12) { timing[168+(context.selector-1)]--; msg.foryou=\"Temperatura clima diminuita di 1°C\"; } else msg.foryou=\"Limite raggiunto\"; }\n if (context.selector==2) { if (timing[168+(context.selector-1)]>12) { timing[168+(context.selector-1)]--; msg.foryou=\"Temperatura fuori casa diminuita di 1°C\"; } else msg.foryou=\"Limite raggiunto\"; }\n if (context.selector==29) { msg.foryou=\"Previous day\"; context.days--; if (context.days < 1) { context.days = 7; } }\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 msg.foryou=\"Temperatura copiata nello slot successivo\";\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 msg.foryou=\"Impostazioni copiate nel giorno successivo\";\n }\n else if(context.days==7)\n msg.foryou=\"Fine della settimana raggiunto!\";\n break;\n case 's': context.saving=0; msg.foryou=\"Impostazioni salvate\"; 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);\n if (msg.payload=='1') msg.foryou=\"Temperatura clima selezionata\"; \n else if (msg.payload=='2') msg.foryou=\"Temperatura fuori casa selezionata\";\n else if (msg.payload=='29') msg.foryou=\"Giorno selezionato\";\n else msg.foryou=\"Regolazione temperatura ore: \" + (parseInt(msg.payload)-5);\n break;\n case 'c' : msg.payload=\"niente\"; msg.foryou=\"Cambiamenti annullati\"; node.send([null,null,msg]);\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 }\n msg.foryou=\"\"",
"outputs": "3",
"noerr": 0,
"x": 680,
"y": 220,
"wires": [
[
"9e4471f8.504c9"
],
[
"4c289645.1d0c88"
],
[
"23c5ae57.908fc2"
]
]
},
{
"id": "b776282e.6cc2b8",
"type": "inject",
"z": "ea4a330a.bb7e6",
"name": "Once only",
"topic": "",
"payload": "",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": true,
"x": 330,
"y": 220,
"wires": [
[
"685115e8.a7daec",
"23c5ae57.908fc2"
]
]
},
{
"id": "d88b185.97925e8",
"type": "inject",
"z": "ea4a330a.bb7e6",
"name": "Every hour",
"topic": "",
"payload": "",
"payloadType": "str",
"repeat": "3600",
"crontab": "",
"once": true,
"x": 480,
"y": 700,
"wires": [
[
"c8f747a4.d4eee8"
]
]
},
{
"id": "7ddabb31.3f34f4",
"type": "function",
"z": "ea4a330a.bb7e6",
"name": "Process heat",
"func": "var timing=global.get(\"timing\");\nvar now = new Date(msg.time);\nmsg.payload=timing[(now.getDay()*24)+now.getHours()];\nmsg.frost=timing[168];\nmsg.away=timing[169];\nnode.status({fill:\"blue\",shape:\"dot\",text:\"Set point \" + msg.payload + \"°C\"});\nreturn msg;\n\n",
"outputs": 1,
"noerr": 0,
"x": 820,
"y": 700,
"wires": [
[
"99fc917c.3c76f"
]
]
},
{
"id": "4c289645.1d0c88",
"type": "file",
"z": "ea4a330a.bb7e6",
"name": "backup",
"filename": "/home/simon.maddox/.node-red/data/thermo_scheduler.log",
"appendNewline": true,
"createDir": true,
"overwriteFile": "true",
"x": 920,
"y": 220,
"wires": []
},
{
"id": "23c5ae57.908fc2",
"type": "file in",
"z": "ea4a330a.bb7e6",
"name": "Restore",
"filename": "/home/simon.maddox/.node-red/data/thermo_scheduler.log",
"format": "utf8",
"sendError": true,
"x": 560,
"y": 300,
"wires": [
[
"d53e7e0c.38af"
]
]
},
{
"id": "d53e7e0c.38af",
"type": "function",
"z": "ea4a330a.bb7e6",
"name": "Restore data from SD",
"func": "context.global.timing=JSON.parse(msg.payload);\nmsg.payload=\"\";\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 780,
"y": 300,
"wires": [
[
"685115e8.a7daec"
]
]
},
{
"id": "c8f747a4.d4eee8",
"type": "moment",
"z": "ea4a330a.bb7e6",
"name": "time",
"topic": "",
"input": "",
"inputType": "date",
"inTz": "UTC",
"adjAmount": "0",
"adjType": "hours",
"adjDir": "add",
"format": "",
"locale": "en_gb",
"output": "time",
"outputType": "msg",
"outTz": "Europe/London",
"x": 660,
"y": 700,
"wires": [
[
"7ddabb31.3f34f4"
]
]
},
{
"id": "99fc917c.3c76f",
"type": "mqtt out",
"z": "ea4a330a.bb7e6",
"name": "",
"topic": "settings/lounge/targets/temperature",
"qos": "2",
"retain": "true",
"broker": "e4e72b98.749778",
"x": 1110,
"y": 700,
"wires": []
},
{
"id": "26e49e05.954bf2",
"type": "ui_button",
"z": "ea4a330a.bb7e6",
"name": "",
"group": "cbcc2b66.d9e678",
"order": 3,
"width": "0",
"height": "0",
"passthru": false,
"label": "Home",
"color": "",
"bgcolor": "#404040",
"icon": "",
"payload": "Home",
"payloadType": "str",
"topic": "",
"x": 260,
"y": 920,
"wires": [
[
"cdae219e.4167"
]
]
},
{
"id": "cce948d7.cac208",
"type": "ui_button",
"z": "ea4a330a.bb7e6",
"name": "",
"group": "cbcc2b66.d9e678",
"order": 1,
"width": "3",
"height": "1",
"passthru": false,
"label": "Charts",
"color": "",
"bgcolor": "#404040",
"icon": "",
"payload": "Charts",
"payloadType": "str",
"topic": "",
"x": 260,
"y": 840,
"wires": [
[
"cdae219e.4167"
]
]
},
{
"id": "cdae219e.4167",
"type": "ui_ui_control",
"z": "ea4a330a.bb7e6",
"name": "ui control",
"x": 430,
"y": 880,
"wires": [
[]
]
},
{
"id": "5b8b70b7.59c5b",
"type": "ui_button",
"z": "ea4a330a.bb7e6",
"name": "",
"group": "cbcc2b66.d9e678",
"order": 2,
"width": "3",
"height": "1",
"passthru": false,
"label": "Console",
"color": "",
"bgcolor": "#404040",
"icon": "",
"payload": "Console",
"payloadType": "str",
"topic": "",
"x": 270,
"y": 880,
"wires": [
[
"cdae219e.4167"
]
]
},
{
"id": "6f8550d0.cddd3",
"type": "ui_button",
"z": "ea4a330a.bb7e6",
"name": "Boost",
"group": "3f0f8980.fdfed6",
"order": 6,
"width": "2",
"height": "2",
"passthru": false,
"label": "{{msg.label}}",
"color": "{{msg.colour}}",
"bgcolor": "#404040",
"icon": "fa-thermometer-full fa-4x",
"payload": "true",
"payloadType": "bool",
"topic": "",
"x": 610,
"y": 520,
"wires": [
[
"d9cd1b4e.f12548",
"7d65861f.177738",
"6e50ea23.b378d4"
]
]
},
{
"id": "7d65861f.177738",
"type": "function",
"z": "ea4a330a.bb7e6",
"name": "Toggle",
"func": " context.state = context.state | false;\n\n\nswitch(msg.payload) {\n case true: \n context.state = true\n msg.colour = \"#a02020\";\n node.status({fill:\"red\",shape:\"dot\",text:msg.payload});\n break;\n case false:\n context.state = false\n msg.colour = \"#808080\";\n node.status({fill:\"grey\",shape:\"ring\",text:msg.payload});\n break;\n default:\n context.state = !context.state;\n break;\n }\n msg.payload = context.state;\n\n if (msg.payload){\n node.status({fill:\"red\",shape:\"dot\",text:msg.payload});\n }else{\n node.status({fill:\"grey\",shape:\"ring\",text:msg.payload});\n }\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 620,
"y": 440,
"wires": [
[
"6f8550d0.cddd3"
]
]
},
{
"id": "cde6687e.e42348",
"type": "inject",
"z": "ea4a330a.bb7e6",
"name": "startup",
"topic": "",
"payload": "false",
"payloadType": "bool",
"repeat": "",
"crontab": "",
"once": true,
"x": 420,
"y": 440,
"wires": [
[
"7d65861f.177738"
]
]
},
{
"id": "d9cd1b4e.f12548",
"type": "trigger",
"z": "ea4a330a.bb7e6",
"op1": "",
"op2": "false",
"op1type": "nul",
"op2type": "bool",
"duration": "60",
"extend": true,
"units": "min",
"reset": "",
"name": "Boost timer",
"x": 600,
"y": 580,
"wires": [
[
"7d65861f.177738",
"c8f747a4.d4eee8"
]
]
},
{
"id": "96ea8f3.50a367",
"type": "ui_button",
"z": "ea4a330a.bb7e6",
"name": "Revert",
"group": "3f0f8980.fdfed6",
"order": 7,
"width": "2",
"height": "2",
"passthru": false,
"label": "{{msg.label}}",
"color": "#808080",
"bgcolor": "#404040",
"icon": "fa-clock-o fa-4x",
"payload": "false",
"payloadType": "bool",
"topic": "reset",
"x": 100,
"y": 580,
"wires": [
[
"3148e200.72d83e",
"7d65861f.177738",
"c8f747a4.d4eee8"
]
]
},
{
"id": "3148e200.72d83e",
"type": "change",
"z": "ea4a330a.bb7e6",
"name": "",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "reset",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 360,
"y": 580,
"wires": [
[
"d9cd1b4e.f12548"
]
]
},
{
"id": "6e50ea23.b378d4",
"type": "change",
"z": "ea4a330a.bb7e6",
"name": "25C",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "25",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 850,
"y": 640,
"wires": [
[
"99fc917c.3c76f"
]
]
},
{
"id": "151be4a4.2a40bb",
"type": "ui_group",
"z": "",
"name": "Stat",
"tab": "5955d47b.d81d1c",
"order": 1,
"disp": false,
"width": "6"
},
{
"id": "e4e72b98.749778",
"type": "mqtt-broker",
"z": "",
"broker": "localhost",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"willTopic": "",
"willQos": "0",
"willPayload": "",
"birthTopic": "",
"birthQos": "0",
"birthPayload": ""
},
{
"id": "cbcc2b66.d9e678",
"type": "ui_group",
"z": "",
"name": "Navigation",
"tab": "5955d47b.d81d1c",
"order": 3,
"disp": false,
"width": "6"
},
{
"id": "3f0f8980.fdfed6",
"type": "ui_group",
"z": "",
"name": "Temperature",
"tab": "e5bc8a1a.f5e098",
"order": 1,
"disp": false,
"width": "8"
},
{
"id": "5955d47b.d81d1c",
"type": "ui_tab",
"z": "",
"name": "Settings",
"icon": "dashboard",
"order": 2
},
{
"id": "e5bc8a1a.f5e098",
"type": "ui_tab",
"z": "",
"name": "Home",
"icon": "dashboard",
"order": 1
}
]
@acremers87
Copy link

Hello,
Just curious what are the dependencies for this flow? I have copied your code to node-red but I am missing a module. The module I am missing is between your "Every Hour" inject and your "Process heat" function. Any help would be greatly appreciated.
Thanks,
Andrew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment