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
- Alternate Hardware
- Installing the Mochad daemon on the Raspberry Pi
- Installing the Mochad Hardware in Domoticz
- Log on to the Domoticz web page at
http://192.168.0.22:8080
. - Click on the Setup tab.
- Click on in the drop-down menu.
- Fill the fields to define the hardware.
- Change the
Type:
toMochad CM15Pro/CM19A bridge with LAN interface
. - Give the hardware a name,
Mochad
seems like an obvious choice. - Specify the
Remote Address
andPort
used by the Mochad daemon. In this case, this is192.168.0.22:1099
but instead I used the localhost address127.0.0.1:1099
. If a different Ethernet address is assigned to the Raspberry Pi, it will not be necessary to adjust theRemote Address
field.
- Change the
- Click on the button.
- Adding Hidden Virtual Switches
- Click on the Switches tab.
- Click on the button at the top right of the page to automagically install a device.
- 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 again and retry as often as you want.
- 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
.
Set theSwitch Type
set atOn/Off
. - Click on the
Test Switch Remote
.
button of the new virtual
switch named - Enter
"
http://192.168.0.22:8080/json.htm?type=command¶m=udevice&idx=1&nvalue=1
" in the On Action field. Note how theidx=1
value corresponds to the virtual switchTest Switch
. - Enter
"
http://192.168.0.22:8080/json.htm?type=command¶m=udevice&idx=1&nvalue=0
" in the Off Action field. Again, theidx=1
value corresponds to the virtual switchTest Switch
. - Click on the
Save button. - Click on the
Back button to return to the tab. - Too Complicated for Nothing?
- Do not setup a virtual switch
Test Switch
in the Virtual dummy hardware as shown in MQTT with Domoticz. Indeed there was no need to setup the Virtual dummy hardware in the first place. - Do setup a switch paired with the remote control button as shown in
steps 1 to 4 of previous section named Adding Hidden Virtual Switches, but do
not hide it. In other words, give it a final name (such as
Test Switch
to continue with that example) that does not begin with a dollar sign. - Look up the switch index (
idx
) in the devices list. - Set the Domoticz index number in the Sonoff configuration equal to the virtual switch index.
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.
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:
https://sourceforge.net/projects/mochad/files/ and adjust the
wget
commands accordingly.
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.
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:
Domoticz supports Mochad "hardware". This installation is done only once.
The added hardware should then be visible in the table at the top of the page.
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.
I Tried 'localhost' and '127.0.0.1' 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:
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
tab. To make it
visible again change the name again, removing the "$", but in the devices
list.
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.