Years ago I used X10 for house automation, nothing real fancy just some PIR sensors that could turn on light and some remote controls to control lights.
The X10 system communicated over the power-line, which ended up being quite error-prone especially after everything started to use switch-mode power supplies, I have no intention of using the powerline X10. I am only interested in detecting the RF commands from X10 PIR and remotes
X10 RF used wireless communication, on 310 Mhz or 433MHz, and I still have quite a few PIR sensors and remote controllers in a drawer. The quest is to make these useful again.
X10 RF is not sophisticated, it is simply an old-fashioned remote control over RF instead of using IR, there are 16 house-codes, which each can have 16 devices, which can be turned on/off/dimmed.
How can we receive the X10-RF commands?
- OpenMQTTGateway should be able to do it, you just need a way to detect the RF-signal. probably a small cc1101 board from Aliexpress, and an esp32 would do the trick.
- The X10 CM19A dongle is a X10-RF-to-USB adapter, So a small demon which forward the traffic received on the RF link to a MQTT-server. You can still buy a CM19A for $25 on Amazon.com, note that this is surely the US version which run on 310 MHz
Resources
- heyu.org X10 Automation for Linux, Unix, and Mac OS X
- mochad reference
- www.sigmdel.ca: Mochad on Recent Linux Distributions
- Github: sigmdel/mochad
- Home-Assistant: X10 Mochad to MQTT Gateway Addon
- Github: jeffs555/mochad-mqtt-ha-addon
- Github: kevineye/docker-heyu-mqtt
- Github: timothyh/mochad-mqtt
- Github: StoaferP/mochad_dispatch
mochad_dispatch is what will be used
This is using python-code to talk to MQTT and mochad which is written in C to talk to the X10-RF transceiver over USB.
This run from a docker container using docker-compose.yml
services:
mochad:
image: jshridha/mochad:latest
container_name: mochad
restart: unless-stopped
privileged: true
devices:
- /dev/bus/usb:/dev/bus/usb
ports:
- "1099:1099"
mochad_dispatch:
build: ./mochad_dispatch
container_name: mochad_dispatch
restart: unless-stopped
depends_on:
- mochad
command:
- mochad_dispatch
- -f
- -s
- mochad
- -m
- homeassistant/mochad_dispatch
- mqtt://192.168...:1883,user=....,pass=....
I use a simple Makefile to get hold of the source and save my changes to the code.
NAMES += mochad_dispatch
.PHONY: default Patches Clone Patch
default: Patch
Clone: ${NAMES:=.clone}
Patch: ${NAMES:=.patch}
Patches: ${NAMES:=.diff}
%.clone:
@if [ -d "$*/." ]; then \
echo "Source $* exists"; \
else \
if [ -f "Patches/$*.url" ]; then \
git clone "$$(cat Patches/$*.url)" "$*"; \
fi; \
if [ -f "Patches/$*.gitHEAD" ]; then \
git -C "$*" checkout -b local-patch "$$(cat Patches/$*.gitHEAD)"; \
fi; \
fi
%.patch: %.clone
@if [ -f "$*/.patched" ]; then \
echo "Source $* already patched"; \
elif [ -f "Patches/$*.patch" ]; then \
patch -d "$*" -p1 < "Patches/$*.patch" && touch "$*/.patched"; \
fi
%.diff:
@if [ ! -d "$*/.git" ] && [ ! -f "$*/.git" ]; then echo "No git for $*"; exit 1; fi
mkdir -p Patches
if [ -n "$$(git -C "$*" remote)" ]; then \
git -C "$*" remote get-url origin > "Patches/$*.url"; \
else \
touch "Patches/$*.is_local"; \
fi
git -C "$*" rev-parse --short HEAD > "Patches/$*.gitHEAD"
git -C "$*" diff HEAD > "Patches/$*.patch"
The code comes from https://github.com/StoaferP/mochad_dispatch.git
which is stored in Patches/mochad_dispatch.url
and the changes I had to make is saved in Patches/mochad_dispatch.patch
diff --git a/Dockerfile b/Dockerfile
index deedae8..2d1424e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,3 +1,5 @@
-FROM jfloff/alpine-python:3.4
-COPY . /src
-RUN cd /src; python setup.py install
\ No newline at end of file
+FROM python:3.11-alpine
+WORKDIR /src
+COPY . .
+RUN pip install --no-cache-dir .
+
diff --git a/mochad_dispatch/main.py b/mochad_dispatch/main.py
index 855597b..38f6040 100644
--- a/mochad_dispatch/main.py
+++ b/mochad_dispatch/main.py
@@ -425,7 +425,7 @@ class MochadClient:
Connect to mochad
"""
- if self.reader is not None:
+ if getattr(self, "reader", None) is not None:
self.reader.close_connection()
self.reader = SocketReader(self.host, 1099)
@@ -603,6 +603,7 @@ def main():
args = parser.parse_args()
+ base_path = None
if base_path is None:
base_path = os.path.abspath("./")
