Lighthouse-Automation / node-red-contrib-later

A node red node for triggering using later.js
Other
6 stars 2 forks source link

Dawn/Dusk #5

Open TotallyInformation opened 8 years ago

TotallyInformation commented 8 years ago

Hi, would it be possible to add custom time periods to the later schedule that triggered on dawn and dusk?

d-o commented 8 years ago

I had a look at the later implementation and I don't think that that would be that easy. Later's use is to produce deterministic schedules from input, the same input will (should) give the same output. Also the underlying library, surprisingly, doesn't have any concept of 'date/time', it is really just a parser. Adding dusk/dawn would break that determinism, and require quite a few changes to low levels that I am not that keen to touch. If you could think of an easy way to add that support I would have a closer look, but I can't see an obvious point to plug it in.

TotallyInformation commented 8 years ago

Thanks, I did post into their issues list as you may have seen, your comments clarify theirs somewhat. It is a shame as it would enable this library to replace several others and I much prefer the approach provided here.

The only other approach I can think of would be to use the custom schedule feature to build something that looks for an external input. Then to use a simple sunrise/set function to work out the appropriate time. Not sure if that would work though.

d-o commented 8 years ago

I did find this library https://github.com/mourner/suncalc

One approach I thought of might be to parse the schedule string before passing it to the later parser and remove 'dawn' and 'dusk' and replace them with (say) 00:01 and 23:59. After the later schedule has parsed these into occurrences use suncalc with the date object(s) from later and user supplied lat and long to replace the time in the date object.

Does seem a little complicated, but avoids touching the later.js library and might work. There is also the issue of the time to do it :)

TotallyInformation commented 8 years ago

Sounds like it could be workable and was kind of in line with what I'd thought about. Sorry my coding skills and time aren't quite up to helping but I'd be more than happy to help test and document if needed.

Thanks for following up.