# How do I only pass a motion sensor change between dusk and dawn?

**URL:** <https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067>\
**Category:** General\
**Created:** [17 February 2019 07:59 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067 "2019-02-17T07:59:42Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheZeke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thezeke/32/6071_2.png) [@TheZeke](https://discourse.nodered.org/u/TheZeke)\
**Post date:** [17 February 2019 07:59 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/1 "2019-02-17T07:59:42Z")

</div>

The question mark in the diagram shows where I want to stop the msg from passing through _unless_ it is between dusk and dawn.

[Click HERE for a diagram of the flow.](https://i.imgur.com/aYnte5Q.png)

I'm trying to use the BigTimer node. The problem is the status change used as an input also serves as an override. I think BigTimer is more for actually trigging stuff and the input is _only_ used for overrides. I don't think it's made to pass inputs through if the BigTimer node is ON (during the scheduled on period).

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [17 February 2019 08:32 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/2 "2019-02-17T08:32:38Z")

</div>

There are several different ways to do this.

The one I find easiest to understand when I look back at a flow is to use a global variable

Have a separate flow that starts with a sunrise sunset node (there are several) and using a switch node and a change node to set a global variable to true/false

In your existing flow you can then have a switch node that checks to see if the global variable is true or false and only passes messages forward if true

---

<div class="post-metadata">

**Author:** ![Urs-Eppenberger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/urs-eppenberger/32/28_2.png) [@Urs-Eppenberger](https://discourse.nodered.org/u/Urs-Eppenberger)\
**Post date:** [17 February 2019 08:35 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/3 "2019-02-17T08:35:45Z")

</div>

Another idea is:  
use a gate node [https://flows.nodered.org/node/node-red-contrib-simple-gate](https://flows.nodered.org/node/node-red-contrib-simple-gate)  
Connect BigTimer to it so it switches the gate on and off

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [17 February 2019 09:54 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/4 "2019-02-17T09:54:34Z")

</div>

Bigtimer outputs dusk and dawn times (and many more). Put a debug node set to show the complete message on the middle output and have a look.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [17 February 2019 11:20 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/5 "2019-02-17T11:20:59Z")

</div>

I'm working on a general solution for such use cases to make it easy to use. Just install the dsm node and import the flow from the [Wiki](https://github.com/cflurin/node-red-contrib-dsm/wiki/Time-gate). Like all NR-nodes you can use it as `black box` without any knowledge of its internal workings.

It's a first version, so there is no error-handling yet and it can be only used for a day-range.

![time-gate](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6e36bc749cae999f23b6eee960efec0698d247e6.png)

---

<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:** [17 February 2019 11:43 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/6 "2019-02-17T11:43:31Z")

</div>

Hi @TheZeke

as you can see, lots of possible ways to do it. The suggestion from @ukmoose can also be seen in action in the node-red cookbook recipe: [https://cookbook.nodered.org/basic/route-on-context](https://cookbook.nodered.org/basic/route-on-context)

The recipe talks about routing a message based on a context value - in this instance, as Mark describes, you'd use the Bigtimer node to keep the context value updated to indicate if it is within the desired time period, and then the Switch node to pass a message on only if the context value set to the desired value.

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [17 February 2019 12:23 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/7 "2019-02-17T12:23:20Z")

</div>

You may want to try `node-red-contrib-sun-position`, more especifically the node `within-time-switch` from the set.

> **[node-red-contrib-sun-position](https://www.npmjs.com/package/node-red-contrib-sun-position)**
>
> NodeRED nodes to get sun and moon position. Latest version: 2.2.0-beta3, last published: 2 years ago. Start using node-red-contrib-sun-position in your project by running \`npm i node-red-contrib-sun-position\`. There are no other projects in the npm...

> A simple 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.

 ![a-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/175661cbcdf751e8f4f29c02e47849bff4640754.png)

---

<div class="post-metadata">

**Author:** ![TheZeke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thezeke/32/6071_2.png) [@TheZeke](https://discourse.nodered.org/u/TheZeke)\
**Post date:** [17 February 2019 23:31 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/8 "2019-02-17T23:31:12Z")

</div>

I went with this idea... Works well. Thank you!

![49%20PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e809419f543b609ac55a0ae73577a40131abb565.png)

---

<div class="post-metadata">

**Author:** ![schumi2004](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/schumi2004/32/11708_2.png) [@schumi2004](https://discourse.nodered.org/u/schumi2004)\
**Post date:** [3 September 2019 12:18 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/9 "2019-09-03T12:18:24Z")

</div>

@TheZeke  
I tried the same but cannot get the gate to close and open.  
How does your bigtimer config look like?

---

<div class="post-metadata">

**Author:** ![cdk222](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cdk222/32/34536_2.png) [@cdk222](https://discourse.nodered.org/u/cdk222)\
**Post date:** [10 October 2019 12:36 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/11 "2019-10-10T12:36:06Z")

</div>

Took me a while to figure this one out

You need to set the Topic Msg in the BigTimer to "control" or whatever custom topic you set in the Gate Node under the Control Topic section

Hope this helps

---

<div class="post-metadata">

**Author:** ![Janstander2011](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janstander2011/32/6446_2.png) [@Janstander2011](https://discourse.nodered.org/u/Janstander2011)\
**Post date:** [11 November 2019 04:06 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/12 "2019-11-11T04:06:39Z")

</div>

thank you. this is exactly what I needed.

---

<div class="post-metadata">

**Author:** ![JuliusLedoux](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juliusledoux/32/21749_2.png) [@JuliusLedoux](https://discourse.nodered.org/u/JuliusLedoux)\
**Post date:** [12 May 2020 14:46 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/13 "2020-05-12T14:46:16Z")

</div>

I really liked this approach. It makes sense to me.

---

<div class="post-metadata">

**Author:** ![brucysNZ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brucysnz/32/22420_2.png) [@brucysNZ](https://discourse.nodered.org/u/brucysNZ)\
**Post date:** [21 May 2020 02:02 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/14 "2020-05-21T02:02:35Z")

</div>

Hi @TheZeke

Would you please be able to share you flow as is exactly what i have been looking for. Great solution

---

<div class="post-metadata">

**Author:** ![TheZeke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thezeke/32/6071_2.png) [@TheZeke](https://discourse.nodered.org/u/TheZeke)\
**Post date:** [21 May 2020 17:49 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/15 "2020-05-21T17:49:57Z")

</div>

> [@brucysNZ](#):
>
> Would you please be able to share you flow as is exactly what i have been looking for. Great solution

Certainly I can:

`[{"id":"1e487899.47cf7f","type":"trigger-state","z":"8e59a440.a68cc","name":"","server":"d2195697.bb68a8","entityid":"binary_sensor.sensenode1_motion","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"mms5g7itaz","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":195,"y":135,"wires":[["257dfff2.5ab418","41b7c5e1.fdf2fc"],["41b7c5e1.fdf2fc"]]},{"id":"257dfff2.5ab418","type":"gate","z":"8e59a440.a68cc","name":"Night Gate","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":505,"y":115,"wires":[["7de81d9e.dfc55c"]]},{"id":"98021542.e9a768","type":"api-call-service","z":"8e59a440.a68cc","name":"Office Light On 80%","server":"d2195697.bb68a8","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.office_light\",\"brightness_pct\":80,\"transition\":6}","render_data":false,"mergecontext":"","output_location":"payload","output_location_type":"msg","x":925,"y":135,"wires":[[]]},{"id":"41b7c5e1.fdf2fc","type":"trigger","z":"8e59a440.a68cc","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"30","extend":false,"units":"min","reset":"on","bytopic":"all","name":"","x":505,"y":215,"wires":[["196ad358.b9429d"]]},{"id":"196ad358.b9429d","type":"api-call-service","z":"8e59a440.a68cc","name":"Office Light Off","server":"d2195697.bb68a8","service_domain":"light","service":"turn_off","data":"{\"entity_id\":\"light.office_light\",\"transition\":10}","render_data":false,"mergecontext":"","output_location":"payload","output_location_type":"msg","x":890,"y":210,"wires":[[]]},{"id":"34dae4ca.9262ac","type":"bigtimer","z":"8e59a440.a68cc","outtopic":"control","outpayload1":"open","outpayload2":"close","name":"Sunset-Sunrise","comment":"","lat":"30.09942","lon":"-117.66221","starttime":"5004","endtime":"5003","starttime2":0,"endtime2":0,"startoff":"-90","endoff":"250","offs":0,"outtext1":"","outtext2":"","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":0,"month6":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"repeat":false,"atstart":true,"odd":false,"even":false,"x":290,"y":75,"wires":[["257dfff2.5ab418"],[],[]]},{"id":"7de81d9e.dfc55c","type":"api-current-state","z":"8e59a440.a68cc","name":"Stop if light ON","server":"d2195697.bb68a8","outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.office_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":710,"y":135,"wires":[["98021542.e9a768"],[]]},{"id":"d2195697.bb68a8","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"}]`

---

<div class="post-metadata">

**Author:** ![brucysNZ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brucysnz/32/22420_2.png) [@brucysNZ](https://discourse.nodered.org/u/brucysNZ)\
**Post date:** [21 May 2020 19:25 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/16 "2020-05-21T19:25:30Z")

</div>

Thanks so much bud. I will look at this tonight. Cheers heaps

---

<div class="post-metadata">

**Author:** ![queelyte](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/queelyte/32/30160_2.png) [@queelyte](https://discourse.nodered.org/u/queelyte)\
**Post date:** [1 August 2020 20:38 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/17 "2020-08-01T20:38:52Z")

</div>

I still a noon on node red. Can you provide your flow in json for me to use?

---

<div class="post-metadata">

**Author:** ![queelyte](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/queelyte/32/30160_2.png) [@queelyte](https://discourse.nodered.org/u/queelyte)\
**Post date:** [1 August 2020 20:39 UTC](https://discourse.nodered.org/t/how-do-i-only-pass-a-motion-sensor-change-between-dusk-and-dawn/8067/18 "2020-08-01T20:39:55Z")

</div>

> [@TheZeke](#):
>
> customoutputs":,"outputinitially":false,"state\_type":"str","x":195,"y":135,"wires":

Never mind.....I just saw it. LOL
