Skip to content

Instantly share code, notes, and snippets.

@enishoca
Last active March 3, 2018 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enishoca/b02780901a7148916059623618087d85 to your computer and use it in GitHub Desktop.
Save enishoca/b02780901a7148916059623618087d85 to your computer and use it in GitHub Desktop.
[
{
"id": "8921e4a9.757288",
"type": "tab",
"label": "Smartthings X10 Heyu Connector",
"disabled": false,
"info": ""
},
{
"id": "7878dc79.76b694",
"type": "function",
"z": "8921e4a9.757288",
"name": "Parse heyu Messages",
"func": "msg.headers = {};\nmsg.headers['Content-Type'] = 'application/json';\nmsg.headers['X10NodeRed'] = 'DeviceUpdate';\n \n \n\nconst inLines = msg.payload; \n//return {payload: stringBuf.toString()};\nnode.warn(\"in - \" + inLines);\n\nvar lastCodeSeen = context.get(\"lastCodeSeen\");\nif(typeof lastCodeSeen == \"undefined\") {\n lastCodeSeen = {\n housecode: \"x\",\n unitcode: \"0\"\n };\n context.set(\"lastCodeSeen\", lastCodeSeen);\n}\n\ntry {\n\n var eventData, m;\n //05/30 20:59:20 Tx PL HouseUnit: P1\n //02/20 22:27:04 rcvi addr unit 4 : hu B4 (no_alias)\n //02/20 22:27:04 rcvi func On : hc B\n //02/20 22:27:13 rcvi addr unit 4 : hu B4 (no_alias)\n //02/20 22:27:13 rcvi func Off : hc B\n \n \n //05/30 20:59:20 Tx PL House: P Func: On\n \n \n node.log(\"t1\");\n if (m = /^\\d{2}\\/\\d{2}\\s+(?:\\d{2}:){2}\\d{2}\\s+rcvi addr unit\\s+\\d+\\s+:\\s+hu\\s+([a-pA-P])(\\d{1,2})/m.exec(inLines)) {\n \n lastCodeSeen.housecode = m[1].toLowerCase().trim();\n lastCodeSeen.unitcode = parseInt(m[2].trim(), 10);\n node.warn(\"m1a - \"+ lastCodeSeen.housecode +\":\" + lastCodeSeen.unitcode);\n context.set(\"lastCodeSeen\", lastCodeSeen);\n }\n //if (m = /\\d{2}\\/\\d{2}\\s+(?:\\d{2}:){2}\\d{2}\\srcvi\\s+func:\\s+(On|Off)\\s+:\\s+hc\\s+([a-pA-P])\\s/m.exec(inLines))) {\n\n if (lastCodeSeen.housecode && lastCodeSeen.unitcode && (m = /^\\d{2}\\/\\d{2}\\s+(?:\\d{2}:){2}\\d{2}\\s+rcvi\\s+func\\s+(On|Off)\\s+:\\s+hc\\s+([a-pA-P])/m.exec(inLines))) {\n node.warn(\"m2\");\n eventData = {\n \n protocol: \"*\",\n direction: \"*\",\n housecode: m[2].toLowerCase().trim(),\n unitcode: null,\n state: m[1].toLowerCase().trim()\n \n };\n node.warn(\"m2a - \"+ eventData.housecode +\":\" + eventData.state);\n if (eventData.housecode === lastCodeSeen.housecode) {\n eventData.unitcode = lastCodeSeen.unitcode;\n msg.payload = JSON.stringify(eventData);\n msg.headers['eventData'] = msg.payload;\n return msg; //{payload: JSON.stringify(eventData)};\n }\n }\n}\n \ncatch(err) {\n return null; //ignore the exception, its probably a message we don't understand\n //node.error(\"exception in parsing: \" + err.message); \n} \n \nreturn null;\n\n",
"outputs": 1,
"noerr": 0,
"x": 440,
"y": 220,
"wires": [
[
"933d89e6.70b848",
"da89f564.30b928"
]
]
},
{
"id": "4d070eba.79d49",
"type": "http in",
"z": "8921e4a9.757288",
"name": "/register",
"url": "/register",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 68,
"y": 490,
"wires": [
[
"ba03d104.5faea",
"c345b715.55fad8"
]
]
},
{
"id": "8a3a4571.eb8b38",
"type": "http response",
"z": "8921e4a9.757288",
"name": "Send respone to ST",
"statusCode": "",
"headers": {},
"x": 716,
"y": 532,
"wires": []
},
{
"id": "d42724ae.69e3f8",
"type": "http request",
"z": "8921e4a9.757288",
"name": "http request to ST",
"method": "POST",
"ret": "txt",
"url": "",
"tls": "",
"x": 730,
"y": 160,
"wires": [
[]
]
},
{
"id": "2d3beec0.1c7c82",
"type": "debug",
"z": "8921e4a9.757288",
"name": "",
"active": true,
"console": "false",
"complete": "true",
"x": 910,
"y": 220,
"wires": []
},
{
"id": "622a7e26.2b95c",
"type": "file in",
"z": "8921e4a9.757288",
"name": "Read ST setting after restart",
"filename": "/home/pi/.red-st-connect.conf",
"format": "utf8",
"chunk": false,
"sendError": false,
"x": 366.5,
"y": 80,
"wires": [
[
"5680bb4f.9163a4"
]
]
},
{
"id": "b853d360.89596",
"type": "inject",
"z": "8921e4a9.757288",
"name": "Startup",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": true,
"x": 100,
"y": 81,
"wires": [
[
"622a7e26.2b95c",
"540e5d20.397784"
]
]
},
{
"id": "c345b715.55fad8",
"type": "file",
"z": "8921e4a9.757288",
"name": "Persist ST settings to File",
"filename": "/home/pi/.red-st-connect.conf",
"appendNewline": false,
"createDir": true,
"overwriteFile": "true",
"x": 316.5,
"y": 459,
"wires": []
},
{
"id": "9359f308.71425",
"type": "comment",
"z": "8921e4a9.757288",
"name": "setup config file path",
"info": "If you are not running as pi or /home/pi is\nnot writable change the location of where\nthis flow will read and write ST settings\nsettigns will be stored in /home/pi/.red-st-connect.conf",
"x": 348,
"y": 43,
"wires": []
},
{
"id": "5680bb4f.9163a4",
"type": "function",
"z": "8921e4a9.757288",
"name": "Set ST Settings in global context",
"func": "try {\n var STsettings = JSON.parse(msg.payload);\n if (typeof obj !== 'string' ) \n global.set(\"STsettings\", STsettings);\n} catch (e) {\n // ignore errors\n}\n\nmsg.payload = \"Smartthings settings: \" + JSON.stringify (STsettings);\n\nreturn msg\n\n\n\n",
"outputs": 1,
"noerr": 0,
"x": 674,
"y": 80,
"wires": [
[]
]
},
{
"id": "933d89e6.70b848",
"type": "function",
"z": "8921e4a9.757288",
"name": "Setup http request",
"func": "\n// if you want to hard code the url to ST uncomment these two lines and\n// delete or comment out the rest of the lines in this node\n// msg.url. = \"http://ip_address_of_Smartthings_hub:39500/\";\n// return msg;\n\nvar STsettings = global.get(\"STsettings\");\nif(typeof STsettings == \"undefined\") {\n node.error(\"Can't continue. Don't know where Smartthings hub is.\");\n return null;\n}\nnode.log(\"Please ignore the message properties override warning\");\nmsg.url =\"http://\" + STsettings.ip_for_st + \":\" + STsettings.port_for_st;\nreturn msg;\n\n\n\n\n\n",
"outputs": 1,
"noerr": 0,
"x": 670,
"y": 220,
"wires": [
[
"2d3beec0.1c7c82",
"d42724ae.69e3f8"
]
]
},
{
"id": "ba03d104.5faea",
"type": "function",
"z": "8921e4a9.757288",
"name": "Registration response",
"func": "msg.headers = {};\nmsg.headers['Content-Type'] = 'application/json';\nmsg.headers['X10NodeRed'] = 'Registered';\nmsg.payload = {\"X10NodeRed\":\"Registered\"};\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 310,
"y": 532,
"wires": [
[
"8a3a4571.eb8b38"
]
]
},
{
"id": "8f9a97ed.b92a58",
"type": "comment",
"z": "8921e4a9.757288",
"name": "setup heyu path",
"info": "Here you should setup the path to heyu\n",
"x": 220,
"y": 260,
"wires": []
},
{
"id": "61ec332f.de8fdc",
"type": "comment",
"z": "8921e4a9.757288",
"name": "setup config file path",
"info": "If you are not running as pi or /home/pi is\nnot writable change the location of where\nthis flow will read and write ST settings\nsettigns will be stored in /home/pi/.red-st-connect.conf",
"x": 310,
"y": 416,
"wires": []
},
{
"id": "2af3aed3.30ee72",
"type": "comment",
"z": "8921e4a9.757288",
"name": "setup heyu path",
"info": "Here you should setup the path to heyu\n",
"x": 480,
"y": 700,
"wires": []
},
{
"id": "540e5d20.397784",
"type": "exec",
"z": "8921e4a9.757288",
"command": "/usr/local/bin/heyu",
"addpay": false,
"append": "monitor",
"useSpawn": "true",
"timer": "",
"oldrc": false,
"name": "heyu monitor",
"x": 210,
"y": 320,
"wires": [
[
"7878dc79.76b694",
"da89f564.30b928"
],
[
"da89f564.30b928"
],
[
"da89f564.30b928"
]
]
},
{
"id": "70839d7e.4e60b4",
"type": "http in",
"z": "8921e4a9.757288",
"name": "/push",
"url": "/push",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 70,
"y": 740,
"wires": [
[
"c116faf1.889158"
]
]
},
{
"id": "c116faf1.889158",
"type": "function",
"z": "8921e4a9.757288",
"name": "parse send message",
"func": "var jsonText = JSON.stringify(msg.payload); \nvar obj = JSON.parse(jsonText);\n\n//{\"device\":\"RF-A3\",\"action\":\"off\"}\nif (typeof obj !== 'string' ) {\n var device = obj.device.substring(3);\n\n // heyu on b2\n // heyu off b2\n // heyu fon a1\n \n msg.payload = \" \";\n msg.payload += obj.device.substring(0,2) == \"RF\" ? \" f\" :\" \"; \n msg.payload += obj.action+\" \" + device.toLowerCase() + \"\\n\";\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"x": 260,
"y": 740,
"wires": [
[
"6533fb38.bd88c4",
"e2cef99.b18f608",
"e26e73f7.37ea6"
]
]
},
{
"id": "3e211a27.e8c1a6",
"type": "debug",
"z": "8921e4a9.757288",
"name": "",
"active": true,
"console": false,
"complete": "true",
"x": 750,
"y": 740,
"wires": []
},
{
"id": "6533fb38.bd88c4",
"type": "exec",
"z": "8921e4a9.757288",
"command": "/usr/local/bin/heyu",
"addpay": true,
"append": " ",
"useSpawn": "false",
"timer": "",
"oldrc": false,
"name": "send command to heyu",
"x": 510,
"y": 740,
"wires": [
[
"3e211a27.e8c1a6"
],
[
"3e211a27.e8c1a6"
],
[
"3e211a27.e8c1a6"
]
]
},
{
"id": "e2cef99.b18f608",
"type": "debug",
"z": "8921e4a9.757288",
"name": "",
"active": true,
"console": false,
"complete": "payload",
"x": 470,
"y": 860,
"wires": []
},
{
"id": "da89f564.30b928",
"type": "debug",
"z": "8921e4a9.757288",
"name": "",
"active": true,
"console": false,
"complete": "payload",
"x": 650,
"y": 320,
"wires": []
},
{
"id": "e26e73f7.37ea6",
"type": "function",
"z": "8921e4a9.757288",
"name": "OK response",
"func": "msg.headers = {};\nmsg.headers['Content-Type'] = 'application/json';\nmsg.payload = {\"X10NodeRed\":\"OK\"};\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 490,
"y": 620,
"wires": [
[
"8a3a4571.eb8b38"
]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment