Hi all,
Looking for some help in routing messages. I have a function node that is manipulating data pulled from an API every 60 seconds and doing some if/else statements to determine output and calculate when a relay should close or open. Once a condition is met the message is routed to trigger either relay A or B. If there is second concurrent event and relay B is triggered then relay C triggers. Relay A will only trigger on a certain program. Whereas relays B&C can be triggered concurrently. The issue I'm running into is once the first event ends on relay B, the second event "moves" from relay C to relay B. The events all have a unique ID associated with them and I'm thinking I can use that to route the message but not really sure how to implement it
Test flow below to inject some values into the function node.
[
{
"id": "831a451fa9d84779",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": ""
},
{
"id": "c9f6bc2d8b2f9ec2",
"type": "inject",
"z": "831a451fa9d84779",
"name": "Test Event 2 Start",
"props": [
{
"p": "payload.start2",
"v": "1661431320000",
"vt": "num"
},
{
"p": "payload.end2",
"v": "1661608000000",
"vt": "num"
},
{
"p": "payload.program2",
"v": "DD",
"vt": "str"
},
{
"p": "payload.EventID2",
"v": "10098",
"vt": "num"
},
{
"p": "payload.start3",
"v": "",
"vt": "str"
},
{
"p": "payload.end3",
"v": "",
"vt": "str"
},
{
"p": "payload.program3",
"v": "",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 310,
"y": 300,
"wires": [
[
"0eafebad2a3b3ac0"
]
]
},
{
"id": "5d147fbb54b3c9d3",
"type": "debug",
"z": "831a451fa9d84779",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "trig",
"targetType": "msg",
"statusVal": "payload.program2",
"statusType": "auto",
"x": 800,
"y": 280,
"wires": []
},
{
"id": "c29ed9ffc09a4d48",
"type": "debug",
"z": "831a451fa9d84779",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "trig2",
"targetType": "msg",
"statusVal": "payload.program2",
"statusType": "auto",
"x": 800,
"y": 340,
"wires": []
},
{
"id": "cc5cfc9f021caaae",
"type": "debug",
"z": "831a451fa9d84779",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "trig3",
"targetType": "msg",
"statusVal": "payload.program2",
"statusType": "auto",
"x": 800,
"y": 400,
"wires": []
},
{
"id": "c916c60f52392d5d",
"type": "inject",
"z": "831a451fa9d84779",
"name": "Both Events End",
"props": [
{
"p": "payload.start2",
"v": "",
"vt": "num"
},
{
"p": "payload.end2",
"v": "",
"vt": "num"
},
{
"p": "payload.program2",
"v": "",
"vt": "str"
},
{
"p": "payload.EventID2",
"v": "",
"vt": "num"
},
{
"p": "payload.start3",
"v": "",
"vt": "num"
},
{
"p": "payload.end3",
"v": "",
"vt": "num"
},
{
"p": "payload.program3",
"v": "",
"vt": "str"
},
{
"p": "payload.EventID3",
"v": "",
"vt": "num"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 300,
"y": 420,
"wires": [
[
"0eafebad2a3b3ac0"
]
]
},
{
"id": "0eafebad2a3b3ac0",
"type": "function",
"z": "831a451fa9d84779",
"name": "Test Func",
"func": "// Variable for UTC conversion\nvar UTC = \"UTC\"\nvar TimeString1 = msg.payload.start\nvar TimeString2 = msg.payload.start2\nvar TimeString3 = msg.payload.start3\n\nmsg.trig = msg.payload.trig\nmsg.trig2 = msg.payload.trig2\nmsg.trig3 = msg.payload.trig3\n\n//EPOCH Conversion\nmsg.payload.currentTime = new Date().getTime()\n\n\n//input 1 PRD\nif (typeof msg.payload.start == 'undefined') {\n msg.payload.start = 32524027790000;\n} else {\n msg.payload.start = msg.payload.start\n msg.payload.start = TimeString1.concat(\" \", UTC)\n}\n\nmsg.payload.start = new Date(msg.payload.start).getTime()\nmsg.payload.startconv = msg.payload.start - (24 * 60 * 60 * 1000);\nmsg.payload.end = new Date(msg.payload.end).getTime()\n\n//input 2 DD\nif (typeof msg.payload.start2 == 'undefined') {\n msg.payload.start2 = 32524027790000;\n} else {\n msg.payload.start2 = msg.payload.start2\n // msg.payload.start2 = TimeString2.concat(\" \", UTC)\n}\n\nmsg.payload.start2 = new Date(msg.payload.start2).getTime()\nmsg.payload.startconv2 = msg.payload.start2 - (24*60*60*1000);\nmsg.payload.end2 = new Date(msg.payload.end2).getTime()\n\n// input 3 DD(extra)\nif (typeof msg.payload.start3 == 'undefined') {\n msg.payload.start3 = 32524027790000;\n} else {\n msg.payload.start3 = msg.payload.start2\n // msg.payload.start3 = TimeString3.concat(\" \", UTC)\n}\n\nmsg.payload.start3 = new Date(msg.payload.start3).getTime()\nmsg.payload.startconv3 = msg.payload.start3 - (24 * 60 * 60 * 1000);\nmsg.payload.end3 = new Date(msg.payload.end3).getTime()\n\n//Account for null objects\nif (typeof msg.payload.EventID1 == 'undefined') {\n msg.payload.EventID1 = 0\n} else {\n msg.payload.EventID1 = msg.payload.EventID1\n}\nif (typeof msg.payload.EventID2 == 'undefined') {\n msg.payload.EventID2 = 0\n} else {\n msg.payload.EventID2 = msg.payload.EventID2\n}\nif (typeof msg.payload.EventID3 == 'undefined') {\n msg.payload.EventID3 = 0\n} else {msg.payload.EventID3 = msg.payload.EventID3\n}\n//Event trigger logic\nif (msg.payload.program == \"PRD\" || msg.payload.program2 == \"PRD\" || msg.payload.program3 == \"PRD\") {\n msg.trig = 1;\n} else {\n msg.trig = 0;\n}\nif (msg.payload.currentTime > msg.payload.startconv && msg.payload.program == \"DD\" ||\n msg.payload.currentTime > msg.payload.startconv2 && msg.payload.program2 == \"DD\" ||\n msg.payload.currentTime > msg.payload.startconv3 && msg.payload.program3 == \"DD\") {\n msg.trig2 = 1;\n} else {\n msg.trig2 = 0;\n}\nif (msg.payload.currentTime > msg.payload.startconv && msg.payload.program == \"DD\" && msg.trig2 == 1 && msg.payload.EventID2 != 0 ||\n msg.payload.currentTime > msg.payload.startconv2 && msg.payload.program2 == \"DD\" && msg.trig2 == 1 && msg.payload.EventID3 != 0||\n msg.payload.currentTime > msg.payload.startconv3 && msg.payload.program3 == \"DD\" && msg.trig2 == 1 && msg.payload.EventID1 != 0) {\n msg.trig3 = 1;\n} else {\n msg.trig3 = 0;\n}\nreturn msg;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 560,
"y": 340,
"wires": [
[
"5d147fbb54b3c9d3",
"c29ed9ffc09a4d48",
"cc5cfc9f021caaae",
"dfc9b8feb229d577"
]
]
},
{
"id": "dfc9b8feb229d577",
"type": "debug",
"z": "831a451fa9d84779",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload.start2",
"statusType": "auto",
"x": 810,
"y": 460,
"wires": []
},
{
"id": "27636da3ca968676",
"type": "inject",
"z": "831a451fa9d84779",
"name": "Test Event 2 & 3 Start",
"props": [
{
"p": "payload.start2",
"v": "1661431320000",
"vt": "num"
},
{
"p": "payload.end2",
"v": "1961608000000",
"vt": "num"
},
{
"p": "payload.program2",
"v": "DD",
"vt": "str"
},
{
"p": "payload.EventID2",
"v": "10098",
"vt": "num"
},
{
"p": "payload.start3",
"v": "1962066881",
"vt": "str"
},
{
"p": "payload.end3",
"v": "1962099999",
"vt": "str"
},
{
"p": "payload.program3",
"v": "DD",
"vt": "str"
},
{
"p": "payload.EventID3",
"v": "12345",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 320,
"y": 340,
"wires": [
[
"0eafebad2a3b3ac0"
]
]
},
{
"id": "54236686933e9762",
"type": "inject",
"z": "831a451fa9d84779",
"name": "Test Event 2 End & 3 Start",
"props": [
{
"p": "payload.start2",
"v": "",
"vt": "num"
},
{
"p": "payload.end2",
"v": "",
"vt": "num"
},
{
"p": "payload.program2",
"v": "",
"vt": "str"
},
{
"p": "payload.EventID2",
"v": "",
"vt": "num"
},
{
"p": "payload.start3",
"v": "1962066881",
"vt": "str"
},
{
"p": "payload.end3",
"v": "1962099999",
"vt": "str"
},
{
"p": "payload.program3",
"v": "DD",
"vt": "str"
},
{
"p": "payload.EventID3",
"v": "12345",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 330,
"y": 380,
"wires": [
[
"0eafebad2a3b3ac0"
]
]
}
]