Loop node reminder

Hi all!

I want to loop a node when i make a certain choice. And i want to get a new notification within 24 hours or so to remind me again.

Now i have this.

[{"id":"ecac18b5.46a7e8","type":"switch","z":"97634444.95c118","name":"","property":"originalMessage.text","propertyType":"msg","rules":[{"t":"eq","v":"Si","vt":"str"},{"t":"eq","v":"No","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":310,"y":300,"wires":[["3713e5e.401f41a","291bba44.676b96"],["daaddaa7.60a0d8"]]},{"id":"13059b5c.e5c775","type":"function","z":"97634444.95c118","name":"remove keyboard","func":"var opts = {\n  reply_to_message_id: msg.payload.messageId,\n  reply_markup: JSON.stringify({\n      \"remove_keyboard\" : true\n  })\n};\n\nmsg.payload.options = opts;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1130,"y":340,"wires":[["9bf67bcb.7d6288"]]},{"id":"daaddaa7.60a0d8","type":"function","z":"97634444.95c118","name":"no","func":"msg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'Ok, te aviso nuevamente en 1 hora.';\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":540,"wires":[["13059b5c.e5c775"]]},{"id":"3713e5e.401f41a","type":"function","z":"97634444.95c118","name":"Si","func":"msg.payload = {}\nmsg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'Genial!, escribiendo respuesta en CSV...';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":220,"wires":[["13059b5c.e5c775"]]},{"id":"1e547cc6.cd8da3","type":"file","z":"97634444.95c118","name":"","filename":"/data/psa_cambio_filtro.csv","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"utf8","x":720,"y":340,"wires":[["cc3d40b9.6b8c"]]},{"id":"291bba44.676b96","type":"function","z":"97634444.95c118","name":"data to csv file","func":"var data = \"Filtro PSA de la cocina cambiado!\"\n\nmsg.payload = data;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":260,"wires":[["1e547cc6.cd8da3","13059b5c.e5c775"]]},{"id":"39c28c41.8d5964","type":"moment","z":"97634444.95c118","name":"","topic":"","input":"","inputType":"msg","inTz":"America/Buenos_Aires","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"es-AR","output":"","outputType":"msg","outTz":"America/Buenos_Aires","x":700,"y":300,"wires":[[]]},{"id":"cbc2ffbe.8baf3","type":"delay","z":"97634444.95c118","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":500,"y":300,"wires":[["39c28c41.8d5964"]]},{"id":"6ab34b5e.0c3354","type":"comment","z":"97634444.95c118","name":"TODO","info":"If NO is selected remind me again in the next 24 hours.","x":710,"y":500,"wires":[]},{"id":"d9c9ac8d.eef77","type":"function","z":"97634444.95c118","name":"archivo guardado","func":"msg.payload = {}\nmsg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'Se escribió la respuesta en el archivo /data/psa_cambio_filtro.csv correctamente';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":690,"y":420,"wires":[["9bf67bcb.7d6288"]]},{"id":"cc3d40b9.6b8c","type":"delay","z":"97634444.95c118","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":660,"y":380,"wires":[["d9c9ac8d.eef77"]]}]

It would be helpful to explain what is going on. It looks like you have only provied part of a flow becuse nothing will trigger it to run -as it stands -The flow you

Where is the loop happening?
How are you making the choice?
You say you want to get a new notification within 24 hours. Where is the first notification coming from?

You need to provide more details.

Thanks for the reply.

I want to loop all over when i select the NO option.

Sorry this is the whole node.

[{"id":"bf42a305.e93a1","type":"function","z":"97634444.95c118","name":"Build telegam msg","func":"msg.payload = {\n\tchatId:\"587232739\", \n\ttype:\"message\",\n\tcontent: \"¿Se cambió el filtro PSA de la cocina?:\"\n};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":80,"wires":[["c1384b44.7bd8e8"]]},{"id":"c1384b44.7bd8e8","type":"telegram sender","z":"97634444.95c118","name":"","bot":"4a013224.b5a66c","outputs":1,"x":650,"y":80,"wires":[["aea563c5.f750d"]]},{"id":"d781c51a.c82fd8","type":"function","z":"97634444.95c118","name":"generate and send keyboard","func":"var opts = {\n // reply_to_message_id: msg.payload.messageId,\n  reply_markup: JSON.stringify({\n    keyboard: [\n      ['Si'],\n      ['No']],\n      'resize_keyboard' : true, \n      'one_time_keyboard' : false\n  })\n};\n\nmsg.payload.content = 'Elija una opción:';\nmsg.payload.options = opts;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":720,"y":140,"wires":[["9bf67bcb.7d6288"]]},{"id":"aea563c5.f750d","type":"change","z":"97634444.95c118","name":"","rules":[{"t":"set","p":"msg.payload.messageId","pt":"msg","to":"payload.content.message_id","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":140,"wires":[["d781c51a.c82fd8"]]},{"id":"dd119950.70b828","type":"inject","z":"97634444.95c118","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":100,"wires":[["bf42a305.e93a1","cbc2ffbe.8baf3"]]},{"id":"ecac18b5.46a7e8","type":"switch","z":"97634444.95c118","name":"","property":"originalMessage.text","propertyType":"msg","rules":[{"t":"eq","v":"Si","vt":"str"},{"t":"eq","v":"No","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":310,"y":300,"wires":[["3713e5e.401f41a","291bba44.676b96"],["daaddaa7.60a0d8"]]},{"id":"fe885168.d0106","type":"telegram receiver","z":"97634444.95c118","name":"","bot":"4a013224.b5a66c","saveDataDir":"","filterCommands":false,"x":130,"y":240,"wires":[["ecac18b5.46a7e8"],[]]},{"id":"13059b5c.e5c775","type":"function","z":"97634444.95c118","name":"remove keyboard","func":"var opts = {\n  reply_to_message_id: msg.payload.messageId,\n  reply_markup: JSON.stringify({\n      \"remove_keyboard\" : true\n  })\n};\n\nmsg.payload.options = opts;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1130,"y":340,"wires":[["9bf67bcb.7d6288"]]},{"id":"daaddaa7.60a0d8","type":"function","z":"97634444.95c118","name":"no","func":"msg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'Ok, te aviso nuevamente en 1 hora.';\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":540,"wires":[["13059b5c.e5c775"]]},{"id":"3713e5e.401f41a","type":"function","z":"97634444.95c118","name":"Si","func":"msg.payload = {}\nmsg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'Genial!, escribiendo respuesta en CSV...';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":220,"wires":[["13059b5c.e5c775"]]},{"id":"1e547cc6.cd8da3","type":"file","z":"97634444.95c118","name":"","filename":"/data/psa_cambio_filtro.csv","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"utf8","x":720,"y":340,"wires":[["cc3d40b9.6b8c"]]},{"id":"291bba44.676b96","type":"function","z":"97634444.95c118","name":"data to csv file","func":"var data = \"Filtro PSA de la cocina cambiado!\"\n\nmsg.payload = data;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":260,"wires":[["1e547cc6.cd8da3","13059b5c.e5c775"]]},{"id":"39c28c41.8d5964","type":"moment","z":"97634444.95c118","name":"","topic":"","input":"","inputType":"msg","inTz":"America/Buenos_Aires","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"es-AR","output":"","outputType":"msg","outTz":"America/Buenos_Aires","x":700,"y":300,"wires":[[]]},{"id":"cbc2ffbe.8baf3","type":"delay","z":"97634444.95c118","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":500,"y":300,"wires":[["39c28c41.8d5964"]]},{"id":"6ab34b5e.0c3354","type":"comment","z":"97634444.95c118","name":"TODO","info":"If NO is selected remind me again in the next 24 hours.","x":710,"y":500,"wires":[]},{"id":"d9c9ac8d.eef77","type":"function","z":"97634444.95c118","name":"archivo guardado","func":"msg.payload = {}\nmsg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'Se escribió la respuesta en el archivo /data/psa_cambio_filtro.csv correctamente';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":690,"y":420,"wires":[["9bf67bcb.7d6288"]]},{"id":"cc3d40b9.6b8c","type":"delay","z":"97634444.95c118","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":660,"y":380,"wires":[["d9c9ac8d.eef77"]]},{"id":"4a013224.b5a66c","type":"telegram bot","botname":"fisgon","usernames":"","chatids":"587232739","baseapiurl":"","updatemode":"polling","pollinterval":"400","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

I want to loop at the begging and wait for 24 hours for the loop to start over again.

Thanks again!

What is the 'all' you want to loop over? Currently if a 'No' comes in, you only go to the function node labeled 'No' and the 'remove keyboard' function node.

I'm sure you have an idea of what you want to do, but I don't understand what you want to do.

Maybe you could take a screen shot of our flow and draw in what you want to happen.

You could always send the output of the switch 'No' side to a delay node set to run in 24 hours and send it's output where you want.

Ok, let me get it clear with this picture.

The SI (yes) part works perfectly, i want to go back to the begging and make the loop ask again the whole process if i've selected NO. Maybe i should not use Timestamp because there is no way to do an input or so.

Thanks again!

You could do that by replacing your No node with a Delay node set to 24 hours and feed the output back to the beginning. However, an important question is what do you want to happen if node red is restarted during that 24 hours?

Ok, yes i want the node to remind me again in 24 hours start to counting when i've selected NO.

How is it done with a delay node?

Have you looked at the Help tab for the node?
What don’t you understand about it?

Ok I get it, you mean to delay 24 hours AFTER the NO node is selected?.

Where the loop should go? , should i loop at the beggening of the node?

Thanks!

Well if you want the ‘no’ `function node to run before the delay, where do you think it should go?

One other thing, a collection of nodes attached by wires is called a flow

ok, i want the NO node to loop after is selected. I know where to put it, the thing is where to connect the delay to.

Run the output of the delay to what ever flow you want it to go to. According to your drawing it looks like you want it to connect to the 'Build telegraph msg' node and the 'delay 2s' node

I get the feeling that you are missing some of the fundamental concepts of node-red. I suggest that you watch this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

1 Like

Thanks for your piece of advice, in fact, i go to that documentation very often.

I think that maybe i'm missing some logical/programming concepts because is not that i'm not using the node-red tool the right way instead i don't know HOW to do it in a logical way.
I know is not hard what i want to do.

Thanks a lot!

In your flow, what node do you want to trigger when the 24 hours is up?

Connect the output of the delay node to that node.

When i select the NO node i want to wait 24 hours so the flow start all over again and re ask me the same question.