mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
parent
a5faf13c4d
commit
ddaa9b24b8
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-timeswitch",
|
"name" : "node-red-node-timeswitch",
|
||||||
"version" : "1.0.0",
|
"version" : "1.1.0",
|
||||||
"description" : "A Node-RED node to provide a simple timeswitch to schedule daily on/off events.",
|
"description" : "A Node-RED node to provide a simple timeswitch to schedule daily on/off events.",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"spacetime": "^7.4.0",
|
"spacetime": "^7.4.3",
|
||||||
"suncalc": "^1.8.0"
|
"suncalc": "^1.9.0"
|
||||||
},
|
},
|
||||||
"repository" : {
|
"repository" : {
|
||||||
"type":"git",
|
"type":"git",
|
||||||
|
@ -46,9 +46,16 @@ module.exports = function (RED) {
|
|||||||
|
|
||||||
// all sun events for the given lat/long
|
// all sun events for the given lat/long
|
||||||
const sunEvents = SunCalc.getTimes(nowNative, node.lat, node.lon);
|
const sunEvents = SunCalc.getTimes(nowNative, node.lat, node.lon);
|
||||||
|
const sunAlt = SunCalc.getPosition(nowNative, node.lat, node.lon).altitude;
|
||||||
let sunriseDateTime = spacetime(sunEvents[SUNRISE_KEY]).nearest("minute");
|
let sunriseDateTime = spacetime(sunEvents[SUNRISE_KEY]).nearest("minute");
|
||||||
let sunsetDateTime = spacetime(sunEvents[SUNSET_KEY]).nearest("minute");
|
let sunsetDateTime = spacetime(sunEvents[SUNSET_KEY]).nearest("minute");
|
||||||
|
|
||||||
|
var aday
|
||||||
|
if (sunEvents[SUNRISE_KEY] == "Invalid Date" || sunEvents[SUNSET_KEY] == "Invalid Date") {
|
||||||
|
if (sunAlt >= 0) { aday = 1; }
|
||||||
|
else { aday = 0; }
|
||||||
|
}
|
||||||
|
|
||||||
// add optional sun event offset, if specified
|
// add optional sun event offset, if specified
|
||||||
sunriseDateTime = sunriseDateTime.add(Number(node.sunriseOffset), "minutes");
|
sunriseDateTime = sunriseDateTime.add(Number(node.sunriseOffset), "minutes");
|
||||||
sunsetDateTime = sunsetDateTime.add(Number(node.sunsetOffset), "minutes");
|
sunsetDateTime = sunsetDateTime.add(Number(node.sunsetOffset), "minutes");
|
||||||
@ -126,6 +133,7 @@ module.exports = function (RED) {
|
|||||||
// var o = nextTime.goto(selectedTimeZone.name).offset()/60;
|
// var o = nextTime.goto(selectedTimeZone.name).offset()/60;
|
||||||
// if (o > 0) { o = "+" + o; }
|
// if (o > 0) { o = "+" + o; }
|
||||||
// else {o = "-" + o; }
|
// else {o = "-" + o; }
|
||||||
|
if (nextTime) {
|
||||||
if (payload == 1) {
|
if (payload == 1) {
|
||||||
node.status({
|
node.status({
|
||||||
fill: "yellow",
|
fill: "yellow",
|
||||||
@ -139,6 +147,22 @@ module.exports = function (RED) {
|
|||||||
text: `off until ${nextTime.goto(selectedTimeZone.name).format("time-24")}`
|
text: `off until ${nextTime.goto(selectedTimeZone.name).format("time-24")}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (payload == 1) {
|
||||||
|
node.status({
|
||||||
|
fill: "yellow",
|
||||||
|
shape: "dot",
|
||||||
|
text: `on`
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
node.status({
|
||||||
|
fill: "blue",
|
||||||
|
shape: "dot",
|
||||||
|
text: `off`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var msg = {};
|
var msg = {};
|
||||||
if (node.mytopic) {
|
if (node.mytopic) {
|
||||||
msg.topic = node.mytopic;
|
msg.topic = node.mytopic;
|
||||||
@ -186,6 +210,16 @@ module.exports = function (RED) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (proceed && aday === 1) {
|
||||||
|
sendPayload(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proceed && aday === 0) {
|
||||||
|
sendPayload(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// if the chronological order is NOW --> ON --> OFF, then now should be OFF
|
// if the chronological order is NOW --> ON --> OFF, then now should be OFF
|
||||||
if (proceed && selectedOffTime.isAfter(selectedOnTime)) {
|
if (proceed && selectedOffTime.isAfter(selectedOnTime)) {
|
||||||
sendPayload(0, selectedOnTime);
|
sendPayload(0, selectedOnTime);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user