# Alarm over email

**URL:** https://discourse.nodered.org/t/alarm-over-email/42471
**Category:** General
**Created:** [11 March 2021 10:41 UTC](https://discourse.nodered.org/t/alarm-over-email/42471 "2021-03-11T10:41:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Madhumati](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@Madhumati](https://discourse.nodered.org/u/Madhumati)
#### Post date: [11 March 2021 10:41 UTC](https://discourse.nodered.org/t/alarm-over-email/42471/1 "2021-03-11T10:41:27Z")

</div>

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?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/8606604654d2d3398b9de851fdea6909898ca5a0.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/c/7c8daf4afcf8d13a0d2cdbc615e42ca911d07102.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c9e918d81cc71341017522a4cd644180ef1c5bc.png)

```auto
[{"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

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [11 March 2021 10:57 UTC](https://discourse.nodered.org/t/alarm-over-email/42471/2 "2021-03-11T10:57:08Z")

</div>

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:

```auto
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` )

---

<div class="post-metadata">

### Author: ![Madhumati](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@Madhumati](https://discourse.nodered.org/u/Madhumati)
#### Post date: [11 March 2021 12:07 UTC](https://discourse.nodered.org/t/alarm-over-email/42471/3 "2021-03-11T12:07:48Z")

</div>

thanks . It worked now through switch node.

Br  
Madhumati

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [25 March 2021 12:07 UTC](https://discourse.nodered.org/t/alarm-over-email/42471/4 "2021-03-25T12:07:51Z")

</div>

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