{"id":3355,"date":"2019-07-05T18:40:13","date_gmt":"2019-07-05T18:40:13","guid":{"rendered":"https:\/\/robertjwallace.com\/?p=3355"},"modified":"2019-07-05T18:40:15","modified_gmt":"2019-07-05T18:40:15","slug":"mochad-ha-bridge-and-cm19a-on-zorin","status":"publish","type":"post","link":"https:\/\/robertjwallace.com\/es\/mochad-ha-bridge-and-cm19a-on-zorin\/","title":{"rendered":"Mochad, HA-Bridge and CM19a on Zorin"},"content":{"rendered":"<p>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.  <\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>The four components of the system are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Amazon Echo Dot <br><\/li><li>HA-Bridge &#8211; Home automation  bridge that emulates a Philips Hue light system and can control other  systems such as a Vera, Harmony Hub, Nest, MiLight bulbs or any other  system that has an http\/https\/tcp\/udp interface.  <a rel=\"noreferrer noopener\" aria-label=\"https:\/\/github.com\/bwssytems\/ha-bridge (opens in a new tab)\" href=\"https:\/\/github.com\/bwssytems\/ha-bridge\" target=\"_blank\">https:\/\/github.com\/bwssytems\/ha-bridge<\/a><br><\/li><li>mochad &#8211; mochad is a Linux TCP gateway daemon for the X10 CM15A RF (radio frequency) and PL (power line) controller and the CM19A RF controller.<br><a href=\"https:\/\/sourceforge.net\/projects\/mochad\/files\/\">href=&#8221;https:\/\/sourceforge.net\/projects\/mochad\/files\/&#8221;<\/a><br><\/li><li>CMA19a &#8211; a USB PC Transceiver that sends and receives X10 radio-frequency commands from your PC.  <a href=\"https:\/\/www.x10.com\/cm19a.html\">https:\/\/www.x10.com\/cm19a.html<\/a><\/li><\/ul>\n\n\n\n<p>My system is an HP Envy running a fresh install of Zorin 15 OS<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Mochad<\/h2>\n\n\n\n<p>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.  <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"764\" height=\"635\" data-src=\"https:\/\/robertjwallace.com\/wp-content\/uploads\/2019\/07\/mocha1.jpg\" alt=\"\" class=\"wp-image-3357 lazyload\" data-srcset=\"https:\/\/robertjwallace.com\/wp-content\/uploads\/2019\/07\/mocha1.jpg 764w, https:\/\/robertjwallace.com\/wp-content\/uploads\/2019\/07\/mocha1-300x249.jpg 300w\" data-sizes=\"(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 764px; --smush-placeholder-aspect-ratio: 764\/635;\" \/><\/figure>\n\n\n\n<p>Follow the instructions in the README file to install.  I created a &#8220;Home -Automation&#8221; 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.<\/p>\n\n\n\n<p>Then open a terminal window and change directories to the mochad directory.  The commands I used (as documented in the README file) were<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd ~\/Home-Automation\/mochad*<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt-get install libusb-1.0-0-dev<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">.\/configure<\/pre>\n\n\n\n<p>This last command failed indicating I needed to install a C compiler so I did.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt-get install gcc<\/pre>\n\n\n\n<p>I re-ran the .\/configure command and this time it worked without any errors.  I then continued to build the software.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">make<\/pre>\n\n\n\n<p>The make command failed, saying that it wasn&#8217;t found, so I had to install it as well.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install make<\/pre>\n\n\n\n<p>After it installed I finished the build with the following command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo make install<\/pre>\n\n\n\n<p>I then plugged in the CM19a to a USB port and ran the command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">lsusb<\/pre>\n\n\n\n<p>which showed that the Linux system saw the device.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Bus 003 Device 002: ID 0bc7:0002 X10 Wireless Technology, Inc. Firecracker Interface (ACPI-compliant)<\/pre>\n\n\n\n<p>Following the README instructions I sent a test command to the mochad software:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo \"rf m13 off\" | nc localhost 1099<\/pre>\n\n\n\n<p>Of course it didn&#8217;t work so I had to begin troubleshooting.  I listed the running processes using the ps command and didn&#8217;t see mochad in the list.  So I manually ran it as sudo:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo .\/mochad &amp;<\/pre>\n\n\n\n<p>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.   <\/p>\n\n\n\n<p>I rebooted the machine but mochad still wasn&#8217;t started so I looked in the udev rules folder at \/etc\/udev\/rules.d and there wasn&#8217;t a rule there.  So I went back to the mochad directory and manually copied the rules to the udev rules folder:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd ~\/Home-Automation\/m*\/udev\nsudo cp * \/etc\/udev\/rules.d<\/pre>\n\n\n\n<p>Another reboot and mochad still wasn&#8217;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.<\/p>\n\n\n\n<p>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:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo crontab -e<\/pre>\n\n\n\n<p>I added the line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@reboot \/usr\/local\/bin\/mochad &amp;<\/pre>\n\n\n\n<p>After saving the file and rebooting my test commands worked.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">HA-Bridge<\/h2>\n\n\n\n<p>Now with mochad working the next step was to install the HA-Bridge software.  In my Home-Automation folder I created a new folder &#8220;ha-bridge&#8221;.<\/p>\n\n\n\n<p>I then downloaded the software with the wget command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/github.com\/bwssytems\/ha-bridge\/releases\/download\/v5.2.2\/ha-bridge-5.2.2.jar<\/code><\/pre>\n\n\n\n<p>I then tested it by running the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo java -jar *.jar &amp;<\/pre>\n\n\n\n<p>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<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@reboot java -jar \/home\/bob\/Home-Automation\/ha-bridge\/*.jar &amp;<\/pre>\n\n\n\n<p>to the file.  After a reboot everything started up fine.  So I added my devices to the ha-bridge and am off and running.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resumen<\/h2>\n\n\n\n<p>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 &#8220;if it ain&#8217;t broke&#8230;&#8221;<\/p>\n\n\n\n<p>Below are the listing of some of the files I created:<\/p>\n\n\n\n<p><strong>xon<\/strong>  &#8211; set as executable, run as &#8220;.\/xon   i&#8221; where &#8220;i&#8221; is the unit number you want to turn on.  The &#8220;m&#8221; in the file is my house code.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo \"rf m$1 on\" | nc localhost 1099<\/pre>\n\n\n\n<p><strong>xoff<\/strong>  &#8211; set as executable, run as &#8220;.\/xoff   i&#8221; where &#8220;i&#8221; is the unit number you want to turn on.  The &#8220;m&#8221; in the file is my house code.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo \"rf m$@ off\" | nc localhost 1099<\/pre>\n\n\n\n<p><strong>all_lights_on<\/strong> &#8211; set as an executable, for each unit code it turns the unit on.  This is in a &#8220;scripts&#8221; folder below the xon file, hence the two dots.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in {1..16}\ndo\n  ..\/xon $i\ndone<\/pre>\n\n\n\n<p><strong>all_lights_off<\/strong>&#8211; set as an executable, for each unit code it turns the unit off. This is in a &#8220;scripts&#8221; folder below the xoff file, hence the two dots.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in {1..16}\ndo\n  ..\/xoff $i\ndone<\/pre>\n\n\n\n<p><strong>crontab file<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@reboot \/usr\/local\/bin\/mochad &amp;\n@reboot java -jar \/home\/bob\/Home-Automation\/ha-bridge\/*.jar &amp;<\/pre>","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/robertjwallace.com\/es\/mochad-ha-bridge-and-cm19a-on-zorin\/\" class=\"more-link\">Continuar leyendo<span class=\"screen-reader-text\"> &#8220;Mochad, HA-Bridge and CM19a on Zorin&#8221;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_eb_attr":"","footnotes":""},"categories":[143],"tags":[],"class_list":["post-3355","post","type-post","status-publish","format-standard","hentry","category-computer-stuff"],"featured_image_src":null,"featured_image_src_square":null,"author_info":{"display_name":"Bob","author_link":"https:\/\/robertjwallace.com\/es\/author\/admin\/"},"_links":{"self":[{"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/posts\/3355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/comments?post=3355"}],"version-history":[{"count":9,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/posts\/3355\/revisions"}],"predecessor-version":[{"id":3365,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/posts\/3355\/revisions\/3365"}],"wp:attachment":[{"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/media?parent=3355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/categories?post=3355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/tags?post=3355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}