Hi All,
I am very new to Nodered world and was trying to create some POC to handle request and send response through mqtt in/out node and I am able to handle the same. The flow which I have created is able to handle for single device at a time. Now, I want to understand if there is N number of device and the user send the request then how will it be handle.
In my POC I am trying to ON/OFF an AC device by sending JSON data. The flow which I created it works for one device at a time. Now, I want to send request for multiple device at the same time.
For example: One user has three AC (AC1U1, AC2U1, AC3U1) and another user too has three AC AC1U2, AC2U2, AC3U2. Now, user one has set a request to start the AC at 9 PM and second user send request to start at 10 PM. Do I need to write the flow for each device or same flow can handle the same. Please check and suggest.
[
{
"id": "49e6f074fb16bdb4",
"type": "mqtt in",
"z": "ddcae172591d116c",
"name": "On User Change Settings",
"topic": "ON_CLIENT_REQUEST",
"qos": "0",
"datatype": "auto-detect",
"broker": "aa80a314f5561ca3",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 130,
"y": 100,
"wires": [
[
"0da4788c90498bad",
"9fbc09c2c5510221"
]
]
},
{
"id": "f0aad6a7fcb8ac98",
"type": "switch",
"z": "ddcae172591d116c",
"name": "Check Timer include",
"property": "payload.includeTimer",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "true",
"vt": "str"
},
{
"t": "eq",
"v": "false",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 160,
"y": 300,
"wires": [
[
"d676cf2b058379f4",
"f3f32edc18225eec"
],
[
"aeab5e7c5e72b05d",
"eb22332c24630ad9"
]
]
},
{
"id": "d676cf2b058379f4",
"type": "switch",
"z": "ddcae172591d116c",
"name": "Check Sleep Time enable",
"property": "payload.sleep",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "true",
"vt": "str"
},
{
"t": "eq",
"v": "false",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 470,
"y": 180,
"wires": [
[
"ef8ead052f942954"
],
[
"641f75f3d6f39313"
]
]
},
{
"id": "f3f32edc18225eec",
"type": "switch",
"z": "ddcae172591d116c",
"name": "Check On Time enable",
"property": "payload.timerOn",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "true",
"vt": "str"
},
{
"t": "eq",
"v": "false",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 460,
"y": 420,
"wires": [
[
"8ffdbf223e0b989f"
],
[
"ad5d483df5d5486c"
]
]
},
{
"id": "ef8ead052f942954",
"type": "function",
"z": "ddcae172591d116c",
"name": "Set Delay for sleep time",
"func": "\nmsg.payload.state = \"false\"\nmsg.payload.temp = \"0\"\nmsg.payload.vSwing = \"false\" \nmsg.payload.hSwing = \"false\" \nmsg.payload.timerOn = \"false\" \nmsg.payload.speed = \"0\" \n//msg.payload. = \n\nreturn {\n payload: msg.payload, \n delay: msg.payload.sleepTime || 0,\n}\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 770,
"y": 220,
"wires": [
[
"4d3dcaf8d4fae686"
]
]
},
{
"id": "4a3ad5ef5a19d085",
"type": "debug",
"z": "ddcae172591d116c",
"name": "Set On Time Debug",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1290,
"y": 380,
"wires": []
},
{
"id": "aeab5e7c5e72b05d",
"type": "mqtt out",
"z": "ddcae172591d116c",
"name": "Update New Settings To Device",
"topic": "NEW_DEVICE_SETTINGS",
"qos": "",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "aa80a314f5561ca3",
"x": 1330,
"y": 300,
"wires": []
},
{
"id": "0da4788c90498bad",
"type": "function",
"z": "ddcae172591d116c",
"name": "Check any timer is enable",
"func": "msg.payload.includeTimer = msg.payload.sleepTime > 0 || msg.payload.onTime > 0 ? \"true\": \"false\"\nmsg.includeTimer = msg.payload.sleepTime > 0 || msg.payload.onTime > 0 ? \"true\": \"false\"\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 170,
"y": 180,
"wires": [
[
"f0aad6a7fcb8ac98"
]
]
},
{
"id": "ad5d483df5d5486c",
"type": "debug",
"z": "ddcae172591d116c",
"name": "No On Time set",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 480,
"y": 340,
"wires": []
},
{
"id": "641f75f3d6f39313",
"type": "debug",
"z": "ddcae172591d116c",
"name": "No Sleep Time ",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 480,
"y": 260,
"wires": []
},
{
"id": "4d3dcaf8d4fae686",
"type": "delay",
"z": "ddcae172591d116c",
"name": "Set Sleep Time",
"pauseType": "delayv",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 1000,
"y": 220,
"wires": [
[
"aeab5e7c5e72b05d",
"dc9a9723a4ddbd59"
]
]
},
{
"id": "8ffdbf223e0b989f",
"type": "function",
"z": "ddcae172591d116c",
"name": "Set delay for on time",
"func": "\nreturn {\n payload: msg.payload, \n delay: msg.payload.onTime || 0\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 760,
"y": 380,
"wires": [
[
"3d636fb0cc77a343"
]
]
},
{
"id": "3d636fb0cc77a343",
"type": "delay",
"z": "ddcae172591d116c",
"name": "Set On Time",
"pauseType": "delayv",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 970,
"y": 380,
"wires": [
[
"4a3ad5ef5a19d085",
"aeab5e7c5e72b05d"
]
]
},
{
"id": "eb22332c24630ad9",
"type": "debug",
"z": "ddcae172591d116c",
"name": "No Sleep/On Time Set",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 460,
"y": 500,
"wires": []
},
{
"id": "dc9a9723a4ddbd59",
"type": "debug",
"z": "ddcae172591d116c",
"name": "Set Sleep Time Debug",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1300,
"y": 220,
"wires": []
},
{
"id": "9fbc09c2c5510221",
"type": "mqtt out",
"z": "ddcae172591d116c",
"name": "Notify Request Received",
"topic": "REQUEST_RECV_CONFIRMATION",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "aa80a314f5561ca3",
"x": 470,
"y": 100,
"wires": []
},
{
"id": "aa80a314f5561ca3",
"type": "mqtt-broker",
"name": "Testing local host",
"broker": "broker.emqx.io",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]