@@ -39,9 +44,11 @@
diff --git a/time/suncalc/79-suncalc.js b/time/suncalc/79-suncalc.js
index 6ce278b6..905ff846 100644
--- a/time/suncalc/79-suncalc.js
+++ b/time/suncalc/79-suncalc.js
@@ -9,6 +9,8 @@ module.exports = function(RED) {
this.lon = n.lon;
this.start = n.start;
this.end = n.end;
+ this.soff = (n.soff || 0) * 60000; // minutes
+ this.eoff = (n.eoff || 0) * 60000; // minutes
var node = this;
var oldval = null;
@@ -19,12 +21,14 @@ module.exports = function(RED) {
var nowMillis = Date.UTC(now.getUTCFullYear(),now.getUTCMonth(),now.getUTCDate(),now.getUTCHours(),now.getUTCMinutes());
var startMillis = Date.UTC(times[node.start].getUTCFullYear(),times[node.start].getUTCMonth(),times[node.start].getUTCDate(),times[node.start].getUTCHours(),times[node.start].getUTCMinutes());
var endMillis = Date.UTC(times[node.end].getUTCFullYear(),times[node.end].getUTCMonth(),times[node.end].getUTCDate(),times[node.end].getUTCHours(),times[node.end].getUTCMinutes());
- var e1 = nowMillis - startMillis;
- var e2 = nowMillis - endMillis;
+ var e1 = nowMillis - startMillis - node.soff;
+ var e2 = nowMillis - endMillis - node.eoff;
+ var s1 = new Date(startMillis + node.soff);
+ var s2 = new Date(endMillis + node.eoff);
if (isNaN(e1)) { e1 = 1; }
if (isNaN(e2)) { e2 = -1; }
var moon = parseInt(SunCalc.getMoonIllumination(now).fraction * 100 + 0.5) / 100;
- var msg = {payload:0, topic:"sun", moon:moon};
+ var msg = {payload:0, topic:"sun", moon:moon, start:s1, end:s2, now:now};
if ((e1 > 0) & (e2 < 0)) { msg.payload = 1; }
if (oldval == null) { oldval = msg.payload; }
if (msg.payload == 1) { node.status({fill:"yellow",shape:"dot",text:"day"}); }
diff --git a/time/suncalc/README.md b/time/suncalc/README.md
index 51de9d25..dac87938 100644
--- a/time/suncalc/README.md
+++ b/time/suncalc/README.md
@@ -6,11 +6,10 @@ A Node-RED node to provide a sign
Install
-------
-Run the following command in your Node-RED user directory - typically `~/.node-red`
+Either use the `Node-RED Menu - Manage Palette - Install`, or run the following command in your Node-RED user directory - typically `~/.node-red`
npm install node-red-node-suncalc
-
Usage
-----
@@ -19,10 +18,14 @@ Uses the suncalc npm to generate an output at sunrise and sunset based on a spec
Several choices of definition of sunrise and sunset are available, see the
suncalc module for details.
+The start and end times can be offset by a number of minutes before (minus) or after (plus) the chosen event time.
+
The node provide two outputs. The first output emits a `msg.payload` of 1 or 0 every minute
depending if day-time (1) or night-time (0).
The second output emits only on the transition between night to day (-> 1) or day to night (-> 0).
-It also sets the `msg.topic` to sun and `msg.moon` to the fraction of the moon currently visible
+It also outputs msg.start, msg.end and msg.now which are todays start and end times, with offsets applied, in ISO format, and the current ISO time.
+
+The `msg.topic` is set to sun, and `msg.moon` to the fraction of the moon currently visible
(a value between 0 for no moon and 1 for full moon).
diff --git a/time/suncalc/package.json b/time/suncalc/package.json
index ecb27bcf..cf675cac 100644
--- a/time/suncalc/package.json
+++ b/time/suncalc/package.json
@@ -1,6 +1,6 @@
{
"name" : "node-red-node-suncalc",
- "version" : "0.1.0",
+ "version" : "0.2.0",
"description" : "A Node-RED node to provide a signal at sunrise and sunset",
"dependencies" : {
"suncalc" : "^1.8.0"