# Time Range for the weekend

**URL:** https://discourse.nodered.org/t/time-range-for-the-weekend/57216
**Category:** General
**Created:** [25 January 2022 17:40 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216 "2022-01-25T17:40:03Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)
#### Post date: [25 January 2022 17:40 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/1 "2022-01-25T17:40:03Z")

</div>

I have been using the `time range` node to limit messages being sent at night.

I'd like to have a different time range for the weekend.

Can anyone suggest how?

I looked at `bigtimer` and it looks like the `msg.payload` can be passed through, but I really want the whole `msg` passed on.

Looks like the job for a function if not.

---

<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: [25 January 2022 17:42 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/2 "2022-01-25T17:42:35Z")

</div>

> **[node-red-contrib-schedex](https://flows.nodered.org/node/node-red-contrib-schedex)**
>
> Scheduler for node-red which allows you to enter on/off times as 24hr clock (e.g. 01:10) or suncalc events (e.g. goldenHour). It also allows you to offset times and randomise the time within the offset.

In combination with this maybe:

> **[node-red-contrib-simple-gate](https://flows.nodered.org/node/node-red-contrib-simple-gate)**
>
> A gate node for node-RED

---

<div class="post-metadata">

### Author: ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)
#### Post date: [25 January 2022 17:43 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/3 "2022-01-25T17:43:07Z")

</div>

I recommend to use in general the switch node to filter messages.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6f7a214248f3824738be81341cdc5a2e4495ffda.png)

```auto
[{"id":"2d7a85e86e845196","type":"switch","z":"0db43ef5ee91fda8","name":"","property":"$number($moment().format('E'))","propertyType":"jsonata","rules":[{"t":"gte","v":"6","vt":"num"},{"t":"lt","v":"6","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":770,"y":500,"wires":[["008d2bd0cfe771c3"],["61043008eef85152"]]},{"id":"008d2bd0cfe771c3","type":"debug","z":"0db43ef5ee91fda8","name":"is weekend","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":970,"y":480,"wires":[]},{"id":"61043008eef85152","type":"debug","z":"0db43ef5ee91fda8","name":"is working day","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":980,"y":520,"wires":[]},{"id":"ab42be5d649efe82","type":"inject","z":"0db43ef5ee91fda8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":630,"y":500,"wires":[["2d7a85e86e845196"]]}]

```

EDIT: Changed the switch - to use numbers 1 to 7 for week days.

Btw: Time Range is not necessary as well - can be done with standard nodes in the same way.

If you prefer - a GUI Interface as a filter - I recommend the lightscheduler nodes - which include a filter node and astro times.

> **[node-red-contrib-light-scheduler](https://flows.nodered.org/node/node-red-contrib-light-scheduler)**
>
> Light Scheduler is a node-red node that provides a weekly schedule, and is mainly focused on controlling light in home automation scenarios.

Using the filter node - you can use the mouse to send payloads to first or second out put:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d4806975891f35c70ecc7ff91d4f9beb5bbc4234.png)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [25 January 2022 20:20 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/4 "2022-01-25T20:20:04Z")

</div>

Don't over complicate things. Have two schedules, 1 for weekday and one for weekend.

---

<div class="post-metadata">

### Author: ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)
#### Post date: [26 January 2022 07:52 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/5 "2022-01-26T07:52:01Z")

</div>

> [@mickym2](#):
>
> I recommend to use in general the switch node to filter messages.

Thanks. I'd looked at using a switch, but generally avoid using `moment` (and your example uses it).

> [@TotallyInformation](#):
>
> Don't over complicate things. Have two schedules, 1 for weekday and one for weekend.

Yes, the complication was (is) calculating what day it is. Yes, I could use moment, but I have a bit of an aversion to it for some reason.

Shame there is not a `day_range` node to complement the `time_range` node ☹

This does seem to confirm I have not missed anything obvious in how to do it.

I'll just use a function to block the messages.

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [26 January 2022 08:58 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/6 "2022-01-26T08:58:12Z")

</div>

Yep you want the WIthin-time node from node-red-contrib-sunpos - does exactly what you want

Craig

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [26 January 2022 10:29 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/7 "2022-01-26T10:29:33Z")

</div>

Agree, the sunposition Node has some very nice and useful nodes.

I have this in my startup processing:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/8/68a143e66c3cb0156c273f15c3e25bc8d6ff2ccd.png)

---

<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: [26 January 2022 15:46 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/8 "2022-01-26T15:46:16Z")

</div>

> [@borpin](#):
>
> I'd looked at using a switch, but generally avoid using `moment`

You don't have to use moments, JSONata has the $now(), which you can format to return day of week, Then $substring() to return first letter, eg "s". So in switch, == "s" is week end, otherwise week day.

```auto
$substring($now("[F]"),0,1)

```

you can add a timezone if you wish to.

---

<div class="post-metadata">

### Author: ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)
#### Post date: [26 January 2022 21:48 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/9 "2022-01-26T21:48:07Z")

</div>

> [@E1cid](#):
>
> JSONata has the $now(), which you can format to return day of week,

Ah, that is what I am after. Excellent.

[edit]  
Took me a minute to get this right, so for anyone following on

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/245837ecec32ae7cf7210a9b405d5a7a41802f2d.png)

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [27 January 2022 02:30 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/10 "2022-01-27T02:30:33Z")

</div>

You will look at that in two years and say what does this do !!!

Better off with the Sunpos node - it is very intuitive and self explanatory.

Also i believe moment is now included in the standard NR install AFAIK - i seem to remember Nick saying something about this in a thread a little while ago.

Craig

---

<div class="post-metadata">

### Author: ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)
#### Post date: [27 January 2022 11:11 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/11 "2022-01-27T11:11:16Z")

</div>

> [@craigcurtin](#):
>
> Better off with the Sunpos node

How does `sunpos` help with weekends? All my sun position stuff is done in HA anyway so I have no need for it.

> [@craigcurtin](#):
>
> You will look at that in two years and say what does this do !!!

Nope, nicely documented in the description 🙂

> [@craigcurtin](#):
>
> Also i believe moment is now included in the standard NR install AFAIK

Interesting.

[edit]

> [@craigcurtin](#):
>
> WIthin-time node from node-red-contrib-sunpos

I think you meant [node-red-contrib-sun-position (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-sun-position) (sunpos is a different node) and it isn't well named as it does far more than work on sun position!! I'll have another look.

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [28 January 2022 04:54 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/12 "2022-01-28T04:54:57Z")

</div>

Yep sorry about the incorrect name - the Within-time node allows you to define a time/day/month range that interests you (say the weekend) and if it falls within the time it will go to output 1 - if not it goes to output 2 - makes it very easy to chain them for specfic conditions etc - has a nice status display to show when it will next fire etc etc

Craig

---

<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: [11 February 2022 04:55 UTC](https://discourse.nodered.org/t/time-range-for-the-weekend/57216/13 "2022-02-11T04:55:55Z")

</div>

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