UNPKG

node-red-contrib-sun-position

Version:
853 lines 29.2 kB
[ { "id": "c76466a96ba836b1", "type": "group", "z": "c224c971b366d1da", "name": "Example 4:", "style": { "label": true }, "nodes": [ "ae28974eb66d7e01", "2997c81e7b2225c1", "55b37b3d630fcba4", "961b294957d3a191", "c496262a3e6fe741", "2c7bb11cbc989bd0", "13b8c1499694447c", "d418e260b6b136cd", "96d5f4a031ca61f5", "fb6e7667db75ddfe", "6c876fb5569b72c1", "4e86bf5fa7ce9eb4", "4bda9eccdbfdb495", "bfa382b93bd597ad", "c2682807c38e7984", "d2ee545cee421e7d", "f1cff356b43f2361", "950ddb2bda38827c", "5945cf207c1f9d75", "bc0b1a95c3c96bba", "540c58172e24984e", "12fc3eb929f5fa03", "77af066a2c94381b", "147b4386c49ec7cc", "41297f15f6a5173b" ], "x": 84, "y": 944, "w": 1032, "h": 547 }, { "id": "ae28974eb66d7e01", "type": "function", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "30min 0.5sec", "func": "\nconst minutesEachLoop = 20; // minutes to add\nconst loopCycle = 2; // 0.3; // seconds delay\nlet timeObj = context.get(\"timeObj\");\n\nconst days = ['sun','mon','tue','wed','thu','fri','sat'];\n\nif (timeObj && msg.topic.includes('stop')) {\n clearInterval(timeObj);\n context.set(\"timeObj\", null);\n context.set(\"orgtopic\", null);\n let d = new Date(context.get(\"date\"));\n node.log(\"STOP \" + d.toLocaleTimeString() + ' ####################################### payload='+msg.payload+' topic='+msg.topic);\n node.log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ' + d.toISOString());\n node.status({fill:\"red\",shape:\"ring\",text:\"stopped - \" + d.toLocaleTimeString() + ' (' + d.getDay() + ' ' + days[d.getDay()] + ')'});\n return null;\n} else if (!timeObj && msg.topic.includes('start')) {\n context.set(\"message\", msg);\n context.set(\"orgtopic\", msg.topic);\n context.set(\"dateroll\", -1);\n let d = new Date();\n if (typeof msg.payload === 'string' && msg.payload.length > 0) {\n for (let i=0; i<7; i++) {\n\t \t if (msg.payload.includes(days[i])) {\n\t \t msg.payload = msg.payload.replace(days[i],'').trim();\n \t d.setDate(d.getDate() + (i+(7-d.getDay())) % 7);\n \t break;\n }\n }\n if (msg.payload.includes('days')) {\n d.setDate(d.getDate() + (1+(7-d.getDay())) % 7);\n msg.payload = msg.payload.replace('days','').trim();\n context.set(\"dateroll\", 1);\n }\n }\n let num = Number(msg.payload);\n if (!isNaN(num) && num < 24) {\n d.setHours(num);\n d.setMinutes(0);\n } else {\n let dt = new Date(msg.payload);\n if (dt instanceof Date && !isNaN(dt)) {\n d = dt;\n } else {\n d.setHours(0);\n d.setMinutes(0);\n }\n }\n context.set(\"date\", d.getTime());\n msg.tsISO = d.toISOString();\n msg.ts = d.getTime();\n msg.topic += ' ' + d.toLocaleTimeString();\n node.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');\n node.log(\"START \" + d.toLocaleTimeString() + ' ####################################### payload='+msg.payload+' topic='+msg.topic);\n node.send(msg);\n\n let timeObj = setInterval(function(){\n let msg = context.get(\"message\");\n let topic = context.get(\"orgtopic\");\n let dr = context.get(\"dateroll\");\n let d = new Date(context.get(\"date\"));\n let dt = d.getDate();\n let dm = d.getMonth();\n if (dr >0) {\n dr++;\n if (dr>8) { dr=1; }\n d.setDate(d.getDate() + (dr+(7-d.getDay())) % 7);\n context.set(\"dateroll\", dr);\n } else {\n //d.setHours(d.getHours()+1);\n d.setMinutes(d.getMinutes() + minutesEachLoop)\n d.setDate(dt);\n d.getMonth(dm);\n }\n context.set(\"date\", d.getTime());\n msg.tsISO = d.toISOString();\n msg.ts = d.getTime();\n msg.topic = topic + ' ' + d.toLocaleTimeString();\n node.status({fill:\"green\",shape:\"dot\",text:\"run - \" + d.toLocaleTimeString() + ' (' + d.getDay() + ' ' + days[d.getDay()] + ')'});\n node.log(\"sending \" + d.toLocaleTimeString() + ' ####################################### payload='+msg.payload+' topic='+msg.topic);\n node.send(msg);\n\t}, (1000 * loopCycle));\n context.set(\"timeObj\", timeObj);\n node.status({fill:\"green\",shape:\"ring\",text:\"start - \" + d.toLocaleTimeString() + ' (' + d.getDay() + ' ' + days[d.getDay()] + ')'});\n return null;\n}\n\nlet d = new Date(context.get(\"date\"));\nif (!(d instanceof Date) || isNaN(d)) {\n d = new Date();\n}\nd.setMinutes(d.getMinutes() + 1)\n//d.setHours(d.getHours()+1);\nmsg.tsISO = d.toISOString();\nmsg.ts = d.getTime();\nmsg.topic += ' ' + d.toLocaleTimeString();\nnode.status({fill:\"yellow\",shape:\"dot\",text:\"interposed - \" + d.toLocaleTimeString() + ' (' + d.getDay() + ' ' + days[d.getDay()] + ') - ' + msg.payload});\nnode.log(\"sending interposed msg \" + d.toLocaleTimeString() + ' ####################################### payload='+msg.payload+' topic='+msg.topic);\nnode.send(msg);\nreturn null;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 530, "y": 1060, "wires": [ [ "fb6e7667db75ddfe" ] ] }, { "id": "2997c81e7b2225c1", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "start/stop", "payload": "0", "payloadType": "num", "x": 235, "y": 1015, "wires": [ [ "ae28974eb66d7e01" ] ] }, { "id": "55b37b3d630fcba4", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "reset", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "resetOverwrite", "payload": "true", "payloadType": "bool", "x": 210, "y": 1105, "wires": [ [ "ae28974eb66d7e01" ] ] }, { "id": "961b294957d3a191", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "0%", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "levelOverwrite", "payload": "0", "payloadType": "num", "x": 210, "y": 1145, "wires": [ [ "ae28974eb66d7e01" ] ] }, { "id": "c496262a3e6fe741", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "60%", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "levelOverwrite", "payload": "0.6", "payloadType": "num", "x": 210, "y": 1190, "wires": [ [ "ae28974eb66d7e01" ] ] }, { "id": "2c7bb11cbc989bd0", "type": "comment", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "manual overrides:", "info": "", "x": 205, "y": 1060, "wires": [] }, { "id": "13b8c1499694447c", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "90%, expire 2,5s", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "{\"position\":0.9,\"expire\":2500}", "payloadType": "json", "x": 240, "y": 1240, "wires": [ [ "ae28974eb66d7e01" ] ] }, { "id": "d418e260b6b136cd", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "30% importance 1", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "{\"position\":0.3,\"importance\":1}", "payloadType": "json", "x": 220, "y": 1285, "wires": [ [ "ae28974eb66d7e01" ] ] }, { "id": "96d5f4a031ca61f5", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "100% importance 1", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "{\"importance\":1, \"position\":1}", "payloadType": "json", "x": 230, "y": 1330, "wires": [ [ "ae28974eb66d7e01" ] ] }, { "id": "fb6e7667db75ddfe", "type": "blind-control", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "", "topic": "", "addIdType": "none", "addId": "", "positionConfig": "", "autoTrigger": false, "autoTriggerTime": "1200000", "startDelayTime": "0", "results": [ { "p": "", "pt": "msgTopic", "v": "", "vt": "topic" }, { "p": "", "pt": "msgPayload", "v": "", "vt": "level" }, { "p": "slat", "pt": "msg", "v": "", "vt": "slat" }, { "p": "blindCtrl", "pt": "msg", "v": "", "vt": "ctrlObj" } ], "blindIncrement": "0.01", "blindOpenPos": "1", "blindClosedPos": 0, "blindPosDefault": "open (max)", "blindPosDefaultType": "levelFixed", "slatPosDefault": "", "slatPosDefaultType": "none", "overwriteExpire": "7200000", "rules": [ { "index": 0, "name": "", "version": 3, "isValid": true, "conditions": [ { "valueType": "msg", "value": "windowOpen", "operator": "true", "operatorText": "ist true", "thresholdType": "str", "threshold": "windowOpen" } ], "level": { "type": "levelFixed", "value": "10%", "operator": 1, "operatorText": "⭳❗ Minimum (übersteuernd)" }, "slat": { "type": "none", "value": "" }, "description": "<div><i class=\"fa fa-code-fork\" aria-hidden=\"true\"></i> <var>msg.windowOpen</var> ist true</div><div><div class=\"indent-level-text\"> <i class=\"fa fa-angle-down\" aria-hidden=\"true\"></i><span>Rollladenposition: </span> ⭳❗ Minimum (übersteuernd) <var>10%</var></div></div>", "importance": 0 }, { "index": 1, "name": "", "version": 3, "isValid": true, "conditions": [], "level": { "type": "levelFixed", "value": "closed (min)", "operator": 0, "operatorText": "↕ Absolut" }, "slat": { "type": "none", "value": "" }, "topic": "", "importance": 0, "resetOverwrite": false, "time": { "type": "pdsTime", "value": "civilDawn", "operator": 0, "operatorText": "↥ bis", "offsetType": "none", "offset": "1", "multiplier": 60000, "days": "*", "months": "*" }, "timeMin": { "type": "entered", "value": "5:30", "offsetType": "none", "offset": "1", "multiplier": 60000 }, "description": "<div><i class=\"fa fa-clock-o\" aria-hidden=\"true\"></i> ↥ bis <var>bürgerliche Morgendämmerung</var><div class=\"indent-time-text\"><i class=\"fa fa-step-backward\" aria-hidden=\"true\"></i> <span>frühestens (min)</span> <var>5:30</var></div></div><div><div class=\"indent-level-text\"> <i class=\"fa fa-angle-down\" aria-hidden=\"true\"></i><span>Rollladenposition: </span> ↕ Absolut <var>geschlossen (min)</var></div></div>" }, { "index": 2, "name": "", "version": 3, "isValid": true, "conditions": [ { "valueType": "flow", "value": "dayInfo.today.isWeekendOrHoliday", "operator": "true", "operatorText": "ist true", "thresholdType": "str", "threshold": "" } ], "level": { "type": "levelFixed", "value": "closed (min)", "operator": 0, "operatorText": "↕ Absolut" }, "slat": { "type": "none", "value": "" }, "topic": "", "importance": 0, "resetOverwrite": false, "time": { "type": "pdsTime", "value": "civilDawn", "operator": 0, "operatorText": "↥ bis", "offsetType": "none", "offset": "1", "multiplier": 60000, "days": "*", "months": "*" }, "timeMin": { "type": "entered", "value": "7:25", "offsetType": "none", "offset": "1", "multiplier": 60000 }, "description": "<div><i class=\"fa fa-code-fork\" aria-hidden=\"true\"></i> <var>flow....fo.today.isWeekendOrHoliday</var> ist true</div><div><i class=\"fa fa-clock-o\" aria-hidden=\"true\"></i> ↥ bis <var>bürgerliche Morgendämmerung</var><div class=\"indent-time-text\"><i class=\"fa fa-step-backward\" aria-hidden=\"true\"></i> <span>frühestens (min)</span> <var>7:25</var></div></div><div><div class=\"indent-level-text\"> <i class=\"fa fa-angle-down\" aria-hidden=\"true\"></i><span>Rollladenposition: </span> ↕ Absolut <var>geschlossen (min)</var></div></div>" }, { "index": 3, "name": "", "version": 3, "isValid": true, "conditions": [ { "valueType": "msg", "value": "raining", "operator": "true", "operatorText": "ist true", "thresholdType": "num", "threshold": 0 } ], "level": { "type": "levelFixed", "value": "50%", "operator": 2, "operatorText": "⭱️❗ Maximum (übersteuernd)" }, "slat": { "type": "none", "value": "" }, "description": "<div><i class=\"fa fa-code-fork\" aria-hidden=\"true\"></i> <var>msg.raining</var> ist true</div><div><div class=\"indent-level-text\"> <i class=\"fa fa-angle-down\" aria-hidden=\"true\"></i><span>Rollladenposition: </span> ⭱️❗ Maximum (übersteuernd) <var>50%</var></div></div>", "importance": 0 }, { "index": 4, "name": "", "version": 3, "isValid": true, "conditions": [ { "valueType": "flow", "value": "dayInfo.tomorrow.isWeekendOrHoliday", "operator": "false", "operatorText": "ist false", "thresholdType": "str", "threshold": "" } ], "level": { "type": "levelFixed", "value": "closed (min)", "operator": 0, "operatorText": "↕ Absolut" }, "slat": { "type": "none", "value": "" }, "topic": "", "importance": 0, "resetOverwrite": false, "time": { "type": "pdsTime", "value": "civilDusk", "operator": 1, "operatorText": "↧ von", "offsetType": "none", "offset": "1", "multiplier": 60000, "days": "*", "months": "*" }, "timeMax": { "type": "entered", "value": "21:25", "offsetType": "none", "offset": "1", "multiplier": 60000 }, "description": "<div><i class=\"fa fa-code-fork\" aria-hidden=\"true\"></i> <var>flow....tomorrow.isWeekendOrHoliday</var> ist false</div><div><i class=\"fa fa-clock-o\" aria-hidden=\"true\"></i> ↧ von <var>bürgerliche Abenddämmerung</var><div class=\"indent-time-text\"><i class=\"fa fa-step-forward\" aria-hidden=\"true\"></i> <span>spätestens (max)</span> <var>21:25</var></div></div><div><div class=\"indent-level-text\"> <i class=\"fa fa-angle-down\" aria-hidden=\"true\"></i><span>Rollladenposition: </span> ↕ Absolut <var>geschlossen (min)</var></div></div>" }, { "index": 5, "name": "", "version": 3, "isValid": true, "conditions": [], "level": { "type": "levelFixed", "value": "closed (min)", "operator": 0, "operatorText": "↕ Absolut" }, "slat": { "type": "none", "value": "" }, "topic": "", "importance": 0, "resetOverwrite": false, "time": { "type": "pdsTime", "value": "civilDusk", "operator": 1, "operatorText": "↧ von", "offsetType": "none", "offset": "1", "multiplier": 60000, "days": "*", "months": "*" }, "timeMax": { "type": "entered", "value": "23:15", "offsetType": "none", "offset": "1", "multiplier": 60000 }, "description": "<div><i class=\"fa fa-clock-o\" aria-hidden=\"true\"></i> ↧ von <var>bürgerliche Abenddämmerung</var><div class=\"indent-time-text\"><i class=\"fa fa-step-forward\" aria-hidden=\"true\"></i> <span>spätestens (max)</span> <var>23:15</var></div></div><div><div class=\"indent-level-text\"> <i class=\"fa fa-angle-down\" aria-hidden=\"true\"></i><span>Rollladenposition: </span> ↕ Absolut <var>geschlossen (min)</var></div></div>" } ], "sunControlMode": 16, "sunFloorLengthType": "num", "sunFloorLength": "0.6", "sunMinDelta": "0.1", "blindPosMin": "closed (min)", "blindPosMinType": "levelFixed", "blindPosMax": "open (max)", "blindPosMaxType": "levelFixed", "sunSlat": "", "sunSlatType": "none", "smoothTime": "", "sunTopic": "", "windowTopType": "num", "windowTop": "1.28", "windowBottomType": "num", "windowBottom": "0", "windowAzimuthStartType": "numAzimuth", "windowAzimuthStart": "70", "windowAzimuthEndType": "numAzimuth", "windowAzimuthEnd": "150", "oversteers": [], "oversteerTopic": "", "x": 750, "y": 1060, "wires": [ [ "6c876fb5569b72c1" ], [] ] }, { "id": "6c876fb5569b72c1", "type": "debug", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "Blind position", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "x": 995, "y": 1060, "wires": [] }, { "id": "4e86bf5fa7ce9eb4", "type": "change", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "dayInfo.today.isWeekendOrHoliday", "rules": [ { "t": "set", "p": "dayInfo.today.isWeekendOrHoliday", "pt": "flow", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 825, "y": 1135, "wires": [ [] ] }, { "id": "4bda9eccdbfdb495", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "true", "payloadType": "bool", "x": 555, "y": 1135, "wires": [ [ "4e86bf5fa7ce9eb4" ] ] }, { "id": "bfa382b93bd597ad", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "", "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "topic": "", "payload": "false", "payloadType": "bool", "x": 555, "y": 1180, "wires": [ [ "4e86bf5fa7ce9eb4" ] ] }, { "id": "c2682807c38e7984", "type": "change", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "dayInfo.tomorrow.isWeekendOrHoliday", "rules": [ { "t": "set", "p": "dayInfo.tomorrow.isWeekendOrHoliday", "pt": "flow", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 835, "y": 1225, "wires": [ [] ] }, { "id": "d2ee545cee421e7d", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "true", "payloadType": "bool", "x": 555, "y": 1225, "wires": [ [ "c2682807c38e7984" ] ] }, { "id": "f1cff356b43f2361", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "", "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "topic": "", "payload": "false", "payloadType": "bool", "x": 555, "y": 1270, "wires": [ [ "c2682807c38e7984" ] ] }, { "id": "950ddb2bda38827c", "type": "change", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "", "rules": [ { "t": "set", "p": "windowOpen", "pt": "msg", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 870, "y": 1315, "wires": [ [ "12fc3eb929f5fa03" ] ] }, { "id": "5945cf207c1f9d75", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "window open", "payload": "true", "payloadType": "bool", "x": 585, "y": 1315, "wires": [ [ "950ddb2bda38827c" ] ] }, { "id": "bc0b1a95c3c96bba", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "", "repeat": "", "crontab": "", "once": true, "onceDelay": "0.5", "topic": "window closed", "payload": "false", "payloadType": "bool", "x": 605, "y": 1360, "wires": [ [ "950ddb2bda38827c" ] ] }, { "id": "540c58172e24984e", "type": "link in", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "do_refreshBlind_state", "links": [ "12fc3eb929f5fa03", "dba49bc7.8be158" ], "x": 430, "y": 985, "wires": [ [ "ae28974eb66d7e01" ] ] }, { "id": "12fc3eb929f5fa03", "type": "link out", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "trigger_refreshBlind_state", "links": [ "540c58172e24984e" ], "x": 1075, "y": 1315, "wires": [] }, { "id": "77af066a2c94381b", "type": "change", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "", "rules": [ { "t": "set", "p": "raining", "pt": "msg", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 850, "y": 1405, "wires": [ [ "12fc3eb929f5fa03" ] ] }, { "id": "147b4386c49ec7cc", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "is raining", "payload": "true", "payloadType": "bool", "x": 575, "y": 1405, "wires": [ [ "77af066a2c94381b" ] ] }, { "id": "41297f15f6a5173b", "type": "inject", "z": "c224c971b366d1da", "g": "c76466a96ba836b1", "name": "", "repeat": "", "crontab": "", "once": true, "onceDelay": "0.7", "topic": "is raining", "payload": "false", "payloadType": "bool", "x": 585, "y": 1450, "wires": [ [ "77af066a2c94381b" ] ] } ]