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

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.

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).

1 Like

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

Another idea is:
use a gate node
Connect BigTimer to it so it switches the gate on and off

1 Like

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.

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


1 Like

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:

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.

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

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.

1 Like

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



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

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

thank you. this is exactly what I needed.

1 Like

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

Hi @TheZeke

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"}]

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

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

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