Time Range for the weekend

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.

In combination with this maybe:

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

[{"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.

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

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

2 Likes

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

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 :frowning:

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.

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

Craig

1 Like

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

I have this in my startup processing:

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.

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

you can add a timezone if you wish to.

Ah, that is what I am after. Excellent.

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

image

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

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

Nope, nicely documented in the description :slight_smile:

Interesting.

[edit]

I think you meant node-red-contrib-sun-position (node) - Node-RED (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.

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

1 Like

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