node-red-contrib-sun-position
Version:
NodeRED nodes to get sun and moon position
618 lines • 22.7 kB
JSON
[
{
"id": "f154222105f64635",
"type": "group",
"z": "c224c971b366d1da",
"name": "Example 3:",
"style": {
"label": true
},
"nodes": [
"63677e342a2b4852",
"50ece54c266a208c",
"476de16a1fed3df5",
"5b9d9975b243bd29",
"f00cd7fd0c194cc9",
"9336e0b901db3e22",
"3aa7f018fb3f61cc",
"84fd3f1ff36ef62b",
"d51582816e0b4932",
"6f988ad16fa7500e",
"735d3627bdb581e7",
"9b6ad2e5a5d7eeea",
"1de03741c7881227",
"4b858878346ebe2a",
"fe6920ed64b8cf0c",
"e96f0f06de5514d8",
"26931e3fb054bf5f"
],
"x": 84,
"y": 494,
"w": 1027,
"h": 397
},
{
"id": "63677e342a2b4852",
"type": "function",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "30min 1sec",
"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": 580,
"wires": [
[
"6f988ad16fa7500e"
]
]
},
{
"id": "50ece54c266a208c",
"type": "inject",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "start/stop",
"payload": "0",
"payloadType": "num",
"x": 235,
"y": 535,
"wires": [
[
"63677e342a2b4852"
]
]
},
{
"id": "476de16a1fed3df5",
"type": "inject",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "reset",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "resetOverwrite",
"payload": "true",
"payloadType": "bool",
"x": 210,
"y": 625,
"wires": [
[
"63677e342a2b4852"
]
]
},
{
"id": "5b9d9975b243bd29",
"type": "inject",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "0%",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "levelOverwrite",
"payload": "0",
"payloadType": "num",
"x": 210,
"y": 665,
"wires": [
[
"63677e342a2b4852"
]
]
},
{
"id": "f00cd7fd0c194cc9",
"type": "inject",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "60%",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "levelOverwrite",
"payload": "0.6",
"payloadType": "num",
"x": 210,
"y": 710,
"wires": [
[
"63677e342a2b4852"
]
]
},
{
"id": "9336e0b901db3e22",
"type": "comment",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "manual overrides:",
"info": "",
"x": 205,
"y": 580,
"wires": []
},
{
"id": "3aa7f018fb3f61cc",
"type": "inject",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "90%, expire 2,5s",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"position\":0.9,\"expire\":2500}",
"payloadType": "json",
"x": 240,
"y": 760,
"wires": [
[
"63677e342a2b4852"
]
]
},
{
"id": "84fd3f1ff36ef62b",
"type": "inject",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "30% importance 1",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"position\":0.3,\"importance\":1}",
"payloadType": "json",
"x": 220,
"y": 805,
"wires": [
[
"63677e342a2b4852"
]
]
},
{
"id": "d51582816e0b4932",
"type": "inject",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "100% importance 1",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"importance\":1, \"position\":1}",
"payloadType": "json",
"x": 230,
"y": 850,
"wires": [
[
"63677e342a2b4852"
]
]
},
{
"id": "6f988ad16fa7500e",
"type": "blind-control",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"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": [],
"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": 1,
"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": 1,
"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": 1,
"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": 2,
"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": 1,
"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": 3,
"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": 1,
"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": "",
"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": 580,
"wires": [
[
"735d3627bdb581e7"
],
[]
]
},
{
"id": "735d3627bdb581e7",
"type": "debug",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "Blind position",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 995,
"y": 580,
"wires": []
},
{
"id": "9b6ad2e5a5d7eeea",
"type": "change",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "dayInfo.today.isWeekendOrHoliday",
"rules": [
{
"t": "set",
"p": "dayInfo.today.isWeekendOrHoliday",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 795,
"y": 715,
"wires": [
[]
]
},
{
"id": "1de03741c7881227",
"type": "inject",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "true",
"payloadType": "bool",
"x": 525,
"y": 715,
"wires": [
[
"9b6ad2e5a5d7eeea"
]
]
},
{
"id": "4b858878346ebe2a",
"type": "inject",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "false",
"payloadType": "bool",
"x": 525,
"y": 760,
"wires": [
[
"9b6ad2e5a5d7eeea"
]
]
},
{
"id": "fe6920ed64b8cf0c",
"type": "change",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "dayInfo.tomorrow.isWeekendOrHoliday",
"rules": [
{
"t": "set",
"p": "dayInfo.tomorrow.isWeekendOrHoliday",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 805,
"y": 805,
"wires": [
[]
]
},
{
"id": "e96f0f06de5514d8",
"type": "inject",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "true",
"payloadType": "bool",
"x": 525,
"y": 805,
"wires": [
[
"fe6920ed64b8cf0c"
]
]
},
{
"id": "26931e3fb054bf5f",
"type": "inject",
"z": "c224c971b366d1da",
"g": "f154222105f64635",
"name": "",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "false",
"payloadType": "bool",
"x": 525,
"y": 850,
"wires": [
[
"fe6920ed64b8cf0c"
]
]
}
]