Skip to content

Instantly share code, notes, and snippets.

@jhottell
Last active March 31, 2016 00: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 jhottell/7f5ec8693a62d6ce00c1 to your computer and use it in GitHub Desktop.
Save jhottell/7f5ec8693a62d6ce00c1 to your computer and use it in GitHub Desktop.
X10 CM15A to MQTT bridge

Connects to a port where you have mochad installed to recieve X10 traffic. converts the hex data into string and then cleans it up to sends to MQTT. I don't have sending data figured out yet.

[{"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":"31e5b3b1.099454","type":"tcp in","z":"8eff0b7.93469f8","name":"X10 input","server":"client","host":"localhost","port":"1099","datamode":"stream","datatype":"buffer","newline":",","topic":"X10 input","base64":false,"x":188,"y":277,"wires":[["c986e94.6df4298"]]},{"id":"c986e94.6df4298","type":"function","z":"8eff0b7.93469f8","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":235,"y":340,"wires":[["44c8ea8.929d394","a43155e6.4ff33"]]},{"id":"44c8ea8.929d394","type":"mqtt out","z":"8eff0b7.93469f8","name":"MQTT Out","topic":"X10Bridge/","qos":"","retain":"","broker":"32089d81.1514d2","x":563,"y":329,"wires":[]},{"id":"a43155e6.4ff33","type":"debug","z":"8eff0b7.93469f8","name":"test out","active":true,"console":"false","complete":"payload","x":561,"y":273.5,"wires":[]},{"id":"155410bc.5769cf","type":"comment","z":"8eff0b7.93469f8","name":"X10 to MQTT bridge","info":"","x":192,"y":235,"wires":[]}]
@jhottell
Copy link
Author

Added trim() to make it cleaner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment