# How to restrict a flow's output based on time of day

**URL:** <https://discourse.nodered.org/t/how-to-restrict-a-flows-output-based-on-time-of-day/97762>\
**Category:** General\
**Tags:** time\
**Created:** [23 June 2025 17:29 UTC](https://discourse.nodered.org/t/how-to-restrict-a-flows-output-based-on-time-of-day/97762 "2025-06-23T17:29:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![abrayshaw](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@abrayshaw](https://discourse.nodered.org/u/abrayshaw)\
**Post date:** [23 June 2025 17:29 UTC](https://discourse.nodered.org/t/how-to-restrict-a-flows-output-based-on-time-of-day/97762/1 "2025-06-23T17:29:03Z")

</div>

I am very new to Node-Red. I am using Homeseer automation for lighting control. Using Homeseer's documentation (and hours of experimentation) I was able to create a NR flow to have an outdoor motion sensor cause my Amazon Echo devices to announce "Motion detected" when the sensor is triggered.  
However, I don't want this to happen during nighttime hours.  
My question is, how do I add a node to my system that lets my flow determine the time of day, so I can use a switch node (?) to only allow the Echo trigger during specific hours of the day? I am using NR 4.0.9  
TIA

---

<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:** [23 June 2025 18:15 UTC](https://discourse.nodered.org/t/how-to-restrict-a-flows-output-based-on-time-of-day/97762/2 "2025-06-23T18:15:51Z")

</div>

You could use the [time range switch node](https://flows.nodered.org/node/node-red-contrib-time-range-switch).

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [23 June 2025 20:49 UTC](https://discourse.nodered.org/t/how-to-restrict-a-flows-output-based-on-time-of-day/97762/3 "2025-06-23T20:49:56Z")

</div>

You could also use a switch node and a JSONata expresstion to output time and check if betweeen times in 24hr format  
e.g.

```auto
[{"id":"14e67ff4e0591ac4","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":" { \"relay\":0, \"on\":true }","payloadType":"json","x":330,"y":2220,"wires":[["675924b00eaaa4da"]]},{"id":"675924b00eaaa4da","type":"switch","z":"d1395164b4eec73e","name":"","property":"$number($moment().format(\"Hmm\"))","propertyType":"jsonata","rules":[{"t":"btwn","v":"700","vt":"num","v2":"2200","v2t":"num"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":2220,"wires":[["4c147035c4b63827"]]},{"id":"4c147035c4b63827","type":"debug","z":"d1395164b4eec73e","name":"debug 2565","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":2220,"wires":[]}]

```

Should only pass message if between 700 (7 am) and 2200 (10pm)

---

<div class="post-metadata">

**Author:** ![abrayshaw](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@abrayshaw](https://discourse.nodered.org/u/abrayshaw)\
**Post date:** [24 June 2025 14:03 UTC](https://discourse.nodered.org/t/how-to-restrict-a-flows-output-based-on-time-of-day/97762/4 "2025-06-24T14:03:11Z")

</div>

Sounds like just what I need. But, being a complete newbie to node-red, when the install instructions say to "change directory to your node-red installation", exactly which Windows directory would this be? I can see the NR installation created more than one.  
I tried installing another node, and it did not appear in my node list, so perhaps I wasn't in the correct directory when I issued the command.  
Thanks

---

<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:** [24 June 2025 14:14 UTC](https://discourse.nodered.org/t/how-to-restrict-a-flows-output-based-on-time-of-day/97762/5 "2025-06-24T14:14:12Z")

</div>

In the right top hamburger menu, you can install nodes via manage palette

---

<div class="post-metadata">

**Author:** ![abrayshaw](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@abrayshaw](https://discourse.nodered.org/u/abrayshaw)\
**Post date:** [24 June 2025 15:40 UTC](https://discourse.nodered.org/t/how-to-restrict-a-flows-output-based-on-time-of-day/97762/6 "2025-06-24T15:40:04Z")

</div>

Got it. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 September 2025 15:40 UTC](https://discourse.nodered.org/t/how-to-restrict-a-flows-output-based-on-time-of-day/97762/7 "2025-09-22T15:40:34Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
