One approach is to use a global context incl. contextStorage set in settings.js
- set the global variable.
- use a function with setTimeout()
example:
[{"id":"a45da4bb.5ab008","type":"function","z":"895bbff8.0e6c4","name":"watchdog","func":"var delay = (global.get('delay') || 2) * 1000;\nvar timeout = context.get('timeout') || null;\n\nif (timeout) {\n clearTimeout(timeout);\n}\n\nvar timeout = setTimeout(function() {\n node.send(msg);\n}, delay);\n\ncontext.set('timeout', timeout);\n\nreturn null;","outputs":1,"noerr":0,"x":280,"y":4220,"wires":[["28d88d3d.0c1a12"]]},{"id":"28d88d3d.0c1a12","type":"debug","z":"895bbff8.0e6c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":4220,"wires":[]},{"id":"a1c461ee.db5fe","type":"inject","z":"895bbff8.0e6c4","name":"","topic":"","payload":"timeout","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":4220,"wires":[["a45da4bb.5ab008"]]},{"id":"5c2960e6.0e869","type":"inject","z":"895bbff8.0e6c4","name":"","topic":"","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":4120,"wires":[["6d532299.17d1cc"]]},{"id":"6d532299.17d1cc","type":"change","z":"895bbff8.0e6c4","name":"","rules":[{"t":"set","p":"delay","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":4120,"wires":[[]]},{"id":"a9e85147.9b828","type":"inject","z":"895bbff8.0e6c4","name":"","topic":"","payload":"4","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":4160,"wires":[["6d532299.17d1cc"]]}]