|
"initialize": "// Code added here will be run once\n// whenever the node is deployed.\nconst ROOM_DEVICE_JSON = `{\n\t\"class\": \"ROOM_DEVICE\",\n\t\"programType\": 5,\n\t\"functionList\": [],\n\t\"endClass\": true,\n\t\"implements\": [\"PROGRAM\"],\n\t\"inputs\": {\n\t\t\"roomT\":\t{\"id\":0, \"type\": \"temperature\"},\n\t\t\"rc21\": \t{\"id\":1, \"type\": \"rc21\"},\n\t\t\"floorT\": \t{\"id\":2, \"type\": \"temperature\"},\n\t\t\"wallT\": \t{\"id\":3, \"type\": \"temperature\"},\n\t\t\"humidity\":\t{\"id\":4, \"type\": \"humidity\"},\n\t\t\"CO2\": \t\t{\"id\":5, \"type\": \"onOff\"},\n\t\t\"presense\":\t{\"id\":6, \"type\": \"onOff\"}\n\t},\n\t\"outputs\": {\n\t\t\"floorValve\":\t{\"id\":0, \"type\": \"relay\"},\n\t\t\"radValve\":\t\t{\"id\":1, \"type\": \"relay\"},\n\t\t\"addValve\":\t\t{\"id\":2, \"type\": \"relay\"},\n\t\t\"floorSignal\":\t{\"id\":3, \"type\": \"PWM\"},\n\t\t\"radSignal\":\t{\"id\":4, \"type\": \"PWM\"},\n\t\t\"addSignal\":\t{\"id\":5, \"type\": \"PWM\"},\n\t\t\"ventilation\":\t{\"id\":6, \"type\": \"relay\"}\n\t},\n\t\"parameters\": {\n\t\t\"roomComfortTemperature\":\t{\"id\":1,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"roomReducedTemperature\":\t{\"id\":2,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"roomHysteresis\":\t\t\t{\"id\":3,\t\"encoding\":\"short10\",\t\"deprecated\":true,\t\"type\": \"temperature\"},\n\t\t\"relayPeriod\":\t\t\t\t{\"id\":4,\t\"encoding\":\"uint60K\",\t\"type\": \"minutes\"},\n\t\t\"responsibleCircuit1\":\t\t{\"id\":5,\t\"encoding\":\"ubyte\",\t\"type\": \"id\"},\n\t\t\"responsibleCircuit2\":\t\t{\"id\":6,\t\"encoding\":\"ubyte\",\t\"type\": \"id\"},\n\t\t\"responsibleCircuit3\":\t\t{\"id\":7,\t\"encoding\":\"ubyte\",\t\"type\": \"id\"},\n\t\t\"workMode\":\t\t\t\t\t{\"id\":8,\t\"encoding\":\"ubyte\", \"values\":{\"0\":\"Comfort\", \"1\":\"Economy\", \"2\":\"Schedule\", \"3\":\"Standby\"},\t\"type\": \"picklist\"},\n\t\t\"valveNormalState\":\t\t\t{\"id\":9,\t\"encoding\":\"ubyte\",\t\"type\": \"onOff\"},\n\t\t\"minimumFloorTemperature\":\t{\"id\":10,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"maximumFloorTemperature\":\t{\"id\":11,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"radiatorMinimumSignal\":\t{\"id\":12,\t\"encoding\":\"ubyte\",\t\"type\": \"%\"},\n\t\t\"roomDesiredTemperature\":\t{\"id\":13,\t\"encoding\":\"short10\", \"readOnly\":true,\t\"type\": \"temperature\"},\n\t\t\"relayPercentagePrimary\":\t{\"id\":14,\t\"encoding\":\"ubyte\", \"readOnly\":true,\t\"type\": \"%\"},\n\t\t\"relayPercentageSecondary\":\t{\"id\":15,\t\"encoding\":\"ubyte\", \"readOnly\":true,\t\"type\": \"%\"},\n\t\t\"outdoorTemperature\":\t\t{\"id\":16,\t\"encoding\":\"short10\", \"readOnly\":true,\t\"type\": \"temperature\"},\n\t\t\"relayPercentageAdditional\":\t{\"id\":17,\t\"encoding\":\"ubyte\", \"readOnly\":true,\t\"type\": \"%\"},\n\t\t\"circuit1Shift\":\t\t\t{\"id\":18,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"circuit2Shift\":\t\t\t{\"id\":19,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"circuit3Shift\":\t\t\t{\"id\":20,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"roomOffTemperature\":\t\t{\"id\":21,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"schedule\":\t\t\t\t\t{\"id\":22,\t\"encoding\":\"schedule1\"},\n\t\t\"floorRequiredTemperature\":\t{\"id\":23,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"currentFloorRequiredTemperature\":\t{\"id\":24,\t\"encoding\":\"short10\",\t\"type\": \"temperature\", \"readOnly\":true},\n\t\t\"wallRequiredTemperature\":\t{\"id\":25,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"currentWallRequiredTemperature\":\t{\"id\":26,\t\"encoding\":\"short10\",\t\"type\": \"temperature\", \"readOnly\":true},\n\t\t\"heatExtrication\":\t\t\t{\"id\":27,\t\"encoding\":\"ubyte\",\t\"type\": \"onOff\"},\n\t\t\"floorReducedTemperature\":\t{\"id\":28,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"wallReducedTemperature\":\t{\"id\":29,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"currentWorkModeStatus\":\t{\"id\":30,\t\"encoding\":\"ubyte\",\t\"type\": \"picklist\", \"values\":{\"0\":\"Comfort\", \"1\":\"Economy\", \"2\":\"ScheduleComfort\", \"3\":\"ScheduleEconomy\", \"4\":\"Standby\"}, \"readOnly\":true},\n\t\t\"ventilationCurcuit\":\t\t{\"id\":31,\t\"encoding\":\"ubyte\",\t\"type\": \"id\"},\n\t\t\"requiredHumidity\":\t\t\t{\"id\":32,\t\"encoding\":\"short10\",\t\"type\": \"humidity\"},\n\t\t\"poolCircuit\":\t\t\t\t{\"id\":33,\t\"encoding\":\"ubyte\",\t\"type\": \"id\"},\n\t\t\"poolTemperatureOffset\":\t{\"id\":34,\t\"encoding\":\"short10\",\t\"type\": \"temperature\"},\n\t\t\"schedule2\":\t\t\t\t{\"id\":35,\t\"encoding\":\"schedule2\"},\n\t\t\"location\":\t\t\t\t\t{\"id\":36,\t\"encoding\":\"ubyte\", \"type\": \"picklist\", \"values\": {\"24\": \"Room 5\", \"25\": \"Room 6\", \"26\": \"Room 7\", \"27\": \"Room 8\", \"20\": \"Room 1\", \"21\": \"Room 2\", \"22\": \"Room 3\", \"23\": \"Room 4\", \"28\": \"Room 9\", \"29\": \"Room 10\", \"1\": \"First floor\", \"0\": \"Ground floor\", \"3\": \"Hall\", \"2\": \"Attic\", \"5\": \"Dining room\", \"4\": \"Living room\", \"7\": \"Bathroom\", \"6\": \"Kitchen\", \"9\": \"Bedroom 2\", \"8\": \"Bedroom\", \"11\": \"Office\", \"10\": \"Bedroom 3\", \"13\": \"Nursery\", \"12\": \"Children's room\", \"15\": \"Corridor\", \"14\": \"Playroom\", \"17\": \"Shower\", \"16\": \"Bathroom 2\", \"19\": \"Office 2\", \"18\": \"Restroom\"}}\n\t}\n}`;\nlet PROGRAMS = flow.get(\"PROGRAMS\") || {};\nPROGRAMS[5] = JSON.parse(ROOM_DEVICE_JSON);\nflow.set(\"PROGRAMS\", PROGRAMS);\n\nlet C = {};\nC.PROGRAM = 1;\nC.SENSOR_N = 1;\nC.OUTPUT_N = 2;\nC.REMOTE_CONTROL = 22;\nC.GET_PARAMETER_VALUE = 1;\nC.SET_PARAMETER_VALUE = 2;\nflow.set(\"CONST\", C);", |
|
"func": "if (msg.topic.indexOf(\"/devices/sw \") !== 0) {\n return null;\n}\nlet a = \"/devices/sw \".length;\nlet b = msg.topic.indexOf(\" \", a) + 1;\nlet c = msg.topic.indexOf(\"/\", b);\nlet programID = msg.topic.substring(b, c);\nlet d = msg.topic.indexOf(\"/controls/\", c) + \"/controls/\".length;\nlet e = msg.topic.indexOf(\"/on\", d);\nlet paramName = msg.topic.substring(d, e);\n\nlet PROGRAMS = flow.get(\"PROGRAMS\");\nlet programs = flow.get(\"programs\");\nlet C = flow.get(\"CONST\");\n\ngetSNRqCANMessageID = function(classId, objectId, methodId) {\n\treturn (classId & 255) | ((objectId & 255) << 8) | ((methodId & 255) << 16);\n};\n\nlet program = programs[programID];\nif (program === undefined) {\n return null;\n}\n\nlet prgType = programs[programID].programType;\nlet prg = PROGRAMS[prgType];\nif (prg === undefined) {\n return null;\n}\nlet curPrg = prg;\n\nlet parameter = prg.parameters[paramName];\nif (parameter === undefined) {\n for (let iprgName in prg.implements) {\n for (let iprgType in PROGRAMS) {\n if (PROGRAMS[iprgType].class == iprgName) {\n parameter = PROGRAMS[iprgType].parameters[paramName];\n if (parameter === undefined) {\n continue;\n } else {\n curPrg = PROGRAMS[iprgType];\n }\n }\n }\n }\n}\nif (parameter === undefined) {\n return null;\n}\n\nif (parameter.encoding == \"short10\") {\n let value = msg.payload * 10;\n msg = {};\n msg.payload = {\n ext: true,\n rtr: false,\n canid: getSNRqCANMessageID(C.REMOTE_CONTROL, programID, C.SET_PARAMETER_VALUE),\n dlc: 2,\n data: [curPrg.programType, parameter.id, value & 0xff, (value & 0xff00) >> 8]\n };\n} else if (parameter.encoding == \"ubyte\") {\n let value = msg.payload;\n if (parameter.type == \"picklist\") {\n let match = false;\n for (let option in parameter.values) {\n if (parameter.values[option] == value) {\n value = option;\n match = true;\n break;\n }\n }\n if (!match) {\n return null;\n }\n }\n msg = {};\n msg.payload = {\n ext: true,\n rtr: false,\n canid: getSNRqCANMessageID(C.REMOTE_CONTROL, programID, C.SET_PARAMETER_VALUE),\n dlc: 2,\n data: [curPrg.programType, parameter.id, value]\n };\n} else if (parameter.encoding == \"uint60K\") {\n let value = msg.payload * 60000;\n msg = {};\n msg.payload = {\n ext: true,\n rtr: false,\n canid: getSNRqCANMessageID(C.REMOTE_CONTROL, programID, C.SET_PARAMETER_VALUE),\n dlc: 5,\n data: [\n curPrg.programType,\n parameter.id,\n value & 0xff,\n (value & 0xff00) >> 8,\n (value & 0xff0000) >> 16,\n (value & 0xff000000) >> 24]\n };\n}\n \nreturn msg;", |