After receiving message generate each second a message for 10 minutes

So after a message arrives (content is irrelevant) a node starts so send for 10 minutes a message each second. How is this possible?

Doing a for loop sending via node.send? https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously
However there is no build in sleep function in JavaScript. You need a few lines code to use a sleep function. So is there no easier way to achive this task?

Have a look at the https://flows.nodered.org/node/node-red-contrib-msg-resend node.

Using the core nodes, you can do it with a pair of Trigger nodes:

[{"id":"ffb4b0dd.5fd2d","type":"trigger","z":"e91e40e3.6bde","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-1","extend":false,"units":"s","reset":"reset","bytopic":"all","topic":"topic","outputs":1,"x":420,"y":720,"wires":[["a53c62cb.19d2e"]]},{"id":"8e18f3ce.54299","type":"trigger","z":"e91e40e3.6bde","name":"","op1":"","op2":"reset","op1type":"nul","op2type":"str","duration":"10","extend":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":250,"y":800,"wires":[["ffb4b0dd.5fd2d"]]},{"id":"a53c62cb.19d2e","type":"debug","z":"e91e40e3.6bde","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":720,"wires":[]},{"id":"36fe03d.6d6aefc","type":"inject","z":"e91e40e3.6bde","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":720,"wires":[["ffb4b0dd.5fd2d","8e18f3ce.54299"]]}]

The incoming message goes to both trigger nodes. The top one is configured to resend 1 every second until it receives a msg.payload with a value of "reset".
The bottom trigger node sends nothing initially, waits 10 minutes, then sends a payload of reset, which is passed to the top trigger node to stop it.

3 Likes

Thanks, I'll use this variant with built in nodes. The https://flows.nodered.org/node/node-red-contrib-msg-resend is especially useful if you want to change the intervals at runtime.