[Release] X-10 Devices using Mchad or Heyu with Node Red bridge

Hubitat Apps and Device Handlers for X-10 Devices using Mchad or Heyu with Node Red bridge

Image of Logo

This solution allows 2-way communication between Hubitat and X-10 devices using Node Red and Mochad. You can control your X-10 devices from within HE and use various automation solutions within HE. You can also use X-10 remotes and motion sensors to control other devices. X-10 equipment is fairly inexpensive and readily available on E-Bay etc.

In this solution all X-10 settings and device mappings are done using the Hubitat app. Only a couple of one-time settings need to be made on the Node Red flow.

See the orginal ST page for details and user discussions

Changes from ST Version

  • Uses telnet connections for more robust connectivity between node red server and HE. The default TCP port is 1025, you may need to change it, if its not available on the machine where you are running the node red server

  • Device P-15 is reserved for pinging the system to maintain connectivtiy every 30 minutes. If you need to use this device for something else you can change it in x-10-node-red-mochad-device.groovy

  • Heyu functionality has NOT been tested, since I don't have a heyu device. For ST a heyu user worked with me to do the implementation. If anyone is interested ping me, if you can compare it code and make the changes yourself, feel free to send me a PR

Supported Devices and Functionality

  • X-10 Switches and Modules - on/off and dimming are supported

  • X-10 Motion Senors and Remote buttions - on/off funtions supported from devices sending housecode/unitcode on/off commands

  • X-10 Security Devices

Please note: Dimmer functions are a bit wonky - don't rely too much on percentage just treat them like up/down buttons becaue that's what is available on physical X-10 devices. You can get percentages almost right, if you caliberate by setting to 0 and physically dimming to dark, but it remains dicey, there is no good solution to it.

Requirements

Raspberry Pi

These instructions are for Raspberry Pi, but they can be easily adapted to any Linux variant

Mochad and CM15A or CM19A USB Devices

Mochad exposes a TCP interface to X-10 commands, and can run on any linux system including Raspberry PI. It uses CM15A or CM19A USB devices to communicate with X-10 over RF or powerline. Using these devices you are not limited to a single house code, you can use any of the 15 house code with any x-10 device.

https://bfocht.github.io/mochad/

https://bfocht.github.io/mochad/mochad_reference.html

Node Red

Node-RED is a programming tool for wiring together hardware devices, APIs and online services using a browser-based editor. Node Red is very simple to deploy and is very light-weight. Requires very little effort to setup and run

https://nodered.org/

https://nodered.org/docs/hardware/raspberrypi

Setup


Step 1: Install Mochad on Raspberry Pi

Follow any number of tutorials to setup your Raspberry Pi using your favorite distro, make sure you install the development tools. On Raspbian you can do this using the following command

> sudo apt-get install build-essential

Build mochad

  • Install libusb-1.0.0 development files. mochad will not build without this.

> $ sudo apt-get install libusb-1.0-0-dev

  • Get mochad source code and unpack it.

> $ wget -O mochad.tgz https://sourceforge.net/projects/mochad/files/mochad-0.1.17.tar.gz/download

> $ tar xf mochad.tgz

> Now build mochad.

> $ cd mochad*

> $ ./configure

> $ make

> $ sudo make install

  • Edit /etc/udev/rules.d/91-usb-x10-controllers.rules change the following line to :

> RUN+="/usr/local/bin/mochad &"

This ensures that mochad will load whenever the usb device is detected, include when Raspberry pi reboots

Blink a lamp

  • Plug in a CM15A, CM19A, or CM15Pro into a Raspi USB port. Connect a lamp to X10 module set for address A1.

  • If using a CM15A or CM15Pro try the following power line (pl) commands.

> $ echo "pl a1 on" | nc localhost 1099

> $ echo "pl a1 off" | nc locahost 1099

  • If using a CM19A try the following radio frequency (rf) commands.

> $ echo "rf a1 on" | nc localhost 1099

> $ echo "rf a1 off" | nc localhost 1099

At this point you should make a list of commands that you need to turn your X-10 devices on and off, you will need this later.

credit - X10 Linux: Installing mochad on a Raspberry Pi

Step 2: Install & Setup Node Red

Install Node Red

Follow the instructions on this page to install Node Red on your Pi Redirecting…

Play around a little bit to get the hangs of the basics

Setup Node Red

Step 3: Add the Apps and Drivers Code in Hubitat

You will need to install the following Apps and Drivers in the appropriate sections - make sure you install all of them

Step 4: Add App to Hubitat and configure X-10 devices

  • Add the X-10 Node Red Bridge Parent App in the Apps section in Hubitat IDE using 'Add Usser App' functionality

You will need to select the hub and configure IP address and port for the Node Red server - this should be the same IP address you use to connect to Node Red on the browser. Port is specified in the first node in the flow, it defaults to 1025 - ensure that you are using the same port on both sides

  • You can then add X-10 devices in Hubitat and set their X-10 addresses.

Once you add a switch you should be able to turn it on and off. You can map remote buttons and motion sensor address to any device that supports on/off function and control it.

Thanks for the tutorial. I haven't finished it yet but I discovered one problem involving mochad that I thought might help someone else.
I spent a whole day trying to get mochad to work until I found this post:

https://www.sigmdel.ca/michel/ha/domo/domo_08_en.html

The gist of the problem is Sourceforge considers 0.1.16 to be the latest version (as of 6/26/2019) but it has problems in Raspian Jessie. Version 0.1.17 has a fix for this problem. I replaced the line:

wget -O mochad.tgz http://sourceforge.net/projects/mochad/files/latest/download

with

wget -O mochad.tgz https://sourceforge.net/projects/mochad/files/mochad-0.1.17.tar.gz/download

and every thing else worked fine.
I'm sure Sourceforge will fix this at some point so be sure to check

https://sourceforge.net/projects/mochad/files/

Again, thanks to enishoca for this great tutorial and to Michel Deslierres for the fix for my Raspian Jessie on my Pi 3+.

Also, to check the mochad installation, try the suggestion in Michel's post:

sudo systemctl status mochad

both before and after plugging in your CM15A or CM19A devices.

Now for setting up Node Red!!!

1 Like

Thank you - I have updated the main post. My Pi was built long ago and there has been no reason to rebuild it.

I have Been following the SmartThings link that was mentioned in the opening post.

It seems someone has commented out a few lines, or set it to verify that the desired change has been executed. I don’t know if it has been added to the hubitat node-red.

I am having a problem with an automation. I am trying to set every switch to the off position via a rule machine. The problem I am seeing is when the hubitat sends “off” the node-red reads the current state and just changes it. If the device is off, it just changes it to the opposite status and turns it on. (If it is on, it turns it off). When I run it again, it again switched to the opposite status of the current light.

Rule machine:

Log file:

I thought it was rule machine problem, but now I think it is a nore-red /mochad problem.

Is anybody looking at this post anymore?