It can be done without using the function node. The idea is to load the random number to msg.payload
, delay 1 second using the trigger node, and then decrement msg.payload
using a change node. The trigger node will be reset when payload reaches the value zero.
[{"id":"13040b63810e7b1b","type":"tab","label":"Flow 4","disabled":false,"info":"","env":[]},{"id":"85611df1d2aa62b5","type":"trigger","z":"13040b63810e7b1b","name":"heartbeat","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":false,"overrideDelay":false,"units":"s","reset":"0","bytopic":"all","topic":"topic","outputs":1,"x":520,"y":180,"wires":[["131bed3b32a1a64a"]],"outputLabels":["send \"fail\" if not feeded"]},{"id":"2ed4ee7be5488558","type":"inject","z":"13040b63810e7b1b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":180,"wires":[["607a9ef5307de2e5"]]},{"id":"1b4d94e2ff9d92b5","type":"link out","z":"13040b63810e7b1b","name":"link out 1","mode":"link","links":["c4e2a8281a303149"],"x":795,"y":260,"wires":[]},{"id":"c4e2a8281a303149","type":"link in","z":"13040b63810e7b1b","name":"link in 1","links":["1b4d94e2ff9d92b5"],"x":485,"y":260,"wires":[["85611df1d2aa62b5"]]},{"id":"8f6ca65f4feac75b","type":"debug","z":"13040b63810e7b1b","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":880,"y":180,"wires":[]},{"id":"607a9ef5307de2e5","type":"random","z":"13040b63810e7b1b","name":"","low":"5","high":10,"inte":"true","property":"payload","x":340,"y":180,"wires":[["85611df1d2aa62b5"]]},{"id":"131bed3b32a1a64a","type":"change","z":"13040b63810e7b1b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload - 1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":180,"wires":[["8f6ca65f4feac75b","1b4d94e2ff9d92b5"]]}]