Hello everyone, I have a flow that is supposed to send me a WhatsApp message via "CallMeBot" when there is an inequality between two nodes
But in practice I can't get it to work even though I checked the API KEY and it works, and the join node also outputs an array Something in the function doesn't work for me....
[
{
"id": "node1",
"type": "inject",
"z": "flow1",
"name": "Node 1 Value",
"props": [
{
"p": "payload",
"v": "{\"name\": \"Sensor A\", \"value\": 50}",
"vt": "json"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"wires": [["joinNode"]]
},
{
"id": "node2",
"type": "inject",
"z": "flow1",
"name": "Node 2 Value",
"props": [
{
"p": "payload",
"v": "{\"name\": \"Sensor B\", \"value\": 40}",
"vt": "json"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"wires": [["joinNode"]]
},
{
"id": "joinNode",
"type": "join",
"z": "flow1",
"name": "Join Sensor Data",
"mode": "custom",
"build": "array",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"timeout": "",
"count": "2",
"wires": [["functionNode"]]
},
{
"id": "functionNode",
"type": "function",
"z": "flow1",
"name": "Compare & Alert",
"func": "let node1 = msg.payload[0];\nlet node2 = msg.payload[1];\n\nlet node1Value = node1.value;\nlet node2Value = node2.value;\n\nlet node1Name = node1.name || \"Node 1\";\nlet node2Name = node2.name || \"Node 2\";\n\nlet currentDifference = Math.abs(node1Value - node2Value);\nlet threshold = 10;\nlet previousDifference = context.get(\"previousDifference\") || currentDifference;\nlet differenceChange = Math.abs(currentDifference - previousDifference);\n\nif (differenceChange >= threshold) {\n let alertMessage = `ā ļø Alert! Significant change detected!\\nš Node: ${node1Name} vs. ${node2Name}\\nš¢ Previous Difference: ${previousDifference}\\nš¢ Current Difference: ${currentDifference}\\nš Change: ${differenceChange}`;\n \n msg.payload = {\n url: \"https://api.callmebot.com/whatsapp.php?phone=+1234567890&text=\" + encodeURIComponent(alertMessage) + \"&apikey=YOUR_API_KEY\",\n method: \"GET\"\n };\n \n context.set(\"previousDifference\", currentDifference);\n return msg;\n}\nreturn null;",
"outputs": 1,
"noerr": 0,
"wires": [["httpRequestNode"]]
},
{
"id": "httpRequestNode",
"type": "http request",
"z": "flow1",
"name": "Send CallMeBot Alert",
"method": "GET",
"ret": "txt",
"paytoqs": "query",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 500,
"y": 200,
"wires": [["debugNode"]]
},
{
"id": "debugNode",
"type": "debug",
"z": "flow1",
"name": "Debug Response",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 700,
"y": 200,
"wires": []
}
]