Skip to main content

mochad_dispatch is a daemon written in Python that translates mochad's tcp-based events to MQTT messages

Project description

mochad_dispatch allows you to connect your X10 security devices (door/window sensors, motion sensors, remotes) to home automation software like OpenHAB, Home Assistant or Domoticz

What exactly does it do?

mochad_dispatch connects to mochad (which reads messages from a USB receiver like the X10 CM15a) and listens for X10 security and button-press messages which now includes power line receipt of control messages (Rx PL) then publishes those to an MQTT broker.

It will automatically reconnect to both mochad and the MQTT broker. However, if a reconnect attempt fails for 60 seconds straight, mochad_dispatch will give up and exit.

How do I use it?

Run mochad_dispatch with a mochad hostname and a MQTT URI

$ mochad_dispatch -s hal9000 mqtt://mqtt.example.com:1883

Then subscribe to the appropriate device topics. The general format is

X10/MOCHAD_HOST/KIND/ADDRESS

where KIND is security for RFSEC alerts and button for button presses from an X10 remote. Note that button events are sent at QoS 0 and without the retain flag so they will not persist.

What about MQTT with TLS?

For TLS support use the ‘–cafile’ option like so

$ mochad_dispatch -s hal9000 --cafile /etc/pki/tls/cert.pem mqtt://mqtt.example.com:8883

What about MQTT username and password?

For username and password use the ‘,user=theusername,pass=thepassword’ appended to the URI like so

$ mochad_dispatch -s hal9000 mqtt://mqtt.example.com:1883,user=theusername,pass=thepassword

What about house code filtering?

You can also add filtering by house code as well using the -c/–housecodes optino and list your codes that you want to use. The default is all A thru P. To use just add -c AD or any other combination of house codes.

$ mochad_dispatch -s hal9000 -c AD mqtt://mqtt.example.com:1883

Troubleshooting

mochad_dispatch has been tested with mochad 0.1.17 and Mosquitto 1.4.3

Start by making sure your MQTT broker is relaying X10 messages by subscribing to the topic

X10/#

For example, using the mosquitto broker:

$ mosquitto_sub -v -t X10/#
X10/hal9000/security/C8:21:B2 {"dispatch_time": "2016-02-18T18:36:12.147877+00:00", "func": {"event_type": "contact", "event_state": "normal", "device_type": "DS10A", "delay": "min"}}
X10/hal9000/security/33:8C:30 {"dispatch_time": "2016-02-18T18:30:42.763780+00:00", "func": {"event_state": "normal", "device_type": "DS10A", "delay": "min", "event_type": "contact"}}

Dockerized App

Build the docker image (using the Dockerfile based on the jfloff/alpine-python image) and run the mochad_dispatch command. IMPORTANT: you must use the “-f” flag (to disable background/daemon mode) else the docker container will exit immediately.

$ docker build -t mochad_dispatch .
$ docker run -d -it mochad_dispatch mochad_dispatch -s hal9000 mqtt://mqtt.example.com:1883 -f

Dockerized App Full Stack Example

Run (and background) individual Docker containers to provide an MQTT broker, a MOCHAD daemon, and a MOCHAD_DISPATCH instance (assuming you’ve already built an image as described above):

$ docker run -d --name=mosquitto -p 1883:1883 -p 9001:9001 sourceperl/mosquitto
$ docker run -d --name=mochad -p 1099:1099 --device "/dev/bus/usb/005" jshridha/mochad:latest
$ docker run --link mosquitto --link mochad:hal9000 -d -it mochad_dispatch mochad_dispatch -s hal9000 mqtt://mosquitto:1883 -f

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mochad_dispatch-0.2.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mochad_dispatch-0.2.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file mochad_dispatch-0.2.1.tar.gz.

File metadata

  • Download URL: mochad_dispatch-0.2.1.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for mochad_dispatch-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1b94e4ca3858b7ad243cb6ee54e7b57496993d1cae587811696cd62ae01e9a20
MD5 89f121f5e119550db9f3fb0a65bb903d
BLAKE2b-256 b6a0a5c9048eee530e8c673e538b5de98069e1f300d87d2114bda02519664465

See more details on using hashes here.

File details

Details for the file mochad_dispatch-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mochad_dispatch-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1f94fd35e097c6ca72dfebd707c618e6586067ad7c4268ab3540a1b177e1713
MD5 aeb9a38e2542a0fcfac8e73dab95b872
BLAKE2b-256 82d9b3dadf585f9c8b24ec8b50c22dd92374178c3daec34bb1c31f7fafb5c0a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page