New RFXCOM to MQTT driver

I wrote a new MQTT driver for the RFXCOM rfxtrx433 (USB version). This driver lets you connect your RFXCOM to HA using MQTT. The RFXCOM RF modem does not need to be connected to your HA system directly, it can be located anywhere as long as it can reach the network and your MQTT broker. The driver runs on NodeJS and is based on the Node-RFXCOM library.

image

I wrote this driver because I was very unhappy with the HA built-in RFXCOM integration, which it completely replaces. This new driver does not use any form of awkward and unintuitive UI for configuration. All settings are in a YAML file. It’s as simple as it gets.

Right now the driver is still rather basic, but fully functional. It already supports a lot of temperature, humidity, rain, wind and integrated weather station sensors (including Oregon Scientific). Also lighting2 protocol switches, remotes and relays (DIO, CHACON, KlikAanKlikUit, HomeEasy, etc) and lighting5 protocol (OTIO, Conrad RSL), because those are the devices I have and can test. PRs for support of additional devices are definitely welcome !

Installation

The driver runs on NodeJS, do you need to make sure you have that one installed. Here is a quick install guide for Raspberry Pi and other Debian based systems. It can also be installed manually for ARMv6 systems like the Rpi0. NodeJS v16 minimum is required.

Next, run npm install to automatically install the dependencies.

Take a look at the supplied configuration.yaml file and enter the serial port your RFXCOM is connected to, as well as your MQTT broker:

serial:
  port: '/dev/ttyUSB0'

mqtt:
  server: 'mqtt://192.168.4.100:1883'
  username: 'user' 
  password: 'password'

The username and password are both optional.

Scanning for RF devices

Now run the driver in scanning mode:

node ./rfxcom.js --scan

This will show a list of devices the driver recognizes as they come in, with their device ID and protocol (and subtype for lighting / switch devices). You can use this information to fill your device section in the configuration.yaml for the next step.

You can also run a the driver in realtime stream mode. This will show all incoming data for all supported devices in realtime, with RSSI and command codes. This is more for debugging or if you’re interested in how frequently devices send data around you.

node ./rfxcom.js --stream

image

Adding devices to the configuration.yaml

Once you know your device IDs and protocols, you can simply fill them into the YAML. Use the provided sample config as an example:

temperaturehumidity1:
  topic: temp               # optional, topic name for devices using this protocol
  devices:
    '0xF501': 'bedroom'

lighting2:
  topic: 'switch'           # optional, topic name for devices using this protocol
  subtype: 'AC'             # The subtype of the protocol used for the transmitter (see the results of device scan)
  devices:
    0x01A8D1EA/1: 'bedroom'

Once you have your configuration setup, run the driver in normal operation mode:

node ./rfxcom.js

You can now view the MQTT topics come in using MQTT explorer, for example.

Adding as HA MQTT entities

For the example above, the MQTT entities in the HA configuration.yaml would look like this:

mqtt:
  sensor:
    - name: "Bedroom temperature"
      state_topic: "rfxcom/temp/bedroom/temperature"
      unit_of_measurement: "°C"

    - name: 'Bedroom humidity'
      state_topic: 'rfxcom/temp/bedroom/humidity'
      unit_of_measurement: '%'

  switch:
    - name: 'Bedroom light'
      state_topic: 'rfxcom/switch/bedroom/state'
      command_topic: 'rfxcom/switch/bedroom/set'
      payload_on: 'On'
      payload_off: 'Off'
      optimistic: true

Base topic names, the topic names for each protocol and of course the topic name for each entity / device can be freely configured. See the configuration.yaml example on the github repo.

Feedback welcome !

8 Likes

Awesome - will check it out! Thanks.

I get the part of becoming less HA depent on this, but as fairly limited user of rfxcom, what are the other benefits moving to this?

If you are not using MQTT and you don’t mind the built-in integrations UI, then there is probably no reason to move. This driver is specifically meant for users who are using MQTT or who prefer everything to be configured by (versionable) config files rather than a UI.

1 Like

Version 1.1 was released, adding support for dimmer lights and switches (for example the Chacon DIO 54524).

Use the following MQTT topics to interact with light dimmers:

Incoming data

This is data received from a 433MHz switch / dimmer device (for example from a remote control, a light switch or a transmitter micro-module).

  • Binary on / off commands are published to the state topic, for example rfxcom/switch/bedroom_light/state and the payload is On or Off.
  • Dimmer level commands are published to the level topic, for example rfxcom/switch/bedroom_light/level and the payload is the numeric dimmer level.

Outgoing data

This is the commands you send from HA to your 433MHz switches or dimmers. All commands are published to the set topic. For example, rfxcom/switch/bedroom_light/set. The payload can be one of the following:

  • Off turns the light / switch / outlet off.
  • On turns the light / switch / outlet on.
  • A numeric level turns the light to the specified brightness level.

Sending a brightness level will usually turn the device on at the same time, no need to send a separate On command (in fact doing this will usually make the light behave strangely). Turning on a dimmer with the On command will turn it on at the last set brightness. The brightness level range goes from 0 (minimum brightness) to a device dependent maximum. In the case of the Chacon DIO 54524 dimmer, the maximum level is 15.

In HA, an example MQTT configuration may look like this, so to smoothly integrate it with light dimmer functionality.

state_topic: "rfxcom/switch/bedroom_light/state"
command_topic: "rfxcom/switch/bedroom_light/set"
payload_on: "On"
payload_off: "Off"
brightness_scale: 15
brightness_state_topic: "rfxcom/switch/bedroom_light/level"
brightness_command_topic: "rfxcom/switch/bedroom_light/set"
brightness_value_template: "{{ value | int }}"
on_command_type: brightness
optimistic: true

Can you tell me how I can make it survive a reboot? I tried it via crontab but for some reason it does not work.

PS : not running on the same pi as the Home Assitant.

You’d write a systemd script for it.

[Unit]
Description=RFXcom MQTT Gateway
After=multi-user.target

[Service]
User=pi
Type=idle
ExecStart=/usr/bin/node /home/pi/rfcom.js

[Install]
WantedBy=multi-user.target

Something like that. Google for systemd

very promising and exactly what I’m looking for

RFY (Somfy RTS) protocol is not yet supported, is that it?

I’m afraid not, as I don’t have any Somfy devices.

When I do npm install, I have the following :

pi@raspberrypi-185:~ $ npm install

up to date, audited 49 packages in 5s

2 packages are looking for funding
 run `npm fund` for details

3 moderate severity vulnerabilities

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.

and npm audit this :

pi@raspberrypi-185:~ $ npm audit
# npm audit report

request  *
Severity: moderate
Server-Side Request Forgery in Request - https://github.com/advisories/GHSA-p8p7-x288-28g6
Depends on vulnerable versions of tough-cookie
No fix available
node_modules/request
  @hermannp/node-red-getproduction-fusionsolar  *
  Depends on vulnerable versions of request
  node_modules/@hermannp/node-red-getproduction-fusionsolar

tough-cookie  <4.1.3
Severity: moderate
tough-cookie Prototype Pollution vulnerability - https://github.com/advisories/GHSA-72xf-g2v4-qvf3
No fix available
node_modules/tough-cookie

3 moderate severity vulnerabilities

Some issues need review, and may require choosing
a different dependency.

And npm fund this :

pi@raspberrypi-185:~ $ npm fund
pi
├── https://github.com/sponsors/feross
│   └── [email protected]
└── https://github.com/sponsors/epoberezkin
    └── [email protected]

An idea ? :wink: