BeagleBone Green X10 to MQTT Bridge with CM15A and email out

A flow that: Emails the BBG IP address uppon reboot Listens to X10 traffic using the CM15A Parses the messages Publishes via MQTT and email

[{"id":"32089d81.1514d2","type":"mqtt-broker","z":"124898bd.f6036f","broker":"localhost","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":null,"willPayload":"","birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":""},{"id":"6f83cfb.f31f33","type":"tcp in","z":"124898bd.f6036f","name":"X10 input","server":"client","host":"localhost","port":"1099","datamode":"stream","datatype":"buffer","newline":",","topic":"X10 input","base64":false,"x":122,"y":365,"wires":[["5004d671.f6608"]]},{"id":"5004d671.f6608","type":"function","z":"124898bd.f6036f","name":"Convert Hex to String","func":"var hexInput, stringInput, houseUnit, func, i, outString, strArray;          // declare variables\nhexInput = msg.payload;                                 // read the input into a variable called hexInput\nconst buf2 = new Buffer(hexInput, 'hex');               // use the \"Buffer\" function and identifies the encoding as hex \nstringInput = buf2.toString();                          // convert our hex buffer to a string       \nif (stringInput.length > 100){                           // if the string length is over 60 we parse it (there are sometimes shorter messages that we want to skip)     \n    strArray = stringInput.split(\" \");\n    i = strArray.indexOf(\"HouseUnit:\") + 1;\n    houseUnit = \"HouseUnit: \" + strArray[i];               // take the second value in the array and add \"House:\" back to the beginning of it\n    //i = strArray.indexOf(\"Func:\") + 1;\n    //func = \"Func: \" + strArray[i]; \n    i = strArray.length - 1;\n    func = \"Func: \" + strArray[i].trim(); \n    outString = houseUnit + \" \" + func;                 // take the second value in the array and add \"House:\" back to the beginning of it\n    return {payload: outString};                        // return our new cleaned value to the output of the funtion\n}\n\n\n\n","outputs":1,"noerr":0,"x":169,"y":428,"wires":[["bf539d6.8f6026","25e63f2d.19d918","5a950e50.bf99c8","a5badc02.11df28"]]},{"id":"bf539d6.8f6026","type":"mqtt out","z":"124898bd.f6036f","name":"MQTT Out","topic":"X10Bridge/","qos":"","retain":"","broker":"32089d81.1514d2","x":497,"y":417,"wires":[]},{"id":"a5c865.e1138f98","type":"exec","z":"124898bd.f6036f","command":"ifconfig","append":"","useSpawn":false,"name":"ifconfig","x":315,"y":124,"wires":[["9f5af425.fb837"],[],[]]},{"id":"69890fa7.76ec3","type":"inject","z":"124898bd.f6036f","name":"get ip - eth0","topic":"ip","payload":"eth0","payloadType":"none","repeat":"","crontab":"","once":true,"x":139,"y":125.5,"wires":[["a5c865.e1138f98"]]},{"id":"a5badc02.11df28","type":"debug","z":"124898bd.f6036f","name":"test out","active":true,"console":"false","complete":"payload","x":492,"y":291.5,"wires":[]},{"id":"9f5af425.fb837","type":"function","z":"124898bd.f6036f","name":"Extract network config","func":"// Initialize variables\nvar input, tokens, inet, bcast, mask;\nvar outString = \"TestRasPi network config for eth0\\n\";\n\n// Parse the entire string by spaces, and put each item into an array called tokens\n\ninput = msg.payload;\ntokens = input.split(\":\", 10);\n\n// Get the 7th token (example: \"addr:192.168.0.120\")\n// and get the substring from character 6 to the end\ninet = tokens[7].split(\" \", 1);\noutString += \"\\n\" + \"inet addr: \" + inet[0];\n\n// Get the 8th token (example: \"Bcast:192.168.0.255\")\n// and get the substring from character 7 to the end\nbcast = tokens[8].split(\" \", 1);\noutString += \"\\n\" + \"Bcast: \" + bcast[0];\n\n// Get the 9th token (example: \"Mask:255.255.255.0\")\n// and get the substring from character 6 to the end\nmask = tokens[9].split(\" \", 1);\noutString += \"\\n\" + \"Mask: \" + mask[0];\n\n// Don't send a message if the IF is the known default. Change to default ip.\nif (inet==\"192.168.0.120\") { \n//outString = \"\"; // set output to null if ip is the same so no message is sent\nreturn null;\n}else{\n// return the final output\nreturn {payload: outString};\n}\n","outputs":1,"noerr":0,"x":525,"y":111,"wires":[["f8c5990c.3dca68"]]},{"id":"f8c5990c.3dca68","type":"delay","z":"124898bd.f6036f","name":"Delay","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":256,"y":219,"wires":[["a5badc02.11df28","508568b0.505558","bf539d6.8f6026"]]},{"id":"508568b0.505558","type":"e-mail","z":"124898bd.f6036f","server":"smtp.gmail.com","port":"465","name":"[email protected]","dname":"Gmail Out","x":474,"y":507.5,"wires":[]},{"id":"2cdbc416.a7313c","type":"comment","z":"124898bd.f6036f","name":"Send ip address on boot","info":"","x":318,"y":54.5,"wires":[]},{"id":"3350fdde.d1e5fa","type":"comment","z":"124898bd.f6036f","name":"X10 to MQTT bridge","info":"","x":126,"y":323,"wires":[]},{"id":"25e63f2d.19d918","type":"function","z":"124898bd.f6036f","name":"Text output","func":"var inputString, outputString;          // declare variables\ninputString = msg.payload;                                 // read the input into a variable called hexInput\nif (inputString === 'HouseUnit: A1 Func: On') {\n    outputString = \"Driveway Motion Detected\";\n    return {payload: outputString}; \n} \n\nif (inputString === \"HouseUnit: A3 Func: On\") {\n    outputString = \"Safe Room Breach!!!\";\n    return {payload: outputString}; \n} \n\n    \n\n\n\n\n","outputs":1,"noerr":0,"x":188,"y":593,"wires":[["bf539d6.8f6026","a5badc02.11df28"]]},{"id":"c22c7222.2dba18","type":"comment","z":"124898bd.f6036f","name":"Decode commands case statements","info":"","x":149,"y":550,"wires":[]},{"id":"5a950e50.bf99c8","type":"function","z":"124898bd.f6036f","name":"Email output","func":"var inputString, outputString;          // declare variables\ninputString = msg.payload;                                 // read the input into a variable called hexInput\nswitch (inputString) {\n    case \"HouseUnit: A3 Func: On\":\n        outputString = \"Safe Room Breach!!!\";\n        return {payload: outputString};         \n        break;\n    case 2:\n        outputString = \"Tuesday\";\n        break;\n} \n\n    \n\n\n\n\n","outputs":1,"noerr":0,"x":189,"y":647,"wires":[["508568b0.505558","a5badc02.11df28"]]}]
ElectronHacks

Flow Info

created 1 year, 10 months ago

Node Types

Core
  • comment (x3)
  • debug (x1)
  • delay (x1)
  • e-mail (x1)
  • exec (x1)
  • function (x4)
  • inject (x1)
  • mqtt out (x1)
  • mqtt-broker (x1)
  • tcp in (x1)

Tags

  • MQTT
  • X10
  • Hackster.io
  • node-red
  • beaglebone
  • CM15A
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option