Skip to content

Instantly share code, notes, and snippets.

@mva-one
Last active November 30, 2022 17:09
Show Gist options
  • Save mva-one/8c1ed7bd3820d09ad38d92cabc798964 to your computer and use it in GitHub Desktop.
Save mva-one/8c1ed7bd3820d09ad38d92cabc798964 to your computer and use it in GitHub Desktop.
OpenHAB + Proxmox + MQTT + 433MHz Remote Controlled Sockets

SmartHome integration of 433MHz Remote Plugs ("Funksteckdosen")

Recently I found some older radio-controlled sockets in the attic, but these are not particularly easy to control with my existing SmartHome system, based on openHAB.

But instead of throwing them away and buying some new WiFi-controlled sockets (with Tasmota, of course ;), I decided to resue them and integrate them into my system.

Due to the lack of a return channel in the "433MHz radio frequency sockets system", only unidirectional communication is possible: my Smarthome system sends the command to switch on or off, but it does not receive any feedback as to whether the sockets received the command and actually switched accordingly. So that's nothing I could do about and that's why I only use these sockets for some non-critical applications, such as controlling some christmas decoration lights.

I will leave aside the obvious security problems due to the lack of encryption of the radio signal...

Transmitting the correct 433MHz signal

To get started, I needed a way to transmit the correct radio signals on the 433MHz frequency, according to the settings of the sockets, so I got my transmitter I had from an earlier project and started researching how to send the correct codes.

The transmitter I had is a so called "NanoCUL", essentially an Arduino Nano with a 433MHz radio module attached to it, which receives specific commands via its USB-serial port.

https://www.smart-home-komponente.de/nano-cul/nano-cul-433/

http://culfw.de/commandref.html

To be able to send ON and OFF commands to the sockets, I needed to convert their settings to a specific code, like described here: https://wiki.fhem.de/wiki/Intertechno_Code_Berechnung

Example: One of my sockets has its DIP switches set to 01110-10000 which means the "system code" is 01110 and the "unit code" is "A". The corresponding command to turn the socket on is is0FFF00FFFFFF.

First, I needed to configure the serial port settings accordingly:
stty -F /dev/ttyUSB0 38400 cs8 -cstopb -parenb

As I sent this command to the serial port the NanoCUL was attached to, the socket indeed turned on! 🥳
echo is0FFF00FFFFFF > /dev/ttyUSB0

MQTT Integration

Since I did not want my openHAB system to directly issue shell commands, I decided to make up a quick shell script running as a service inside an (unprivileged) Proxmox Container to receive commands via MQTT and transmit the correct sequence via the serial port. This tutorial https://gist.github.com/crundberg/a77b22de856e92a7e14c81f40e7a74bd was really helpful!

First, I needed to get the cgroup number of the serial device on my Proxmox host machine:
ls -ln /dev/ttyUSB0

The command returned a row like

crw-rw-rw- 1 0 20 188, 0 28. Nov 22:22 /dev/ttyUSB0

...with 188 being the number I was looking for.

Then I created a device file with the correct permissions, so an unprivileged Proxmox LXC container (in this case with ID 105) can access it:

mkdir -p /lxcdev/105/
cd /lxcdev/105/
mknod -m 660 ttyUSB0 c 188 0
chown 100000:100020 ttyUSB0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment