freakent / node-red-contrib-sunevents

A node for node-red that generates events based on the position of the Sun at the appropriate time of day.
Apache License 2.0
15 stars 14 forks source link

Offsets #7

Closed Wordna1 closed 4 years ago

Wordna1 commented 4 years ago

I am trying to trigger a NodeRED flow 3 hours before Nadir which is currently at 00:47. I have successfully offset the longitude by 15 to offset the event an hour later, but I think offsetting in this way to a time before the midnight calculations (ie. 00:47 to 21:47) is causing issues.

It would be helpful if either my longitude workaround actually worked as expected or (better yet) if the node accepted an offset in minutes.

freakent commented 4 years ago

As usual it would be useful to understand what you are trying to achieve, but adjusting longitude doesn’t seem like the right way to go. The way the underlying Suncalc library works is by angles to the sun. Each event output is at a set sun angle. for example, sunrise is at -0.833 radians and nightEnd at -18 radians. Nadir (the darkest moment) is calculated to be 0.5 radians from solarNoon. So the most reliable way to achieve this would be to figure out the correct angle In Radian, give this new event a name and emit it as a custom event. Take a look at Suncalc for more info.

Wordna1 commented 4 years ago

I am trying to turn off my grow light for the 6 darkest hours of the night (hence from 3 hours before Nadir to 3 hours after Nadir). I live far enough north that the night is less than 6 hours long during the summer.

As far as I understand, 3 hours before Nadir doesn't correspond to a specific angle of the sun.

freakent commented 4 years ago

-30 radians is getting me pretty close (see nadir+3 and nadir-3 below) . It depends whether you must have exactly 6hrs. If you must have exactly 6 hrs then this node can not do it. I would rather create another node for that purpose.

[sunevents] Ignoring 2020-03-03T01:18:49+01:00, nadir was Today at 1:18 AM, -21 hours ago [sunevents] Ignoring 2020-03-03T04:31:40+01:00, nadir-3 was Today at 4:31 AM, -18 hours ago [sunevents] Ignoring 2020-03-03T05:55:39+01:00, nightEnd was Today at 5:55 AM, -16 hours ago [sunevents] Ignoring 2020-03-03T06:34:59+01:00, nauticalDawn was Today at 6:34 AM, -16 hours ago [sunevents] Ignoring 2020-03-03T07:13:52+01:00, dawn was Today at 7:13 AM, -15 hours ago [sunevents] Ignoring 2020-03-03T07:47:35+01:00, sunrise was Today at 7:47 AM, -14 hours ago [sunevents] Ignoring 2020-03-03T07:51:05+01:00, sunriseEnd was Today at 7:51 AM, -14 hours ago [sunevents] Ignoring 2020-03-03T07:53:43+01:00, breakfast was Today at 7:53 AM, -14 hours ago [sunevents] Ignoring 2020-03-03T08:33:18+01:00, goldenHourEnd was Today at 8:33 AM, -14 hours ago [sunevents] Ignoring 2020-03-03T13:18:49+01:00, solarNoon was Today at 1:18 PM, -9 hours ago [sunevents] Ignoring 2020-03-03T18:04:21+01:00, goldenHour was Today at 6:04 PM, -4 hours ago [sunevents] Ignoring 2020-03-03T18:43:56+01:00, sundowner was Today at 6:43 PM, -4 hours ago [sunevents] Ignoring 2020-03-03T18:46:34+01:00, sunsetStart was Today at 6:46 PM, -4 hours ago [sunevents] Ignoring 2020-03-03T18:50:04+01:00, sunset was Today at 6:50 PM, -3 hours ago [sunevents] Ignoring 2020-03-03T19:23:46+01:00, dusk was Today at 7:23 PM, -3 hours ago [sunevents] Ignoring 2020-03-03T20:02:40+01:00, nauticalDusk was Today at 8:02 PM, -2 hours ago [sunevents] Ignoring 2020-03-03T20:42:00+01:00, night was Today at 8:42 PM, -2 hours ago [sunevents] Ignoring 2020-03-03T22:05:59+01:00, nadir+3 was Today at 10:05 PM, 0 hours ago