X10 RF controller with a CM19A Interface in Domoticz
May 31, 2017

To manually control three lamps in the living room connected to Sonoff WiFi switches by ITEAD, I am using a HR12A PalmPad Remote Control with a CM19A USB PC Transceiver. In this post, I will show how to install the Mochad deamon and how to integrate it with Domoticz home automation package.

This is a continuation of the previous post where I argued that it is most often necessary to provide some sort of local means of turning on and off lamps connected to Sonoff WiFi switches by ITEAD. There is a slight difference because previously, I added wired remote switches to the Sonoff that directly control the state of its relay. In this instalment, I describe a way of operating the Sonoffs which requires that the Domoticz be running. This may not be acceptable in some circumstances.

Table of Contents

  1. Alternate Hardware
  2. Installing the Mochad daemon on the Raspberry Pi
  3. Installing the Mochad Hardware in Domoticz
  4. Adding Hidden Virtual Switches
  5. Too Complicated for Nothing?

  1. Alternate Hardware
  2. While I describe the use of the CM19A USB PC Transceiver below, I am pretty sure that a CM15A ActiveHome Pro USB Transceiver Module could be used instead to receive the RF transmission from the remote control. I cannot be positive because, as I mentioned before, the RF portion of the CM15A that I purchased from X10 was defective.

    As far as the remote is concerned, any one device or, for that matter, any combination of devices from the following should work:

    HR12A (or PHR03) PalmPad Remote Control (shown above),
    KR19A (or PHR04) Keychain Remote Control,
    KR22A CreditCard Thin Remote Control,
    SS13A (or PHW04D) Slimline Switch Decorator White.

    The combination of the Mochad deamon and the Domoticz server can also be used for motion detection with the MS16A (or PMS03) ActiveEye Wireless Motion Sensor. The details are described elsewhere.

    This installation was done on a Raspberry Pi 3. There is no reason it would not work on an older Raspberry Pi. As a matter of fact, the original installation was done on a Raspberry Pi Model B+ where it worked well. I may very well install the CM19A on a Raspberry Pi Model B when I will remove all X10 devices from my home automation network.

  3. Installing the Mochad daemon on the Raspberry Pi
  4. Do not install the "latest" mochad package available from Sourceforge as it has problems in Raspian Jessie. For some reason Sourceforge currently serves mochad version 0.1.16 (as of 18 June 2017) even though version 0.1.17 has been available for some time. The following shows how to install the later version. However you should check for a newer version here: and adjust the wget commands accordingly.

    pi@rpi2b:~ $ sudo apt-get install libusb-1.0-0-dev pi@rpi2b:~ $ mkdir mochad pi@rpi2b:~ $ cd mochad pi@rpi2b:~/mochad $ wget -O mochad.tgz pi@rpi2b:~/mochad $ tar xf mochad.tgz pi@rpi2b:~.mochad $ cd mochad* pi@rpi2b:~/mochad/mochad-0.1.17 $ ./configure pi@rpi2b:~/mochad/mochad-0.1.17 $ make pi@rpi2b:~/mochad/mochad-0.1.17 $sudo make install

    Check that initially the Mochad daemon is not running, but that it does become active when a CM19A or CM15A computer interface is plugged into the Raspberry Pi.

    pi@rpi2b:~/mochad/mochad-0.1.17 $cd $home pi@rpi2b:~ $ sudo systemctl status mochad ● mochad.service - Start mochad service Loaded: loaded (/lib/systemd/system/mochad.service; disabled) Active: inactive (dead) Plug in the CM19A or CM15A and wait a little while... pi@rpi2b:~ $ sudo systemctl status mochad ● mochad.service - Start mochad service Loaded: loaded (/lib/systemd/system/mochad.service; disabled) Active: active (running) since Tue 2016-11-01 01:37:38 ADT; 10s ago Process: 1296 ExecStart=/usr/local/bin/mochad (code=exited, status=0/SUCCESS) Main PiD: 1301 (mochad) CGroup: /system.slice/mochad.service └─1301 /usr/local/bin/mochad May 31 16:17:41 domo mochad[2094]: Found CM19A May 31 16:17:41 domo mochad[2094]: In endpoint 0x83, Out endpoint 0x04 May 31 16:17:41 domo systemd[1]: Started Start mochad service.

    Now test that the gateway can receive RF commands from a remote control. I am using a Palm Pad Remote Control HR12A. The first step is to connect to the Mochad daemon on port 1099 of the Raspberry Pi, with Netcat> to listen in on the communications with the CM19A. Then press on some buttons on the remote, the deamon should report which buttons were clicked:

    pi@domo:~ $ nc localhost 1099 05/31 16:19:02 Rx RF HouseUnit: F1 Func: On 05/31 16:19:06 Rx RF HouseUnit: F5 Func: Off 05/31 16:19:08 Rx RF House: F Func: Bright 05/31 16:19:10 Rx RF House: F Func: Dim

  5. Installing the Mochad Hardware in Domoticz
  6. Domoticz supports Mochad "hardware". This installation is done only once.

    1. Log on to the Domoticz web page at
    2. Click on the Setup tab.
    3. Click on Hardware in the drop-down menu.
    4. Fill the fields to define the hardware.
      • Change the Type: to Mochad CM15Pro/CM19A bridge with LAN interface.
      • Give the hardware a name, Mochad seems like an obvious choice.
      • Specify the Remote Address and Port used by the Mochad daemon. In this case, this is but instead I used the localhost address If a different Ethernet address is assigned to the Raspberry Pi, it will not be necessary to adjust the Remote Address field.
        Add Mochad bridge
    5. Click on the Add button.

    The added hardware should then be visible in the table at the top of the page.
    Add hardware

  7. Adding Hidden Virtual Switches
  8. If the CM19A or CM15A interface will be a permanent element of your home automation set up, please read the following section Too Complicated for Nothing? before following the instructions in this section.

    Virtual switches in the Domoticz database are already paired with Sonoff switches (for details see MQTT with Domoticz . Recall that the first of these virtual switches was called Test Switch. We will now add a hidden switch paired with the X10 remote control to control the virtual switch. (Actually it does not really matter if a Sonoff has been reprogrammed, installed and linked with the virtual device, all that matters is that the virtual device has been added to the database).

    A new virtual switch will be added to Domoticz> and paired with an on/off buttons on the X10 remote.

    1. Click on the Switches tab.
    2. Click on the Learn Light/Switch button at the top right of the page to automagically install a device.
    3. Click on the button on the remote associated with the lamp when Domoticz displays a prompt saying to Press button on Remote.... Be quick about it, you will be given only a couple of seconds to press that button. Of course you can click on Lean Light/Switch again and retry as often as you want.
    4. Fill in the fields when Domoticz displays a prompt asking for a unique name for the device and the type of switch it is. I called it Test Switch Remote.
      Add Light/Switch Device
      Set the Switch Type set at On/Off.
    5. Click on the Edit button of the new virtual switch named Test Switch Remote.
    6. Enter "¶m=udevice&idx=1&nvalue=1" in the On Action field. Note how the idx=1 value corresponds to the virtual switch Test Switch.
    7. Enter "¶m=udevice&idx=1&nvalue=0" in the Off Action field. Again, the idx=1 value corresponds to the virtual switch Test Switch.
    8. Click on the Save button.
    9. Click on the Back button to return to the Switches tab.

    I Tried 'localhost' and '' instead of hard-wiring the IP address in the On Action and Off Action fields but neither worked.

    If there is no remote handy in step 3 above, then netcat into Mochad and prepare the command to turn on the device but wait to press the Return or Enter key until prompted to press the button on the remote:

    pi@rpi2b:~ $ nc localhost 1099 rf f1 on Press Enter key when prompted
    You can do this from the desktop computer
    michel@hp:~ $ nc 1099 rf f1 on Press Enter key when prompted

    Test that the hardware toggles on and off, that the Test Switch Remote icon and that the Test Switch icon reflect the state of the switch as the remote controler is used.

    If everything works, put "$" sign in front of the name of the Test Switch Remote that will hide it from the Switches tab. To make it visible again change the name again, removing the "$", but in the devices list.

  9. Too Complicated for Nothing?
  10. Some could argue that what preceded is too complicated. Indeed you could do the following.

    I believe everything will work: the bulb icon will follow the state of the physical switch as it is toggled on and off with its button or with the remote control. And the physical switch will turn on and off in response to clicking on the bulb icon in Domoticz.

    For a permanent set up, I think this latter approach would be the way to go. But, remember, I am getting rid of all X10 stuff. It will be simple to delete the hidden virtual switch when the time comes without disrupting the rest of the home automation network. If I follow the simpler approach, I will loose the timers, notifications, etc. associated with the virtual dummy switch working exclusively with MQTT.