Timeout Function for E-Mail Alert

Hello, I recently got into Node-Red and Javascript for a project, most of the stuff I did so far worked well but I am struggling to set up an Email-alert or more specifically the timeout for that alert (in order to not get spammed by Node-Red). The sending of the Email if a condition is met works but I would like to add a timeout that, if the condition is met, it sends the email and then stops the function from running again for x-amount of time (lets say 10 minutes/600000 milliseconds). I would be very thankful if anyone could help me with my problem. Below is the flow for the function i have so far (working e-mail alert without timeout).
Required Nodes: node-red-node-email (node) - Node-RED

[{"id":"5c52b845.9f7ea8","type":"e-mail","z":"fa544ea.0c724b","server":"smtp.gmail.com","port":"465","secure":true,"tls":true,"name":"","dname":"E-Mail-Out","x":670,"y":940,"wires":[]},{"id":"cf426062.d581c","type":"inject","z":"fa544ea.0c724b","name":"<500 Alarm","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"400","payloadType":"num","x":230,"y":940,"wires":[["bd20c11.581384"]]},{"id":"192561a2.ae71ae","type":"inject","z":"fa544ea.0c724b","name":">=500 kein Alarm","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"600","payloadType":"num","x":240,"y":1000,"wires":[["bd20c11.581384"]]},{"id":"cf430d54.2ff45","type":"debug","z":"fa544ea.0c724b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":1000,"wires":[]},{"id":"bd20c11.581384","type":"function","z":"fa544ea.0c724b","name":"","func":"if (msg.payload < 500)\n{\n        msg.payload = 'Value under 500';\n        msg.topic = 'Alarm';\n        return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":460,"y":960,"wires":[["5c52b845.9f7ea8","cf430d54.2ff45"]]}]

Hi Felix, welcome to the forum!

Have you looked at the trigger node? It's part of the code nodes. Set it to send the existing msg object, wait for 10 minutes then send nothing.

See if that does what you want.

1 Like

It seems to work now. Thank you so much honestly, I struggled like 8 hours with this issue and tried so much (mainly new import nodes and solving it with javascript). Amazing that I found help here so quickly. Have a great time and thanks again!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.