suncalc msg at startup (#1083)

Thanks Bart.
This commit is contained in:
bartbutenaers 2024-09-24 22:14:50 +02:00 committed by GitHub
parent 55011335ab
commit 23e6147e72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 30 deletions

View File

@ -39,6 +39,11 @@
<span style="margin-right:4px" data-i18n="sunrise.start"></span> <input type="text" id="node-input-soff" placeholder="minutes" style='width:60px;' > <span data-i18n="sunrise.mins"></span>
<span style="margin-left:14px; margin-right:4px" data-i18n="sunrise.end"></span> <input type="text" id="node-input-eoff" placeholder="minutes" style='width:60px;'><span data-i18n="sunrise.mins"></span>
</div>
<div class="form-row">
<label for="node-input-sendAtStartup"><i class="fa fa-refresh"></i><span data-i18n="sunrise.label.startup"></span></label>
<input type="checkbox" id="node-input-sendAtStartup" style='width:auto ;border:none; vertical-align:baseline;'>
<span for="node-input-sendAtStartup" data-i18n="sunrise.sendAtStartup"></span>
</div>
</script>
<script type="text/javascript">
@ -53,6 +58,7 @@
end: {value:"sunset", required:true},
soff: {value:0, validate:RED.validators.number()},
eoff: {value:0, validate:RED.validators.number()},
sendAtStartup: {value:false}
},
inputs:0,
outputs:2,

View File

@ -11,6 +11,7 @@ module.exports = function(RED) {
this.end = n.end;
this.soff = (n.soff || 0) * 60000; // minutes
this.eoff = (n.eoff || 0) * 60000; // minutes
this.sendAtStartup = n.sendAtStartup;
var node = this;
var oldval = null;
@ -48,7 +49,7 @@ module.exports = function(RED) {
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 (oldval == null && !node.sendAtStartup) { oldval = msg.payload; }
if (msg.payload == 1) { node.status({fill:"yellow",shape:"dot",text:"sunrise.dayState"}); }
else { node.status({fill:"blue",shape:"dot",text:"sunrise.nightState"}); }
if (msg.payload != oldval) {

View File

@ -4,7 +4,8 @@
<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 start and end times can be offset by a number of minutes before (minus) or after (plus) the chosen event time.</p>
<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>
The second output emits only on the transition between night to day (<i>-> 1</i>) or day to night (<i>-> 0</i>).
When the initial value at startup is required to be sent, that value will be emitted at the second output.</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.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>

View File

@ -1,32 +1,34 @@
{
"sunrise": {
"label": {
"latitude": " Latitude",
"longitude": " Longitude",
"sunrise": {
"label": {
"latitude": " Latitude",
"longitude": " Longitude",
"start": " Start",
"end": " End",
"offset": " Offset",
"name": " Name"
"end": " End",
"offset": " Offset",
"name": " Name",
"startup": " Startup"
},
"nightEnd": "Morning astronomical twilight starts",
"nauticalDawn": "Morning nautical twilight starts",
"dawn": "Dawn, morning civil twilight starts",
"sunrise": "Sunrise",
"sunriseEnd": "Sunrise end",
"goldenHourEnd": "End of morning golden hour",
"goldenHour": "Start of evening golden hour",
"sunsetStart": "Sunset start",
"sunset": "Sunset, civil twilight starts",
"dusk": "Dusk, Evening nautical twilight starts",
"nauticalDusk": "Evening astronomical twilight starts",
"night": "Dark enough for astronomy",
"start": " start",
"mins": " mins",
"end": " end",
"dayState": "day",
"nightState": "night",
"onePerMin": "once per minute",
"onse": "only on change",
"sunName": "Sun rise/set"
}
"nightEnd": "Morning astronomical twilight starts",
"nauticalDawn": "Morning nautical twilight starts",
"dawn": "Dawn, morning civil twilight starts",
"sunrise": "Sunrise",
"sunriseEnd": "Sunrise end",
"goldenHourEnd": "End of morning golden hour",
"goldenHour": "Start of evening golden hour",
"sunsetStart": "Sunset start",
"sunset": "Sunset, civil twilight starts",
"dusk": "Dusk, Evening nautical twilight starts",
"nauticalDusk": "Evening astronomical twilight starts",
"night": "Dark enough for astronomy",
"start": " start",
"mins": " mins",
"end": " end",
"dayState": "day",
"nightState": "night",
"onePerMin": "once per minute",
"onse": "only on change",
"sunName": "Sun rise/set",
"sendAtStartup": "Send the current value at startup"
}
}