openHAB 3.0.2 / MochadX10 / Alexa integration [SOLVED]

I am trying to control mochad with openHAB but I can’t find how to add the mochadx10 addon.
There is a userdata/config/org/openhab/mochadx10.config file but I can’t find where to add the IP and PORT info. I can nc {ip} {port} and send commands to mochad.
Was it removed? Can I manually add it? Any help will be greatly appreciated.

I found a repository with a jar

I think all OH 1 binaries have been removed from OH 3.

I had X10 devices in OH3 using a CM19a device and this program:

which used MQTT.

I don’t have any X10 devices anymore.

It may work for you.

The solution is to run an OH2 instance with your v1 binding and use the remoteopenhab binding to get the OH2 Items into OH3 for control.

Generally v1 bindings have been abandoned by the developer.

I’m new to OH so from what I understand, these are 2 separate solutions and on both solutions I need to run OH2?

One solution uses MQTT/cm19python instead of mochadx10 or in conjunction?

OH2 + cm19python + mochadx10
OH2 + cm19python

And the other solution

OH2 + mochadx10 + OH3 + remoteopenhab?

Thank you in advance.

BTW, can I just run OH2 + mochadx10? Or do I rely on OH3 for Alexa to work?

The two solutions are:


X10 <-> cm19python <-> MQTT <-> openHAB

So for this solution you’ll need to separately run cm19python, an MQTT broker, and openHAB.


X10 <-> openHAB 2 <-> openHAB 3

For this solution you will run openHAB 2 and use the Mochad binding to communicate with X10. On openHAB 3 you will install the Remote openHAB binding. This binding will mirror the Items in the openHAB 2 instance allowing you to see and control stuff in the other openHAB instance.

One caution on the second approach. openHAB 2 is at end of support. 1.x version bindings can be considered, as Bruce said, abandoned. In both cases what you have now is what there will be forever more. Both openHAB 2 and 1.x version bindings will receive no further updates.

I don’t know the status of cm19python.

OH 2.5 works with Alexa for now as far as I’m aware. But Alexa integration is a moving target. I would not expect it to continue to work forever in OH 2.5. Amazon will change something at some point that will break the binding. The OH 3 binding will be updated, the 2.5 binding will not.

I used a different solution based on the Exec-Binding. So no need for a second OH2.5 instance. It is not as easy as the mochad binding but works quite fine for me.

What you need:

  • exec binding
  • shell script called by exec binding
  • three generic X10 items for exec in, exec out and exec run
  • one generic X10 rule for triggering the binding
  • one specific rule for each specific X10 item

I’ll just explain the pretty easy way of switching lights on an off. But if you are able to write shell scripts, the world is open to you :wink:

To be honest, I don’t like the openhab documentation at all, it is not easy to understand, but nevertheless, first have a look here:

But now, lets do the magic, step by step…

  1. Add the exec binding

  2. Add a thing based on the exec binding. Configuration:
    Command: “/usr/local/bin/OH3_X10_Mochad_Switch %2$s”
    Transformation: “REGEX((.*))”
    Intervall: 0
    Timeout: 15
    Autorun: off

  3. Add three string items:
    Nothing to configure, but it is important, that these are string items

  4. Go to Exec-Binding Thing and edit Channel:
    Link Output to X10_Out item
    Link Input to X10_In item
    Link Run to X10_Run item

  5. Go to Rules. Add a Rule called “X10_Run”
    “When X10_in received a command, execute a given script”
    The script:

if (X10_Run.state != ON) {
  // the Run indicator state will go ON shortly, and return OFF when script finished
  logInfo("Your command exec", "Script already in use, skipping execution.")
  1. Create your shellscript named “OH3_X10_Mochad_Switch”, here just my example for using NC to control mochad:
echo "pl $1 $2" | nc localhost 1099 >/dev/null
  1. Add the following line to “/etc/openhab/misc/exec.whitelist”:
    /usr/local/bin/OH3_X10_Mochad_Switch %2$s

  2. Add an Item for every X10 switch you want to control. e.g. “X10_Lamp_Bathroom”, type Switch.

  3. Add a rule for every X10 switch you want to control, e.g.
    “When X10_Lamp_Bathroom changed, execute a given script”
    The script:

if(X10_Lamp_Bathroom.state == ON){
      X10_In.sendCommand("C1 ON")
      X10_In.sendCommand("C1 OFF")

The magic: The specific rule sends a command to X10_In, when a switch is changed. The X10_In triggers the Exec-Thing with the input parameters (X10 Addresses). The The Exec-Thing triggers the the X10_Run item and calls the shell-Script, if not running.

For switching X10 lamps this is completely sufficent. If you want to react on mochad output, you have to add rules for X10_out item.

So, for adding new lamps/switches you now just need to do step 8 and 9.

For me that works fine and easy and no need to host a separate OH instance… Add metadata to your X10-Switch-Items to make them visible for Alexa, Siri, etc…

1 Like

I can’t get this to work.

I can turn on light with both commands:

echo “pl A1 ON” | nc localhost 1099 >/dev/null

OH3_X10_Mochad_Switch A1 ON

But OpenHAB is not working when I try to switch the ITEM.

I followed every step, including the adding OH3_X10_Mochad_Switch %2$s to the exec.whitelist but it’s not working.

I also tried to change the rules following this documentation using itemRegistry but no-go…

Did you take a look into the OpenHab-Log? Normally it shows in detail, what failed.

Other idea: Maybe the skript has not the correct rights to be executed by openhab? But that also would be stated within the logfile.

1 Like

Where is the log stored at?

Also, when I remove the X10_Run and rule and set it to autorun, it runs once but it won’t run again, like if it was stuck on always ON and not exiting.


Use “tail -f /var/log/openhab.log” in a second terminal and check in parallel, what happens, when you change the switch…

1 Like

Not there… BTW this is a docker…

tail: cannot open ‘/var/log/openhab.log’ for reading: No such file or directory

I had to use Blockly to do the scripts also, here is what a switch script looks like:

if (itemRegistry.getItem(‘Master_Bedroom_Light’).getState() == ‘ON’) {
events.sendCommand(‘X10_In’, ‘A1 ON’);
} else {
events.sendCommand(‘X10_In’, ‘A1 OFF’);

Ok, found it…

2021-05-10 16:52:58.203 [INFO ] [org.openhab.rule.019339a944 ] - Script already in use, skipping execution.
2021-05-10 16:53:46.167 [INFO ] [org.openhab.rule.019339a944 ] - Script already in use, skipping execution.
2021-05-10 16:53:52.079 [INFO ] [org.openhab.rule.019339a944 ] - Script already in use, skipping execution.

It stays running after the 1st time it runs. It somehow needs to stop execution.

X10_Run string item was staying “ON”, switched it to “Switch” and it worked once. It’s back again…

OK, so found the problem… My script (that runs nc) is running and not exiting because nc isn’t exiting. Any way of terminating after the echo or after a second?

Just figured out a work-around… pkill nc before running the nc will only have 1 nc running and won’t lock up. Now on to Alexa… ugh… LOL

Well, got openhab clound and alexa all connected, but Alexa can’t find any of my devices (items)

EDIT: Found problem, wasn’t labeling and Alexa needed the label field.

NOTE: This was done after having it all setup, I may have missed a step or two, so will edit if needed.

A HUGE thanks to @Nobser which I used almost all instructions from his solution but had to update a few to accommodate my docker installation, so here is the working solution for me.

  1. Installed openHAB 3.0.2 (Docker - had to copy nc which wasn’t included)

  2. Setup openHAB 3 with Exec binding, added openHAB cloud connector, connected to my account and setup the openHAB Skill on Alexa.

For openHAB 3 docker and openHAB cloud connector, uuid is in “/openhab/userdata/uuid” while secret is in “/openhab/userdata/openhabcloud/secret”

  1. Created “/openhab/conf/scripts/pl” file with:

pkill nc
echo “pl $1 $2” | /openhab/conf/scripts/nc {ip of mochad docker/service} 1099 >/dev/null

and changed permissions to pl: chmod u+x /openhab/conf/scirpts/pl

Step 3 was changed and added pkill nc to kill all nc commands previously executed, reason why it would work several times, then it would stop working.

  1. Added “/openhab/conf/scripts/pl %2$s” to “/openhab/conf/misc/exec.whitelist”

  2. Created Thing named it “X10” with command “/openhab/conf/scripts/pl %2$s” left defaults.

  3. In thing X10 channels, created Input link name “_Command”

  4. In thing X10 channels, created Running link name “_Execute”

  5. Created a rule name “_Rule”, added When trigger selected Item Event “_Command” and selected “changed”, then added Then trigger selected Run Script and ECMAScript with:

events.sendCommand(’_Execute’, ‘ON’);

Step 8 was changed and we no longer check if it’s running since we are killing “nc” processes before sending a new “nc” command. “nc” wasn’t exiting/stopping.

  1. For each switch I created an Item of Type Switch name “Test_Light” and label “Test Light”

  2. After creating switch, added Metadata “Amazon Alexa” of Type “Switchable” and under Advanced selected Category “LIGHT” to keep all my lights under “LIGHT” instead of “SWITCH”

  3. For each Item, I created a rule name “_Test_Light”, added When trigger selected Item Event “Test_Light” and selected “receives a command”, then added Then trigger selected Run Script and ECMAScript with:

if (itemRegistry.getItem(‘Test_Light’).getState() == ‘ON’) {
events.sendCommand(’_Command’, ‘A1 OFF’);
events.sendCommand(’_Command’, ‘A1 ON’);
} else {
events.sendCommand(’_Command’, ‘A1 ON’);
events.sendCommand(’_Command’, ‘A1 OFF’);

Step 11 has an additional reversed command since Alexa does not switch ON if switch is already ON, so turning it OFF first solved this issue.

NOTE: Repeat steps 9 thru 11 for additional switches (with different names, tags and house/unit codes of course)

  1. On Alexa Discover New Devices and enjoy!

Again, CREDIT and a HUGE THANKS goes to @Nobser without his help I wouldn’t have been able to get my openHAB 3 / MochadX10 / Alexa project completed.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.