Alarm over email

Hello,

we are trying to generate alarms in case distnace sensor shows out of range value & then alarm message to be sent to client over email.
attached is our flow.
In this case , alarm gets generated & email is also sent. BUT , for normal /correct sensor reading also, email is sent . So we get lot of emails. we just want email in case of Alarm condition.
what should be the wrong in our flow?



[{"id":"3fbea8a9.e88e78","type":"OpcUa-Client","z":"a0bec44d.96a628","endpoint":"98409f5a.8549b","action":"read","deadbandtype":"a","deadbandvalue":1,"time":10,"timeUnit":"s","certificate":"n","localfile":"","securitymode":"None","securitypolicy":"None","name":"","x":320,"y":100,"wires":[["ab5e2c91.37cac","23473bba.74cf64"]]},{"id":"7cbb02e9.8570fc","type":"inject","z":"a0bec44d.96a628","name":"ProcessData","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ns=4;s=|var|CODESYS Control for Raspberry Pi SL.Application.PLC_PRG.uiOutput","payload":"","payloadType":"date","x":110,"y":100,"wires":[["3fbea8a9.e88e78"]]},{"id":"ab5e2c91.37cac","type":"debug","z":"a0bec44d.96a628","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":100,"wires":[]},{"id":"23473bba.74cf64","type":"function","z":"a0bec44d.96a628","name":"","func":"msg.topic = \"Alarm IOT Gateway\";\nif(msg.payload>=400)\n{\n    msg.payload=\"Alarm Generated\" + msg.payload;\n}\nelse\n{\n    \n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":260,"wires":[["8ef1c227.ee088","e97cbf17.9d74f"]]},{"id":"8ef1c227.ee088","type":"e-mail","z":"a0bec44d.96a628","server":"smtp.gmail.com","port":"465","secure":true,"tls":false,"name":"dsongra@hilscher.in","dname":"alarm","x":690,"y":240,"wires":[]},{"id":"e97cbf17.9d74f","type":"debug","z":"a0bec44d.96a628","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":180,"wires":[]},{"id":"98409f5a.8549b","type":"OpcUa-Endpoint","endpoint":"opc.tcp://192.168.1.107:4840","secpol":"None","secmode":"None","login":false}]

please help

BR
Madhumati

since you are always sending the output of the function node to the email node, it will always send an email.

From the looks of your function node:

msg.topic = "Alarm IOT Gateway";
if(msg.payload>=400)
{
    msg.payload="Alarm Generated" + msg.payload;
}
else
{
    
}
return msg;

I assume you don't have much javascript experience. You should really take a Javascript tutorial.

If this is all the logic you are going to have, you could easily use a switch to test the condition and a change node to create the message with the addition of 'Alarm Generated' (use a jsonata expression 'Alarm Generated ' & payload )

thanks . It worked now through switch node.

Br
Madhumati

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