X10 Remotes & Sensors with Smartthings using mochad

Update [Jan-28-2018]

This solution was fairly complex to deploy and maintain - I have published another solution:

Summary

X10 remotes, security devices, motion sensors are dirt cheap and I have a boatload of them. Looking around couldn’t find anything to use them with SmartThings.

Mochad is a very stable and widely used deamon process can run on any linux system including Raspberry PI and uses CM15A or CM19A USB devices to communicate with X-10 over RF or powerline. Using this devices you are limited to a single house code, you can use any of the 15 house code with any remote or sensor and make interesting combinations.

https://bfocht.github.io/mochad/
https://bfocht.github.io/mochad/mochad_reference.html

I have developed a small nodejs script that talks to mochad and invokes REST commands to control Smartthings devices.

The rest of this post outlines how I did this using a Raspberry Pi, nodejs and mochad:

Setup

Step 1: Setup a REST SmartApp Endpoint

Follow the tutorial here on how to do this Tutorial: Creating a REST SmartApp Endpoint Install the SmartApp in as instructed and get it fully operational, test it using the PHP script.

Please note that you will probably need make changes to the PHP code for all instances of https://graph.api.smartthings.com… url to point the correct url for your account for this script to work.

I have have a slightly modified version of this this PHP script here which also prints out the REST endpoint urls for all devices. These will come in handy later in the process. I have also removed the locks portion since I wasn’t interested in controlling locks using an insecure system like X10. Here is the matching SmartApp code.

Step 2: Setup the nodejs X10toST deamon

Install nodejs somewhere here is a good tutorial: Node.js - Environment Setup

Copy the following file X10ToSTsignals.js somewhere on the machine where you will run node

make the script executable

chmod +x X10ToSTsignals.js

You will also need to install following node modules:
reconnect-net
events
request

npm install reconnect-net
npm install events
npm install request

Step 3: Map X10 devices to SmartThings REST endpoints

Edit the X10ToSTsignals.js

Change the following lines to match your mochad installation

var hostname = 'pi';  // host name or IP address of mochad server
var port = 1099;      // mochad port - default 1099

In the next section you will need to map X10 command(s) that will get parsed by this code to REST API end points that you extracted using the PHP script. You will need to customize the switch (command) section of the code to reflect your installation:

switch (command) {
    case "c1-on": //X-10 switch
        stUrl = "https://graph-na04-useast2.api.smartthings.com/api/smartapps/installations/88888888-9999-8888-9999-999999999999/switches/88888888-9999-8888-9999-999999999999/on?access_token=88888888-9999-8888-9999-999999999999";
        callurl(stUrl);
        break;

The command format for remote buttons is [House code][Device code]-on or [House code][Device code]-on .
Please note CM15A or CM19A don’t restrict you to a single house code; you can set up different codes for different rooms etc. and they can all work with one receiver.

Security devices are a bit trickier and you will need to discover the command emitted by them. The best way to find out what you will get is to run the script, use the device to generate the event and look for a line like this in the console - the characters following data: is what you need to put in the case “xxxx”: line.

data: 0xfe*-disarm_sh624

Motion sensors are a mixed bag, some generate data like switches others act like security devices, so you will need to look at the output after running the script to determine the output your particular device generates.

Step 4 - Running the script

You can run the script by simply executing it
./X10ToSTsignals.js

Once you run the script you should see output in console as you press buttons on the remote or motion sensors are triggered.

You will probably want to daemonize it for your system so it runs every time your system starts up.

1 Like