Node-red-contrib-time-range-switch

I am using node-red-contrib-time-range-switch node to route messages depending on the time. Questions:

  1. How can I re-use a node across multiple flows(tabs)? For example, I create a node from 6am to 9am and wants to use same node in multiple flows.
  2. Does it support variables as inputs (like “Start time”, “End time”)? what is the syntax?

Thanks.

For #1. You can use the ‘Link in’ and ‘Link out’ nodes. And for #2. The ‘time range’ node should have an option to select range of time that will allow the payload to be allowed through or blocked.

  1. Link in and link out can’t be used here, because the link out has to target to different actions. Here is the example:

motion trigger 1 -> if within 6am to 9am -> do action 1
motion trigger 2 -> if within 6am to 9am -> do action 2

  1. sorry I don’t understand. I was thinking if it takes variable as input, I can define start time and end time as variables and pass to the time range node.

the goal is to define a common start/end time for multiple time range node, so I don’t have to change multiple places if I decided to change the start/end time.

  1. Hope this outlines the idea:

[{"id":"e084f85b.8197b8","type":"time-range-switch","z":"25063fae.4f85f","name":"6-9am","lat":"","lon":"","startTime":"06:00","endTime":"09:00","startOffset":0,"endOffset":0,"x":1398,"y":465,"wires":[["940cfe74.4596e"],[]]},{"id":"b8a21a79.cc5088","type":"inject","z":"25063fae.4f85f","name":"Trig1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":1040,"y":465,"wires":[["672dae78.6384b"]]},{"id":"672dae78.6384b","type":"link out","z":"25063fae.4f85f","name":"Trig1 Out","links":["1f1586d.5667079"],"x":1159,"y":464,"wires":[]},{"id":"1f1586d.5667079","type":"link in","z":"25063fae.4f85f","name":"In different flow","links":["2da8f8e0.6542d8","672dae78.6384b"],"x":1270,"y":466,"wires":[["e084f85b.8197b8"]]},{"id":"940cfe74.4596e","type":"link out","z":"25063fae.4f85f","name":"Flow 3","links":["4185510d.c3d79","b517a534.fe6148"],"x":1518,"y":458,"wires":[]},{"id":"431f7bad.971234","type":"inject","z":"25063fae.4f85f","name":"Trig2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":1043,"y":572,"wires":[["2da8f8e0.6542d8"]]},{"id":"2da8f8e0.6542d8","type":"link out","z":"25063fae.4f85f","name":"Trig 2 Out","links":["1f1586d.5667079"],"x":1162,"y":571,"wires":[]},{"id":"aa574030.8b38a","type":"comment","z":"25063fae.4f85f","name":"Triggers in Flow#1","info":"","x":1082,"y":406,"wires":[]},{"id":"28cde1ce.76b99e","type":"comment","z":"25063fae.4f85f","name":"Node in Flow#3","info":"","x":1373,"y":407,"wires":[]},{"id":"71394199.bab81","type":"comment","z":"25063fae.4f85f","name":"Node in Flow #1 or #2 etc","info":"","x":1107,"y":526,"wires":[]},{"id":"4185510d.c3d79","type":"link in","z":"25063fae.4f85f","name":"Flow 4","links":["940cfe74.4596e"],"x":1647,"y":459,"wires":[[]]},{"id":"e164164.1f69ee8","type":"comment","z":"25063fae.4f85f","name":"Node in Flow#4","info":"","x":1694,"y":408,"wires":[]},{"id":"258a209f.12c09","type":"comment","z":"25063fae.4f85f","name":"Node in Flow#4","info":"","x":1695,"y":528,"wires":[]},{"id":"b517a534.fe6148","type":"link in","z":"25063fae.4f85f","name":"Flow 4","links":["940cfe74.4596e"],"x":1656,"y":584,"wires":[[]]}]

  1. Time-range-switch doesn’t appear to be able to be re-defined on the fly with and external inputed time range. i.e. you set the range once and that’s it. There may be another node that allows this but you will have to go through the nodes to establish if this is possible.

Hope this helps.

So? why not link in/out twice??

in this case, trig1 will trigger all actions connect to the link out, which is not intended.

sorry, maybe there is misunderstanding, the purpose is to have ONE place control the start/end time, which serves in multiple flows.

yeah, basically i made the same recommendation as bastero, but you are right, it would trigger in both cases.

Maybe an idea to use a global variable for the start/stop time on a bigtimer?

global.set("starttime",”12:34”)

on_overide global.get("starttime")

You’d still need to use the bigtimer everywhere, but it would allow you to change them centrally :thinking:

1 Like

Thanks for the idea. I used bigtimer before and it was complicated than what I needed. I will research more on how to use on_override.

That’s where you can use subflows see Subflows : Node-RED

I don’t use this node. However, you can do it with node-red-contrib-sun-position (node) - Node-RED and the within-time node. It can use variables or (eg) msg.starttime among other options.

1 Like

This is what I am looking for! Thank you!