Function Node: Time between 22:00 - 6:00

Hello forum,
i would like to build a function node that only executes the next node under these conditions (Time between 22:00 - 6:00), otherwise just terminate it. Does anyone have an idea?

thank you in advance.

I would probably use node-red-contrib-simple-gate to block the message, and control the gate by sending open/close messages from one of the scheduler nodes such as cron-plus or even from a couple of inject nodes set to fire at 22:00 and 06:00.

If you really want to do it in a function node as a learning exercise then start by looking at the javascript Date object.

thank. in my case your idea doesn't work. I have a motion detector as a trigger. The cron plus node has no input.

You misunderstand. Feed the motion detector into the gate node. When the gate is open it will pass any motion messages on, when the gate is closed it will block them. Also feed the cron-plus node into the gate and configure it to send the control messages that open and close the gate at the appropriate times.

Hi, sorry but i don't understand...

The Motion Detector Node has not input too

Here my flow:

Take a look :

Feed both the motion detector and the cron plus node into the gate.
However the time switch node is a better way, I had forgotten about that one.

Super! that seems to be working. Thank you!

Thank you for Help.

A few days ago I spotted this new node.

Might also be useful in that case.

1 Like

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