correct output for timeswitch

(simple typo)
Also tidied up info etc…
push to close #176
This commit is contained in:
Dave Conway-Jones 2016-02-15 11:12:29 +00:00
parent 952a794db5
commit b33571b240
8 changed files with 50 additions and 47 deletions

View File

@ -54,9 +54,9 @@
<script type="text/x-red" data-help-name="sunrise">
<p>Uses the suncalc module to generate an output at sunrise and sunset based on a specified location.</p>
<p>Several choices of definition of sunrise and sunset are available, see the <i><a href = "https://github.com/mourner/suncalc" target="_new">suncalc</a></i> module for details.</p>
<p>The first output emits a <b>msg.payload</b> of <i>1</i> or <i>0</i> every minute depending if in between selected times or not.
<p>The first output emits a <code>msg.payload</code> of <i>1</i> or <i>0</i> every minute depending if in between selected times or not.
The second output emits only on the transition between night to day (<i>-> 1</i>) or day to night (<i>-> 0</i>).</p>
<p>Also sets <b>msg.topic</b> to <i>sun</i> and <b>msg.moon</b> to the fraction of the moon between 0 and 1.</p>
<p>Also sets <code>msg.topic</code> to <i>sun</i> and <code>msg.moon</code> to the fraction of the moon between 0 and 1.</p>
</script>
<script type="text/javascript">

View File

@ -36,15 +36,15 @@ module.exports = function(RED) {
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 moon = parseInt(SunCalc.getMoonIllumination(now).fraction*100+0.5)/100;
var msg = { payload:0, topic:"sun", moon:moon };
var moon = parseInt(SunCalc.getMoonIllumination(now).fraction * 100 + 0.5) / 100;
var msg = {payload:0, topic:"sun", moon:moon};
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"}); }
else { node.status({fill:"blue",shape:"dot",text:"night"}); }
if (msg.payload != oldval) {
oldval = msg.payload;
node.send( [msg,msg] );
node.send([msg,msg]);
}
else { node.send(msg); }
}, 60000);
@ -54,4 +54,4 @@ module.exports = function(RED) {
});
}
RED.nodes.registerType("sunrise",SunNode);
}
};

View File

@ -16,10 +16,13 @@ Usage
Uses the suncalc npm to generate an output at sunrise and sunset based on a specified location.
Several choices of definition of sunrise and sunset are available, see the <i><a href = "https://github.com/mourner/suncalc" target="_new">suncalc</a></i> module for details.
Several choices of definition of sunrise and sunset are available, see the
<i><a href = "https://github.com/mourner/suncalc" target="_new">suncalc</a></i> module for details.
The node provide two outputs. The first output emits a <b>msg.payload</b> of <i>1</i> or <i>0</i> every minute depending if day-time (1) or night-time (0).
The node provide two outputs. The first output emits a `msg.payload` of <i>1</i> or <i>0</i> every minute
depending if day-time (1) or night-time (0).
The second output emits only on the transition between night to day (<i>-> 1</i>) or day to night (<i>-> 0</i>).
It also sets the <b>msg.topic</b> to <i>sun</i> and <b>msg.moon</b> to the fraction of the moon currently visible (a value between 0 for no moon and 1 for full moon).</p>
It also sets the `msg.topic` to <i>sun</i> and `msg.moon` to the fraction of the moon currently visible
(a value between 0 for no moon and 1 for full moon).</p>

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-suncalc",
"version" : "0.0.6",
"version" : "0.0.7",
"description" : "A Node-RED node to provide a signal at sunrise and sunset",
"dependencies" : {
"suncalc" : "1.6.*"

View File

@ -15,19 +15,19 @@ Usually this is `~/.node-red`
Usage
-----
Sets **msg.payload** to *1* during on times, and *0* during off times.
Sets `msg.payload` to *1* during on times, and *0* during off times.
Also uses the suncalc module to allow use of dawn and dusk.
Dawn and dusk times can be offset both positively (+ve) for minutes after dawn
or dusk, and negatively (-ve) for minutes before dawn or dusk..
The output emits a **msg.payload** of *1* or *0* every minute depending on
The output emits a `msg.payload` of *1* or *0* every minute depending on
whether the current time is during the selected on time or off time.
If you just need the transitions from 0->1 or 1->0 then follow this node with an RBE node.
You may also optionally specify a **msg.topic** if required.
You may also optionally specify a `msg.topic` if required.
**Note**: For a more complex version with more built-in options see Pete Scargill's
[node-red-contrib-bigtimer](http://flows.nodered.org/node/node-red-contrib-bigtimer) node.

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-timeswitch",
"version" : "0.0.2",
"version" : "0.0.3",
"description" : "A Node-RED node to provide a simple timeswitch to schedule daily on/off events.",
"dependencies" : {
"suncalc": "1.6.0"

View File

@ -285,14 +285,14 @@
<script type="text/x-red" data-help-name="timeswitch">
<p>Timeswitch node to schedule daily on/off events.</p>
<p>Sets <b>msg.payload</b> to 1 at on time, and 0 at off time.</p>
<p>Sets <code>msg.payload</code> to 1 at on time, and 0 at off time.</p>
<p>Also allows the use of dawn and dusk.</p>
<p>Dawn and dusk times can be offset both positively (+ve) for minutes later
or negatively (-ve) for minutes earlier.</p>
<p>The output emits a <b>msg.payload</b> of <i>1</i> or <i>0</i> every minute depending on
<p>The output emits a <code>msg.payload</code> of <i>1</i> or <i>0</i> every minute depending on
whether the current time is during the selected on time or off time.</p>
<p>If you just need the transitions from 0->1 or 1->0 then follow this node with an RBE node.</p>
<p>You may also optionally specify a <b>msg.topic</b> if required.</p>
<p>You may also optionally specify a <code>msg.topic</code> if required.</p>
</script>
<script type="text/javascript">

View File

@ -72,43 +72,43 @@ module.exports = function(RED) {
if ((starttime >= 5000) || (endtime == 5000) || (endtime == 6000)) {
var times = SunCalc.getTimes(now, node.lat, node.lon);
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 endMillis = Date.UTC(times[node.end].getUTCFullYear(), times[node.end].getUTCMonth(), times[node.end].getUTCDate(), times[node.end].getUTCHours(), times[node.end].getUTCMinutes());
startMillis += nowoff;
endMillis += nowoff;
endMillis += nowoff;
var dawn = ((startMillis - midnightMillis) / 60000) + Number(node.dawnoff);
var dusk = ((endMillis - midnightMillis) / 60000) + Number(node.duskoff);
var dusk = ((endMillis - midnightMillis) / 60000) + Number(node.duskoff);
if (starttime == 5000) { starttime = dawn; }
if (starttime == 6000) { starttime = dusk; }
if (endtime == 5000) { endtime = dawn; }
if (endtime == 6000) { endtime = dusk; }
if (endtime == 5000) { endtime = dawn; }
if (endtime == 6000) { endtime = dusk; }
if (RED.settings.verbose) { node.log("Dawn " + parseInt(dawn / 60) + ":" + dawn % 60 + " - Dusk " + parseInt(dusk / 60) + ":" + dusk % 60); }
}
var proceed = 0;
switch (now.getDay()) {
case 0 : { if (node.sun) { proceed++ } break; }
case 1 : { if (node.mon) { proceed++ } break; }
case 2 : { if (node.tue) { proceed++ } break; }
case 3 : { if (node.wed) { proceed++ } break; }
case 4 : { if (node.thu) { proceed++ } break; }
case 5 : { if (node.fri) { proceed++ } break; }
case 6 : { if (node.sat) { proceed++ } break; }
case 0 : { if (node.sun) { proceed++; } break; }
case 1 : { if (node.mon) { proceed++; } break; }
case 2 : { if (node.tue) { proceed++; } break; }
case 3 : { if (node.wed) { proceed++; } break; }
case 4 : { if (node.thu) { proceed++; } break; }
case 5 : { if (node.fri) { proceed++; } break; }
case 6 : { if (node.sat) { proceed++; } break; }
}
if (proceed) {
switch (now.getMonth()) {
case 0 : { if (node.jan) { proceed++ } break; }
case 1 : { if (node.feb) { proceed++ } break; }
case 2 : { if (node.mar) { proceed++ } break; }
case 3 : { if (node.apr) { proceed++ } break; }
case 4 : { if (node.may) { proceed++ } break; }
case 5 : { if (node.jun) { proceed++ } break; }
case 6 : { if (node.jul) { proceed++ } break; }
case 7 : { if (node.aug) { proceed++ } break; }
case 8 : { if (node.sep) { proceed++ } break; }
case 9 : { if (node.oct) { proceed++ } break; }
case 10: { if (node.nov) { proceed++ } break; }
case 11: { if (node.dec) { proceed++ } break; }
case 0 : { if (node.jan) { proceed++; } break; }
case 1 : { if (node.feb) { proceed++; } break; }
case 2 : { if (node.mar) { proceed++; } break; }
case 3 : { if (node.apr) { proceed++; } break; }
case 4 : { if (node.may) { proceed++; } break; }
case 5 : { if (node.jun) { proceed++; } break; }
case 6 : { if (node.jul) { proceed++; } break; }
case 7 : { if (node.aug) { proceed++; } break; }
case 8 : { if (node.sep) { proceed++; } break; }
case 9 : { if (node.oct) { proceed++; } break; }
case 10: { if (node.nov) { proceed++; } break; }
case 11: { if (node.dec) { proceed++; } break; }
}
}
@ -134,11 +134,11 @@ module.exports = function(RED) {
node.status({fill:"yellow", shape:"dot", text:"on until " + parseInt(newendtime / 60) + ":" + ("0" + newendtime % 60).substr(-2)});
}
//else { node.status({fill:"blue",shape:"dot",text:"off"}); }
else { node.status({fill:"blue", shape:"dot", text:"off until " + parseInt(starttime / 60) + ":" + ("0" + starttime % 60).substr(-2)}); }
else { node.status({fill:"blue", shape:"dot", text:"off until " + parseInt(starttime / 60) + ":" + ("0" + starttime % 60).substr(-2)}); }
var msg = {};
if (node.mytopic) { msg.topic = node.mytopic; }
msg.payload = (process>=2) ? 1 : 0;
msg.payload = (proceed >= 2) ? 1 : 0;
node.send(msg);
});
@ -161,15 +161,15 @@ module.exports = function(RED) {
if (node != null) {
try {
node.emit("input", {payload:"reset"});
res.send(200);
res.sendStatus(200);
} catch (err) {
res.send(500);
res.sendStatus(500);
node.error("Inject failed:" + err);
}
} else {
res.send(404);
res.sendStatus(404);
}
});
RED.nodes.registerType("timeswitch", TimeswitchNode);
}
};