Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- {
- "id": "47a23c1e32bc602e",
- "type": "tab",
- "label": "Traffic Light",
- "disabled": false,
- "info": "",
- "env": []
- },
- {
- "id": "6790a5e816e67fe8",
- "type": "junction",
- "z": "47a23c1e32bc602e",
- "x": 400,
- "y": 180,
- "wires": [
- [
- "cee5cbdc5de38a41"
- ]
- ]
- },
- {
- "id": "cee5cbdc5de38a41",
- "type": "function",
- "z": "47a23c1e32bc602e",
- "name": "",
- "func": "const DEFAULT_COLOR = \"grey\";\nlet statusColor = \"grey\"; // default color\n\nlet value = msg.payload;\n\n//Create a new messages and assume all signals is off.\nlet redMsg = {\n payload : \"off\",\n color : \"red\",\n value : value\n };\n\nlet yellowMsg = {\n payload: \"off\",\n color: \"yellow\",\n value: value\n};\n\nlet greenMsg = {\n payload: \"off\",\n color: \"green\",\n value: value\n};\n\n\n\n//Evaluate\nif (value >= 920) {\n redMsg.payload.red = \"on\";\n statusColor = \"red\";\n}\nelse if (value >= 800) {\n yellowMsg.payload = \"on\";\n statusColor = \"yellow\";\n}\nelse if (value >= 150) {\n greenMsg.payload = \"on\";\n statusColor = \"green\";\n\n}\n\n\nnode.status({ fill: statusColor,shape:\"dot\",text:\"Value: \" + value});\n\nreturn [redMsg, yellowMsg, greenMsg];",
- "outputs": 3,
- "timeout": "",
- "noerr": 0,
- "initialize": "",
- "finalize": "",
- "libs": [],
- "x": 500,
- "y": 180,
- "wires": [
- [
- "e9f6272924c0229a"
- ],
- [
- "f041dc561b4347fa"
- ],
- [
- "30dc6f071c6b04ff"
- ]
- ],
- "inputLabels": [
- "Payload = Value"
- ],
- "outputLabels": [
- "Red",
- "Yellow",
- "Green"
- ]
- },
- {
- "id": "770bb79258022b7e",
- "type": "inject",
- "z": "47a23c1e32bc602e",
- "name": "",
- "props": [
- {
- "p": "payload"
- },
- {
- "p": "topic",
- "vt": "str"
- }
- ],
- "repeat": "",
- "crontab": "",
- "once": false,
- "onceDelay": 0.1,
- "topic": "",
- "payload": "101",
- "payloadType": "num",
- "x": 150,
- "y": 120,
- "wires": [
- [
- "6790a5e816e67fe8"
- ]
- ]
- },
- {
- "id": "39c24b88990ef1c2",
- "type": "inject",
- "z": "47a23c1e32bc602e",
- "name": "",
- "props": [
- {
- "p": "payload"
- },
- {
- "p": "topic",
- "vt": "str"
- }
- ],
- "repeat": "",
- "crontab": "",
- "once": false,
- "onceDelay": 0.1,
- "topic": "",
- "payload": "450",
- "payloadType": "num",
- "x": 150,
- "y": 160,
- "wires": [
- [
- "6790a5e816e67fe8"
- ]
- ]
- },
- {
- "id": "c3efd8bbd9afc141",
- "type": "inject",
- "z": "47a23c1e32bc602e",
- "name": "",
- "props": [
- {
- "p": "payload"
- },
- {
- "p": "topic",
- "vt": "str"
- }
- ],
- "repeat": "",
- "crontab": "",
- "once": false,
- "onceDelay": 0.1,
- "topic": "",
- "payload": "850",
- "payloadType": "num",
- "x": 150,
- "y": 200,
- "wires": [
- [
- "6790a5e816e67fe8"
- ]
- ]
- },
- {
- "id": "e523ae55e8502d28",
- "type": "inject",
- "z": "47a23c1e32bc602e",
- "name": "",
- "props": [
- {
- "p": "payload"
- },
- {
- "p": "topic",
- "vt": "str"
- }
- ],
- "repeat": "",
- "crontab": "",
- "once": false,
- "onceDelay": 0.1,
- "topic": "",
- "payload": "950",
- "payloadType": "num",
- "x": 150,
- "y": 240,
- "wires": [
- [
- "6790a5e816e67fe8"
- ]
- ]
- },
- {
- "id": "e9f6272924c0229a",
- "type": "debug",
- "z": "47a23c1e32bc602e",
- "name": "dbg Red",
- "active": true,
- "tosidebar": true,
- "console": false,
- "tostatus": false,
- "complete": "true",
- "targetType": "full",
- "statusVal": "",
- "statusType": "auto",
- "x": 700,
- "y": 140,
- "wires": []
- },
- {
- "id": "f041dc561b4347fa",
- "type": "debug",
- "z": "47a23c1e32bc602e",
- "name": "dbg Yellow",
- "active": true,
- "tosidebar": true,
- "console": false,
- "tostatus": false,
- "complete": "true",
- "targetType": "full",
- "statusVal": "",
- "statusType": "auto",
- "x": 710,
- "y": 180,
- "wires": []
- },
- {
- "id": "30dc6f071c6b04ff",
- "type": "debug",
- "z": "47a23c1e32bc602e",
- "name": "dbg Green",
- "active": true,
- "tosidebar": true,
- "console": false,
- "tostatus": false,
- "complete": "true",
- "targetType": "full",
- "statusVal": "",
- "statusType": "auto",
- "x": 710,
- "y": 220,
- "wires": []
- },
- {
- "id": "2a7ac1490adc17f2",
- "type": "function",
- "z": "47a23c1e32bc602e",
- "name": "Random 0 - 1000",
- "func": "const MIN_VAL = 0;\nconst MAX_VAL = 1000;\n\nmsg.payload = Math.round(Math.random()*(MAX_VAL - MIN_VAL) + MIN_VAL);\n\nnode.status({text: \"Value: \" + msg.payload});\nreturn msg;",
- "outputs": 1,
- "timeout": 0,
- "noerr": 0,
- "initialize": "",
- "finalize": "",
- "libs": [],
- "x": 350,
- "y": 300,
- "wires": [
- [
- "6790a5e816e67fe8"
- ]
- ]
- },
- {
- "id": "4551df0b59990fe3",
- "type": "inject",
- "z": "47a23c1e32bc602e",
- "name": "Random",
- "props": [
- {
- "p": "payload"
- },
- {
- "p": "topic",
- "vt": "str"
- }
- ],
- "repeat": "",
- "crontab": "",
- "once": false,
- "onceDelay": 0.1,
- "topic": "",
- "payload": "",
- "payloadType": "date",
- "x": 160,
- "y": 300,
- "wires": [
- [
- "2a7ac1490adc17f2"
- ]
- ]
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment