2013-10-19 15:31:42 +02:00
2020-04-03 23:25:35 +02:00
< script type = "text/html" data-template-name = "sunrise" >
2013-10-19 15:31:42 +02:00
< div class = "form-row" >
2014-07-15 11:15:04 +02:00
< label for = "node-input-lat" > < i class = "fa fa-globe" > < / i > Latitude< / label >
2013-10-19 15:31:42 +02:00
< input type = "text" id = "node-input-lat" placeholder = "51.025" >
< / div >
< div class = "form-row" >
2014-07-15 11:15:04 +02:00
< label for = "node-input-lon" > < i class = "fa fa-globe" > < / i > Longitude< / label >
2013-10-19 15:31:42 +02:00
< input type = "text" id = "node-input-lon" placeholder = "-1.4" >
< / div >
< div class = "form-row" >
2014-07-15 11:15:04 +02:00
< label for = "node-input-start" > < i class = "fa fa-clock-o" > < / i > Start< / label >
2013-10-19 15:31:42 +02:00
< select id = "node-input-start" style = 'width:70%' >
2020-04-03 23:25:35 +02:00
< option value = "nightEnd" > Morning astronomical twilight starts< / option >
< option value = "nauticalDawn" > Morning nautical twilight starts< / option >
< option value = "dawn" > Dawn, morning civil twilight starts< / option >
2013-10-19 15:31:42 +02:00
< option value = "sunrise" > Sunrise< / option >
< option value = "sunriseEnd" > Sunrise end< / option >
< option value = "goldenHourEnd" > End of morning golden hour< / option >
< / select >
< / div >
< div class = "form-row" >
2014-07-15 11:15:04 +02:00
< label for = "node-input-end" > < i class = "fa fa-clock-o" > < / i > End< / label >
2013-10-19 15:31:42 +02:00
< select id = "node-input-end" style = 'width:70%' >
< option value = "goldenHour" > Start of evening golden hour< / option >
2020-04-03 23:25:35 +02:00
< option value = "sunsetStart" > Sunset start< / option >
< option value = "sunset" > Sunset, civil twilight starts< / option >
2013-10-19 15:31:42 +02:00
< option value = "dusk" > Dusk, Evening astronomical twilight starts< / option >
< option value = "nauticalDusk" > Evening nautical twilight starts< / option >
< option value = "night" > Dark enough for astronomy< / option >
< / select >
< / div >
2020-04-18 14:55:57 +02:00
< div class = "form-row" >
< label > < i class = "fa fa-arrows-h" > < / i > Offset< / label >
< span style = "margin-right:4px" > start< / span > < input type = "text" id = "node-input-soff" placeholder = "minutes" style = 'width:60px;' > mins
< span style = "margin-left:14px; margin-right:4px" > end< / span > < input type = "text" id = "node-input-eoff" placeholder = "minutes" style = 'width:60px;' > mins
< / div >
2013-10-19 15:31:42 +02:00
< div class = "form-row" >
2014-07-15 11:15:04 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > Name< / label >
2013-10-19 15:31:42 +02:00
< input type = "text" id = "node-input-name" placeholder = "Name" >
< / div >
< / script >
2020-04-03 23:25:35 +02:00
< script type = "text/html" data-help-name = "sunrise" >
2013-10-19 15:31:42 +02:00
< 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 >
2020-04-18 14:55:57 +02:00
< p > The start and end times can be offset by a number of minutes before (minus) or after (plus) the chosen event time.< / p >
2016-02-15 12:12:29 +01:00
< 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.
2013-10-19 16:37:20 +02:00
The second output emits only on the transition between night to day (< i > -> 1< / i > ) or day to night (< i > -> 0< / i > ).< / p >
2020-04-18 14:55:57 +02:00
< 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 >
2013-10-19 15:31:42 +02:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('sunrise',{
2019-10-20 23:43:32 +02:00
category: 'time',
2013-10-19 15:31:42 +02:00
color:"#ffcc66",
defaults: {
name: {value:""},
lat: {value:"", required:true, validate:RED.validators.number()},
lon: {value:"", required:true, validate:RED.validators.number()},
2014-09-07 22:56:49 +02:00
start: {value:"sunrise", required:true},
2020-04-18 14:55:57 +02:00
end: {value:"sunset", required:true},
soff: {value:0, validate:RED.validators.number()},
eoff: {value:0, validate:RED.validators.number()},
2013-10-19 15:31:42 +02:00
},
inputs:0,
outputs:2,
2017-01-29 18:47:06 +01:00
outputLabels: ["once per minute","only on change"],
2013-10-19 15:31:42 +02:00
icon: "sun.png",
label: function() {
return this.name||"Sun rise/set";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
2014-09-07 22:56:49 +02:00
},
oneditprepare: function() {
if (($("#node-input-lat").val() === "") & & ($("#node-input-lon").val() === "")) {
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
$("#node-input-lat").val(Number(position.coords.latitude.toFixed(5)));
$("#node-input-lon").val(Number(position.coords.longitude.toFixed(5)));
});
}
}
2020-04-18 14:55:57 +02:00
if ($("#node-input-soff").val() === "") { $("#node-input-soff").val(0) }
if ($("#node-input-eoff").val() === "") { $("#node-input-eoff").val(0) }
$("#node-input-soff").spinner({});
$("#node-input-eoff").spinner({});
2013-10-19 15:31:42 +02:00
}
});
< / script >