Hello!
I want to send a notification by email but I'm receiving the whole payload by email instead of the message I wrote in the function. If the alarm = 1 then send the email notification. The else part should do nothing! Thank you!
Function Notification
var temp=msg.payload
msg.to="c9230b70491a79+1@inbox.mailtrap.io";
msg.from="c9230b70491a79+1@inbox.mailtrap.io";
var d = new Date();
var message="";
if(msg.alarm)
{
msg.alarm=1;
message= " High temperature Alarm check device";
}
else
{
message= " NONE ";
}
return msg;
NODES
[
{
"id": "181547422299f50a",
"type": "inject",
"z": "0685c3c587aa4084",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "start",
"payload": "1",
"payloadType": "num",
"x": 130,
"y": 320,
"wires": [
[
"40b40302d111638e",
"c32fdfcd6980d88b"
]
]
},
{
"id": "f42e3850419a1abf",
"type": "csv",
"z": "0685c3c587aa4084",
"name": "",
"sep": ",",
"hdrin": true,
"hdrout": "",
"multi": "mult",
"ret": "\\n",
"temp": "",
"skip": "0",
"strings": true,
"include_empty_strings": false,
"include_null_values": false,
"x": 550,
"y": 280,
"wires": [
[
"845aa6dfe380c903"
]
]
},
{
"id": "845aa6dfe380c903",
"type": "function",
"z": "0685c3c587aa4084",
"name": "graph generate",
"func": "let payload=msg.payload;\n\nlet data = [[],[]];\nfor(let i=0;i<payload.length;i++){\n let time = new Date(\"1970-01-01T\"+payload[i].TIME.replace(\".\",\":\").padEnd(8,\"0\"));\n data[0].push({\"x\": time, \"y\": payload[i].IA});\n data[1].push({\"x\": time, \"y\": payload[i].IB});\n}\nlet labels = msg.columns.split(\",\").slice(1);\n\nmsg.payload=[{\n\"series\": labels,\n\"data\":data,\n\"labels\": labels\n}];\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 760,
"y": 320,
"wires": [
[
"980b469730d08203",
"66c6aff13893e03c",
"bee42052adfe9674"
]
]
},
{
"id": "980b469730d08203",
"type": "ui_chart",
"z": "0685c3c587aa4084",
"name": "",
"group": "2ac8e3fa.8b8584",
"order": 5,
"width": 0,
"height": 0,
"label": "Time Graph Test",
"chartType": "line",
"legend": "true",
"xformat": "HH:mm:ss",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "",
"ymax": "",
"removeOlder": "10",
"removeOlderPoints": "",
"removeOlderUnit": "3600",
"cutout": 0,
"useOneColor": false,
"useUTC": false,
"colors": [
"#400000",
"#ff8000",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"outputs": 1,
"useDifferentColor": false,
"className": "",
"x": 880,
"y": 140,
"wires": [
[]
]
},
{
"id": "66c6aff13893e03c",
"type": "debug",
"z": "0685c3c587aa4084",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1110,
"y": 160,
"wires": []
},
{
"id": "c32fdfcd6980d88b",
"type": "template",
"z": "0685c3c587aa4084",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "TIME,IA,IB\n09:21.3,-3.984,2.188\n09:22.3,-2.984,1.406\n09:23.3,-1.75,0.703",
"output": "str",
"x": 360,
"y": 280,
"wires": [
[
"f42e3850419a1abf"
]
]
},
{
"id": "bee42052adfe9674",
"type": "function",
"z": "0685c3c587aa4084",
"name": "triggerAlarm",
"func": "var payload=msg.payload[0].data[0][0].y;\nvar alarm_flag=context.get(\"alarm_flag\");\nif(typeof alarm_flag==\"undefined\")\nalarm_flag=false;\n\nif (payload<-3 && !alarm_flag)\n{\n alarm_flag=true;\n msg.alarm=1;\n context.set(\"alarm_flag\",alarm_flag);\n}\nelse if (payload<=-3 && alarm_flag)\n{\n alarm_flag=false;\n msg.alarm=0;\n context.set(\"alarm_flag\",alarm_flag);\n}\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 870,
"y": 440,
"wires": [
[
"e2077f8173696fa2",
"5dd6b786f427ce25"
]
]
},
{
"id": "5dd6b786f427ce25",
"type": "debug",
"z": "0685c3c587aa4084",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1110,
"y": 340,
"wires": []
},
{
"id": "58782dda1425ada3",
"type": "e-mail",
"z": "0685c3c587aa4084",
"server": "smtp.mailtrap.io",
"port": "2525",
"secure": false,
"tls": false,
"name": "c9230b70491a79+1@inbox.mailtrap.io",
"dname": "Email Alert",
"x": 850,
"y": 720,
"wires": []
},
{
"id": "e2077f8173696fa2",
"type": "function",
"z": "0685c3c587aa4084",
"name": "functionNotification",
"func": "var temp=msg.payload\nmsg.to=\"c9230b70491a79+1@inbox.mailtrap.io\";\nmsg.from=\"c9230b70491a79+1@inbox.mailtrap.io\";\n\nvar d = new Date();\nvar message=\"\";\nif(msg.alarm)\n{\n msg.alarm=1;\n message= \" High temperature Alarm \";\n}\nelse\n{\n message= \" All good \";\n}\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 890,
"y": 580,
"wires": [
[
"58782dda1425ada3"
]
]
},
{
"id": "2ac8e3fa.8b8584",
"type": "ui_group",
"name": "Default",
"tab": "ebb1ed1c.5ebe2",
"order": 1,
"disp": true,
"width": "12",
"collapse": false,
"className": ""
},
{
"id": "ebb1ed1c.5ebe2",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]