Hello,
In this flow, there are randomly generated numbers between 20 and 60 in function "Data Generation". Functions' output is connected to a trigger node which configuration is shown bellow. Trigger's output is connected to a function "Fire Off" (Α Mister from this forum helped me a lot with this part). After that there is a debug node which shows the message. What I am trying to accomplish is: generate a random number between 20 and 60, then decrease this number by 1 every 1 second and when the value becomes 20 the next value I want to be the random generated number between 20 and 60. The problem is that flow runs only once and that's why I am trying to insert something like a reset to the value. Are there any ideas on how to make it happen?
Thanks for your time, appreciate your help!
Finished Flow
[{"id":"ff6cdaba.0c2748","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"1e5e334b.eee44d","type":"function","z":"ff6cdaba.0c2748","name":"Data Generation","func":"flow.set(\"counter\", Math.round(Math.random()*(60 - 20) + 20))//Math.floor(Math.random()*41)+20)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":280,"wires":[["4b796f69.bc785"]]},{"id":"31b6afa1.d6b6e","type":"inject","z":"ff6cdaba.0c2748","name":"Sensor","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":530,"y":240,"wires":[["1e5e334b.eee44d"]]},{"id":"ded18de2.933c5","type":"function","z":"ff6cdaba.0c2748","name":"Fire Off","func":"var counter = flow.get('counter')\nmsg.payload = counter;\nif(counter==20)\n{\ncounter=Math.floor(Math.round(Math.random()*(60 - 20) + 20));\n}\nelse\n{\ncounter--;\n}\nflow.set(\"counter\",counter);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":360,"wires":[["212b659d.77354a"]]},{"id":"212b659d.77354a","type":"debug","z":"ff6cdaba.0c2748","name":"Off","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":400,"wires":[]},{"id":"4b796f69.bc785","type":"trigger","z":"ff6cdaba.0c2748","name":"","op1":"","op2":"","op1type":"pay","op2type":"payl","duration":"-500","extend":true,"overrideDelay":false,"units":"ms","reset":"20","bytopic":"all","topic":"topic","outputs":1,"x":640,"y":320,"wires":[["ded18de2.933c5"]]}]