# Inject node: Sunrise/Sunset Feature request

**URL:** <https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634>\
**Category:** Feature Requests\
**Created:** [1 June 2020 16:15 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634 "2020-06-01T16:15:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [1 June 2020 16:15 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/1 "2020-06-01T16:15:20Z")

</div>

The inject node is capable of repeating at specific intervals based on hours (e.g., 00:00, etc.), but there is no support for suncalc type events.

For example:

> **[node-red-contrib-schedex](https://www.npmjs.com/package/node-red-contrib-schedex)**
>
> Scheduler for node-red which allows you to enter on/off times as 24hr clock (e.g. 01:10) or suncalc events (e.g. goldenHour). It also allows you to offset times and randomise the time within the offset.

This seems to be a simple addition -- only latitude, longitude would be needed, and then a dropdown of supported suncalc events if chosen.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 June 2020 16:41 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/2 "2020-06-01T16:41:12Z")

</div>

Its not as simple as you might imagine. And anyhow, there are several contrib nodes that do this. Search flows library.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 June 2020 16:41 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/3 "2020-06-01T16:41:28Z")

</div>

there is node-red-node-suncalc that can do that for you - as well as many others as you have found.

---

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [1 June 2020 16:51 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/4 "2020-06-01T16:51:19Z")

</div>

Thanks @Steve-Mcl and @dceejay ... just wondering why it couldn't be part of the default `Inject` node? I know there are cases where more advanced handling is needed, but I think having these for a simple Inject could be extremely useful. It would (of course) rely on the suncalc library. I could work on a PR for it if there is interest.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [1 June 2020 16:57 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/5 "2020-06-01T16:57:18Z")

</div>

> [@dxdc](#):
>
> I know there are cases where more advanced handling is needed, but I think having these for a simple Inject could be extremely useful.

That always then leads to the inevitable request to add just one more of those features.

We have to strike a balance with the amount of functionality we pile into any one node. Whilst I'm not necessarily saying this applies here, if a node has too many features it becomes harder to use because there are so many options for a user to wade through.

This is why nodes like cronplus, schedex, suncalc, bigtimer have all cropped up. They all are variations on the same theme, each offering a slightly different opinion on how it should be done.

We know from those nodes that adding suncalc-like timings introduces a whole host of further inevitable options. I'd prefer purpose-built nodes for those cases rather than a half-hearted feature in the core set.

---

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [1 June 2020 17:10 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/6 "2020-06-01T17:10:33Z")

</div>

> We have to strike a balance with the amount of functionality we pile into any one node. Whilst I'm not necessarily saying this applies here, if a node has too many features it becomes harder to use because there are so many options for a user to wade through.

I get it. I'm not sure in this case it would be too much though? Just to show you what I was thinking:

- Additional "sun phase" option in dropdown
- Options of: Lat, Lon, and Offset + dropdown list with sun event (sunrise, sunset, etc.)

 ![Screen Shot 2020-06-01 at 12.05.44 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1e41fc4d835ed977d230b8d9ddddceba83504865.png)

Understand though if you'd rather keep it unconnected, I just feel there are a lot of simplistic cases where a user only wants an event to fire at a specific time.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 June 2020 17:25 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/7 "2020-06-01T17:25:59Z")

</div>

> [@dxdc](#):
>
> are a lot of simplistic cases

and the suncalc node handles them quite simply 🙂

---

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [1 June 2020 17:32 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/8 "2020-06-01T17:32:07Z")

</div>

@dceejay 🙂 well, maybe it's my misunderstanding of the suncalc node then, but here was my confusion with it:

- It forces the user to select both a "start" and "end". It's unclear how to use this as a trigger for a single, daily event (e.g., each "sunrise" or each "sunset").

- The options are built so that the early (sunrise, etc.) events are in the start box, and the late (sunset, etc.) events are in the end box. What if a user wants exactly the opposite behavior... or they want it triggered from the beginning of sunset to the end of sunset?

- There is only a single "offset" selection, except there are 2 choices (start/end). Does the offset apply to both? How could independent offsets be chosen?

- There are no checkboxes for which weekday to use (not a big deal)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 June 2020 18:00 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/9 "2020-06-01T18:00:44Z")

</div>

Hi -  
It sends 1 when at the start time and 0 when you set end. so if you only want getting light look for the 1 - if getting dark just look for the 0. Likewise it's up to you to interpret whether 1 means active or inactive ie the opposite behaviour. A following change node can change the 1 to something more meaningful etc.  
For beginning of sunset to end of sunset - indeed it wouldn't - but neither would a single inject node. In both cases you would need two nodes.

The offsets apply to each transition - you can move the 0/1 and 1/0 transition either before the real time or after. Would a simple inject node offer this... we now have to add lat, lon, offset ... getting more options by the minute...

No checkboxes... well we assume the sun rises everyday 🙂

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 June 2020 18:03 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/10 "2020-06-01T18:03:18Z")

</div>

Meanwhile this node has just been released... [[ANNOUNCE] Ultimate (Swiss-Army-Knife) Node-Red Timer based flow control](https://discourse.nodered.org/t/announce-ultimate-swiss-army-knife-node-red-timer-based-flow-control/27560)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 June 2020 18:17 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/11 "2020-06-01T18:17:14Z")

</div>

@dxdc having been working on adding solar events to cron-plus over the course of a couple of months I can say - "adding the UI options" are easy however handling everything else under the hood is far from straight foward.

For example, "at specific sun phase" implies 1 event (like sunrise or sunset) - then before you know it there is a request for "at sunrise and sunset" then the user wants "at sunrise and sunset offset by 30 mins".

Then beyond that, you're asked to output things like `isDay` or `isNight` - sounds easy? Until your user enters coordinates with a [low latitude](https://www.suncalc.org/#/-76.6392,15.4687,3/2020.05.08/07:02/1/3) (where there is no "day" period) or [high latitude](https://www.suncalc.org/#/79.2372,13.0078,5/2020.05.08/12:28/1/3) (where there is no "night" period. Do we scan backwards and forwards to determine state & next solar occurrence?

Then there is the issue of accuracy - most of the libs are approximations (and they all give slightly differing results across the whole gamut of astrological/nautical/civil/dawn/dusk) and some use different sun angles for golden hour, sunrise end etc. I know, i've tried about 7 of the more popular ones - verifying with [suncalc.org](http://suncalc.org), [timeanddate.com](http://timeanddate.com) and [esrl.noaa.gov/gmd/grad/solcalc/](http://esrl.noaa.gov/gmd/grad/solcalc/)

There is more more to this conundrum but I've said enough 😓

This is the nightmare i am working through now. As it stands, I have worked though all of the above (plus more) & I am now (2 months in) _ **nearly** _ happy with it.

And as Nick and Dave have alluded to, there are many choices & soon - another (cron-plus) will have too (once I've worked out all the kinks)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cdde9d4f806f07af245b7db30233c437afc7ba3f.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/89820c1ae38a46202617bc23d878673e0ad8bb15.png)

And lastly, when cron-plus has one entry, you get `inject` like functionality...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/9/e9a505f9c566c0cbf7be1949edd2f6bc91f3f16f.png)

its debug output for a solar event

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/ede8275c2c4f895791f6a16b411e6d15fd9bfc78.png)

---

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [1 June 2020 18:25 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/12 "2020-06-01T18:25:55Z")

</div>

> [@dceejay](#):
>
> The offsets apply to each transition - you can move the 0/1 and 1/0 transition either before the real time or after. Would a simple inject node offer this... we now have to add lat, lon, offset ... getting more options by the minute...

Thanks, was thinking about this approach too. I guess it makes sense, but if I only want a trigger at sunset + 4 hours it seems a little confusing that there is _also_ a trigger at sunrise + 4 hours.

> but neither would a single inject node

You're right, but I find the single inject node more intuitive. I don't need so many triggers and it seems unintuitive to use an arbitrary value for `start` (like sunrise) if it's not being used. It also makes me wonder what exactly happens if a flow is re-deployed in the middle of the day. I think it can have a lot of unintended side effects from this kind of dual start/end behavior.

> Meanwhile this node has just been released

I've looked at this node before, will give it another go 🙂

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 June 2020 18:30 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/13 "2020-06-01T18:30:03Z")

</div>

> [@dxdc](#):
>
> It also makes me wonder what exactly happens if a flow is re-deployed in the middle of the day.

that one is a doosey.

In cron-plus, i have to scan back through solar events until I determine if the users offset is a future event.

As i attempted to allude to above, there is a whole raft of considerations 😭

I am not too far of finishing cron-plus updates - perhaps 1 week.

The benefits I see over other nodes are - the multiple schedules, true timezone support and 100% fully dynamic nature of the node (everything can be automated via msgs)

---

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [1 June 2020 18:35 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/14 "2020-06-01T18:35:58Z")

</div>

> [@Steve-Mcl](#):
>
> having been working on adding solar events to cron-plus over the course of a couple of months I can say - "adding the UI options" are easy however handling everything else under the hood is far from straight foward.

I'm quite familiar with some of these challenges. I've run into a number of problems with plugins with the logic of `sunset + 4 hours` where this amounts to the following day because sunset is after 8pm - and causes problems upon defining the next repeat interval.

As far as the accuracy, sure, it's confusing. I've read through a lot of that code myself for different reasons. A lot of it has to do with the choice of things like the radius of the earth (for which it seems there is no exact agreement??). We need a consensus between astronomers to gain some agreement on their own calculations 🙂 And, what surprised me more is that reading through the NOAA code, which I had expected would be high quality, was anything but. There's also a lot of rounding for simplicity (e.g., round to the nearest minute) which can produce different results.

The definition of the angles is another issue, but I feel like that is a _little_ easier to deal with since it's just a number at the end of the day - so it's a definitional disagreement as opposed to anything else.

> And lastly, when cron-plus has one entry, you get `inject` like functionality...

I presume it's only injecting during the defined solar events? If so, keep me posted once `cron-plus` is updated, would love to test it.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 June 2020 18:38 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/15 "2020-06-01T18:38:17Z")

</div>

> [@dxdc](#):
>
> what exactly happens if a flow is re-deployed in the middle of the day.

Whereas for suncalc it is "easy" 🙂 - the node has two outputs... one that only has the transitions when they occur - so if you've missed it, you have to wait for the next one... and one output that repeats the current state every minute - so if you restart in the middle of the night it will then turn the lights back on (or whatever)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 June 2020 18:40 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/16 "2020-06-01T18:40:58Z")

</div>

I'm in a Magnus Magnusson phase at the minute Dave. I've started so I'll finish (though at times I wish I hadn't)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 June 2020 18:45 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/17 "2020-06-01T18:45:46Z")

</div>

I did try to warn you... but hey...

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 June 2020 18:46 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/18 "2020-06-01T18:46:12Z")

</div>

> [@dxdc](#):
>
> I presume it's only injecting during the defined solar events

Yes and no...

- If you manually inject, it fires but you can use the output status to determine if it's a manual injection and the solar state of "now" is provided along with the time of the next event(s)

The reason for this is so a user can request through a msg for twilight/isDay/isNight etc at any point in time for any location in the world - 100% dynamic without a 2nd output firing every minute for example.

- When an actual solar event occurs, output only occurs for the selected solar events

Hopefully that makes sense?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 June 2020 18:46 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/19 "2020-06-01T18:46:33Z")

</div>

Yes. Yes you did. 😭

---

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [1 June 2020 21:45 UTC](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634/20 "2020-06-01T21:45:18Z")

</div>

> [@Steve-Mcl](#):
>
> Hopefully that makes sense?

This sounds perfect!

[Next page](https://discourse.nodered.org/t/inject-node-sunrise-sunset-feature-request/27634.md?page=2)
