Hello All,
I need to trigger an alert if the element zero in the array is less than -3, I created a function but it is not displaying the alert. What I'm doing wrong? Thank you all.
[
{
"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": [
[
"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": 800,
"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": 1070,
"y": 200,
"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": 320,
"wires": [
[
"f42e3850419a1abf"
]
]
},
{
"id": "bee42052adfe9674",
"type": "function",
"z": "0685c3c587aa4084",
"name": "triggerAlarm",
"func": "var payload=msg.payload[0].IA;\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 return msg;\n}\nif (payload<=-3 && alarm_flag)\n{\n alarm_flag=false;\n msg.alarm=0;\n context.set(\"alarm_flag\",alarm_flag);\n return msg;\n}\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 870,
"y": 440,
"wires": [
[
"66c6aff13893e03c"
]
]
},
{
"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
}
]