# Stopping Sequence an hour before sunset

**URL:** <https://discourse.nodered.org/t/stopping-sequence-an-hour-before-sunset/17911>\
**Category:** General\
**Created:** [13 November 2019 19:50 UTC](https://discourse.nodered.org/t/stopping-sequence-an-hour-before-sunset/17911 "2019-11-13T19:50:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rlongfield](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rlongfield/32/14264_2.png) [@rlongfield](https://discourse.nodered.org/u/rlongfield)\
**Post date:** [13 November 2019 19:50 UTC](https://discourse.nodered.org/t/stopping-sequence-an-hour-before-sunset/17911/1 "2019-11-13T19:50:15Z")

</div>

I am new to Node-Red, like hours new.

I was able to setup a sequence to turn on my lights if the weather is bad, someone is home, and it was after 14:00 and before sunset.

My lights turn on at sunset with 1 light coming on 45 mins earlier.

I created a second flow that turns off the lights if the bad weather ends. I would like to put a check in place that if it's 1 hour before sunset the lights should just stay on. I haven't been able to figure this one out.

I've tried BigTimer and Sun Position but they both require a start and end times. I just need is it more than 1 hour before sunset? Yes - Turn off the lights. No - Leave them on.

Would I just use a start time of 14:00 and an end time of Sunset (with -60 min offset)?

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [13 November 2019 20:23 UTC](https://discourse.nodered.org/t/stopping-sequence-an-hour-before-sunset/17911/2 "2019-11-13T20:23:15Z")

</div>

You can try the Openweathermap node, this will give the sunset and sunrise time as timestamp.  
Then it's easy to substract the 1 hour and do your thing.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [13 November 2019 20:26 UTC](https://discourse.nodered.org/t/stopping-sequence-an-hour-before-sunset/17911/3 "2019-11-13T20:26:45Z")

</div>

Try the time-range switch node. It works with offsets if you want.

> **[node-red-contrib-time-range-switch](https://flows.nodered.org/node/node-red-contrib-time-range-switch)**
>
> A simple Node-RED node that routes messages depending on the time. If the current time falls within the range specified in the node configuration, the message is routed to output 1. Otherwise the message is routed to output 2.

---

<div class="post-metadata">

**Author:** ![Hypnos](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hypnos/32/7566_2.png) [@Hypnos](https://discourse.nodered.org/u/Hypnos)\
**Post date:** [16 November 2019 20:36 UTC](https://discourse.nodered.org/t/stopping-sequence-an-hour-before-sunset/17911/5 "2019-11-16T20:36:57Z")

</div>

What is the problem with the start and end times?

Just add a **within-time-switch** node of the [node-red-contrib-sun-position](https://flows.nodered.org/node/node-red-contrib-sun-position) node collection with a start at 14:00 and a end 1 hour before sunset (set offset to -60 minutes or -1 hour - offset can be negative or positive). Then do switch the light of on the first output of the node and let the second output open.

 ![Setup](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/086e1dec458db224dda0fd473453a854f1fff6bc.png)

---

<div class="post-metadata">

**Author:** ![rlongfield](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rlongfield/32/14264_2.png) [@rlongfield](https://discourse.nodered.org/u/rlongfield)\
**Post date:** [17 November 2019 03:13 UTC](https://discourse.nodered.org/t/stopping-sequence-an-hour-before-sunset/17911/6 "2019-11-17T03:13:33Z")

</div>

This is what I ended up using. Luckily for me it snowed the day atfer I posted my question and it worked!
