mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
suncalc - add moon position and phases, and sun position - bump to 1.0
This commit is contained in:
parent
055be01332
commit
89996016de
@ -48,7 +48,8 @@
|
||||
<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>It also outputs <code>msg.start</code>, <code>msg.end</code> and <code>msg.now</code> which are todays start and end times, with offsets applied, in ISO format, and the current ISO time.</p>
|
||||
<p><code>msg.topic</code> is set to <i>sun</i>, and <code>msg.moon</code> to the fraction of the moon between 0 and 1.</p>
|
||||
<p><code>msg.sun</code> is an object containing the azimuth and altitude, in degrees, of the current sun position.</p>
|
||||
<p><code>msg.moon</code> is an object containing <thead></thead> position, phase, illumination and icon of the moon.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
@ -27,8 +27,26 @@ module.exports = function(RED) {
|
||||
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, start:s1, end:s2, now:now};
|
||||
var moon = SunCalc.getMoonIllumination(now);
|
||||
var moon2 = SunCalc.getMoonPosition(now, node.lat, node.lon);
|
||||
moon = Object.assign(moon, moon2);
|
||||
moon.altitude = moon.altitude * 180 / Math.PI;
|
||||
moon.azimuth = moon.azimuth * 180 / Math.PI;
|
||||
moon.parallacticAngle = moon.parallacticAngle * 180 /Math.PI;
|
||||
moon.icon = "new";
|
||||
if (moon.phase > 0.02) { moon.icon = "wax-cres"}
|
||||
if (moon.phase > 0.22) { moon.icon = "first-quart"}
|
||||
if (moon.phase > 0.28) { moon.icon = "wax-gibb"}
|
||||
if (moon.phase > 0.48) { moon.icon = "full"}
|
||||
if (moon.phase > 0.52) { moon.icon = "wan-gibb"}
|
||||
if (moon.phase > 0.72) { moon.icon = "third-quart"}
|
||||
if (moon.phase > 0.78) { moon.icon = "wan-cres"}
|
||||
if (moon.phase > 0.98) { moon.icon = "new"}
|
||||
moon.icon = "wi-moon-" + moon.icon;
|
||||
var sun = SunCalc.getPosition(now, node.lat, node.lon);
|
||||
sun.altitude = sun.altitude * 180 / Math.PI;
|
||||
sun.azimuth = sun.azimuth * 180 / Math.PI;
|
||||
var msg = {payload:0, topic:"sun", sun: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"}); }
|
||||
|
@ -10,6 +10,8 @@ Either use the `Node-RED Menu - Manage Palette - Install`, or run the following
|
||||
|
||||
npm install node-red-node-suncalc
|
||||
|
||||
**Breaking Change** - in version 1.0 the `msg.moon` property is now an object not a number - containing a lot more information.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
@ -27,5 +29,4 @@ The second output emits only on the transition between night to day (<i>-> 1</i>
|
||||
|
||||
It also outputs <code>msg.start</code>, <code>msg.end</code> and <code>msg.now</code> which are todays start and end times, with offsets applied, in ISO format, and the current ISO time.
|
||||
|
||||
The `msg.topic` is set 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>
|
||||
`msg.sun` is an object containing the azimuth and altitude, in degrees, of the current sun position. `msg.moon` is an object containing its position, phase, illumination and icon.
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-suncalc",
|
||||
"version" : "0.2.0",
|
||||
"version" : "1.0.0",
|
||||
"description" : "A Node-RED node to provide a signal at sunrise and sunset",
|
||||
"dependencies" : {
|
||||
"suncalc" : "^1.8.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user