Mochad, HA-Bridge and CM19a on Zorin

So, in ditching Windows I had to find a solution to my Windows-based X-10 home automation. On Windows I had a CM19a USB based transceiver for issuing X-10 commands to the X-10 modules controlling my house lights. I used a piece of software named Alex10 to command the CM19a, and a Philips Hue Bridge emulator (HA-Bridge) to allow me to give voice commands via my Amazon Echo.

The HA-Bridge software was a Java program with a web interface, so it ported over cleanly from Windows to Linux. What I had to find was something to replace the Alex10 software. Searching the Internet I found some software that did exactly what I needed, Mochad.

The four components of the system are:

My system is an HP Envy running a fresh install of Zorin 15 OS

Mochad

The first step was to get mochad up and running. Go to the files section and the first thing you notice is that the download button downloads version 16, but that there is a newer version, 17. Download the newer version.

Follow the instructions in the README file to install. I created a “Home -Automation” folder in my home folder to keep all the downloaded software in. Open the downloaded mochad file and unzip it to the Home-Automation folder. and then open the README file.

Then open a terminal window and change directories to the mochad directory. The commands I used (as documented in the README file) were

cd ~/Home-Automation/mochad*
sudo apt-get install libusb-1.0-0-dev
./configure

This last command failed indicating I needed to install a C compiler so I did.

sudo apt-get install gcc

I re-ran the ./configure command and this time it worked without any errors. I then continued to build the software.

make

The make command failed, saying that it wasn’t found, so I had to install it as well.

sudo apt install make

After it installed I finished the build with the following command

sudo make install

I then plugged in the CM19a to a USB port and ran the command

lsusb

which showed that the Linux system saw the device.

Bus 003 Device 002: ID 0bc7:0002 X10 Wireless Technology, Inc. Firecracker Interface (ACPI-compliant)

Following the README instructions I sent a test command to the mochad software:

echo "rf m13 off" | nc localhost 1099

Of course it didn’t work so I had to begin troubleshooting. I listed the running processes using the ps command and didn’t see mochad in the list. So I manually ran it as sudo:

sudo ./mochad &

When I did the test command it worked. I did some googling and discovered that others had seen this same issue. The software is suppose to automatically get run when the CM19a is plugged into the USB using the udev process.

I rebooted the machine but mochad still wasn’t started so I looked in the udev rules folder at /etc/udev/rules.d and there wasn’t a rule there. So I went back to the mochad directory and manually copied the rules to the udev rules folder:

cd ~/Home-Automation/m*/udev
sudo cp * /etc/udev/rules.d

Another reboot and mochad still wasn’t running. To make testing easier I created two script files, xon and xoff (described below in summary section). If I manually started mochad these commands worked, if not they failed. So the udev rules were not working. I looked at the rules and they were pointed to mochad in the /usr/local/bin directory. I looked there and mochad was missing. So I manually copied it from my folder to there. After a reboot nothing changed, I still had to manually start mochad.

I found a discussion on the issue (https://sourceforge.net/p/mochad/discussion/1320002/thread/13ccfe060d/) and am going to setup a cron entry to manually run mochad when the system is rebooted. Running the command:

sudo crontab -e

I added the line:

@reboot /usr/local/bin/mochad &

After saving the file and rebooting my test commands worked.

HA-Bridge

Now with mochad working the next step was to install the HA-Bridge software. In my Home-Automation folder I created a new folder “ha-bridge”.

I then downloaded the software with the wget command:

wget https://github.com/bwssytems/ha-bridge/releases/download/v5.2.2/ha-bridge-5.2.2.jar

I then tested it by running the command:

sudo java -jar *.jar &

and opened my browser to localhost and there it was. Since I was starting mochad with a cron job I added this to the crontab as well, adding the line

@reboot java -jar /home/bob/Home-Automation/ha-bridge/*.jar &

to the file. After a reboot everything started up fine. So I added my devices to the ha-bridge and am off and running.

Summary

Other than the udev issue and having to install a couple of things (gcc, java, make) things went pretty well. I plan on looking into the udev issue and if I solve that I will then set up the bridge to run as a service instead of a cron job. This is described in the ha-bridge README file. But for now, it is “if it ain’t broke…”

Below are the listing of some of the files I created:

xon – set as executable, run as “./xon i” where “i” is the unit number you want to turn on. The “m” in the file is my house code.

echo "rf m$1 on" | nc localhost 1099

xoff – set as executable, run as “./xoff i” where “i” is the unit number you want to turn on. The “m” in the file is my house code.

echo "rf m$@ off" | nc localhost 1099

all_lights_on – set as an executable, for each unit code it turns the unit on. This is in a “scripts” folder below the xon file, hence the two dots.

for i in {1..16}
do
  ../xon $i
done

all_lights_off– set as an executable, for each unit code it turns the unit off. This is in a “scripts” folder below the xoff file, hence the two dots.

for i in {1..16}
do
  ../xoff $i
done

crontab file

@reboot /usr/local/bin/mochad &
@reboot java -jar /home/bob/Home-Automation/ha-bridge/*.jar &

Leave a Reply

Your email address will not be published. Required fields are marked *