S7node - fonction node - Gmail alerts

any helps me to get this node, am trying to set a fonction node that if my input variable cross 400 send me an email and what i received from email is this any one can help me to fix this flow
gmailnode

Hi Tadi,

Can you post your flow ? (delete your username and password from email configuration)
What you have in your function node .. looks correct.

Maybe what you are sending to your function node is a string and the if statement fails ?
Do you get any errors ?

And the configuration of you email must be correct since your received some emails. What is the problem?

flows.json (9.7 KB)
here is my flow

If the payload is not greater than 400 your function sends on the original message, is that what you want? If not then move the return statement inside the braces.

nicely spot

I only want from fonction to send message when it cross 400

Did you try what Colin suggested ?

The way you have your function now. With return msg; outside the if statement { } it always sends a message / email. even if the payload is > than 400
return msg; should be inside the if { }

Its works fine now but still have an issue that i want to send it once how to?

you can use a Trigger node between your function and email nodes,
to stop more messages being sent for x amount of time.

Example 1 minute :

Let me try to help you:

1st: I do not recommend you to start using function for such an easy task. You can simply use the standard Node-RED nodes for that. Use the "switch" node to check if the topic is the expected one, and then another "switch" to check the value, like this:

[{"id":"e4b04056.2c977","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"83e054d5.6dfb98","type":"switch","z":"e4b04056.2c977","name":"Check topic","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Default : Surtension","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":290,"y":380,"wires":[["9983d239.c3bef"]]},{"id":"9983d239.c3bef","type":"switch","z":"e4b04056.2c977","name":"Check value","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"400","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":500,"y":380,"wires":[["9630c2cd.77661"]]},{"id":"9630c2cd.77661","type":"template","z":"e4b04056.2c977","name":"e-mail text","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"ALERT! Value is higher than expected: {{payload}} !","output":"str","x":760,"y":380,"wires":[[]]}]

2nd If you want to send an alert only when the value reach a number >= 400 and then stop sending, you will need to store a variable that tells the flow which state you are at the moment, then you will need to use "flow variables" like in this example below

[{"id":"e4b04056.2c977","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"83e054d5.6dfb98","type":"switch","z":"e4b04056.2c977","name":"Check topic","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Default : Surtension","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":130,"y":320,"wires":[["9983d239.c3bef"]]},{"id":"9983d239.c3bef","type":"switch","z":"e4b04056.2c977","name":"Check value","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"400","vt":"num"},{"t":"lt","v":"400","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":320,"wires":[["b45a7d15.6c4e3"],["e4931870.ecc448"]]},{"id":"9630c2cd.77661","type":"template","z":"e4b04056.2c977","name":"e-mail text","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"ALERT! Value is higher than expected: {{payload}} !","output":"str","x":710,"y":300,"wires":[[]]},{"id":"ed3db503.09a3b8","type":"change","z":"e4b04056.2c977","name":"Set alert_sent","rules":[{"t":"set","p":"alert_sent","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":260,"wires":[[]]},{"id":"b45a7d15.6c4e3","type":"switch","z":"e4b04056.2c977","name":"Check alert_sent","property":"alert_sent","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":300,"wires":[["ed3db503.09a3b8","9630c2cd.77661"]]},{"id":"e4931870.ecc448","type":"change","z":"e4b04056.2c977","name":"Reset alert_sent","rules":[{"t":"set","p":"alert_sent","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":340,"wires":[[]]}]

thank you so much i have tried the first one but it wont work
as i see i have compare the value first and if he passed 400 the message wil be sent to email

This is not what you want ? ... to send an email at least once when value is > 400 and after that no more emails until the Trigger time expires. so your inbox will not be flooded with emails for X amount of time.

yes this what i want am trying now your fonction and it seems that work

by the way i see you have 3 functions .. you have to put Triggers for all 3