A python gateway to publish Rfxcom sensor values to an MQTT broker.
The source code for decoding the Rfxcom protocol comes from a very old project I had. I haven't any reference from the origin of the information about the Rfxcom protocol, so I can't give thanks for the author, maybe the author of the document from I base my code its the Rfxcom company itself. In any case if you consider than you can be the author of the Rfxcom protocol information where I based on, please feel free to contact me to add you to the credits.
Several years ago I coded some programs for a protocol called xAP, one of this was a Rfxcom gateway to this protocol because I had a now discontinued Rfxcom device to decode X10RF protocol, Oregon Scientific and Visonic sensors. Recently I buyed an Oregon Scientific LW301 wheather station with the hope to add it to my home automation system based on home assistant. This wheater station has a gateway to sends the sensor data to a web platform that currently not works. I know this before I buyed but the price is good for the sensors it includes. Additionaly I had several Oregon Scientific temperature with humidity sensors in a box, so I started to think to retrieve my old code done for xAP and create this gateway for the MQTT protocol.
If you are interested you can find a detailed list of the Oregon Scientific sensors supported in this link
Coming back to my rfxcom device, this model is a box called "Universal Interface version 1", now it is discontinued from Rfxcom. But for give you some details, it offers only an USB port and a BNC connector for the antenna. Inside, there are one small PCB receiver with support for some 433MHz RF devices and another small PCB receiver for Visonic 866MHz devices (I bought this PCB apart).
My idea is connect this Rfxcom device to a Raspberry Pi and use this program for publish the sensor information received by the Rfxcom device to the MQTT protocol. This program is not limited to the Raspberry Pi so you can use in other platforms.
The Rfxcom supports several sensors, I had support for all of them in my old xAP project, but for this gateway I only support some of them, here is the list of sensors supported by the Rfxcom device and the support of this application:
- ARC-Tech (KlikOn-KlikOff, ELRO AB600, NEXA and Domia lite)
- ATI Remote Wonder
- HomeEasy
- Ikea-Koppla
- Oregon scientific (list of supported sensors)
- RFXCOM sensors
- Visonic
- X10 RF
- X10 security
-
First, update your distribution.
sudo apt update sudo apt upgrade
-
Install Python pip and some dependencies.
sudo apt install python3-pip pip3 install pyserial pip3 install paho-mqtt
-
Install git and clone the repository.
sudo apt install git cd~ git clone https://github.com/homected/Rfxcom2Mqtt.git rfxcom2mqtt
-
Set your own configuration parameters editing the program file.
cd rfxcom2mqtt sudo nano rfxcom2mqtt.py
You have to replace the text between quotes with the correct values for your configuration:
- COM_PORT: Something like /dev/ttyUSB0 or COM1 or /dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0;
- MQTT_Host: The IP Address of the MQTT broker;
- MQTT_Port: Port of the MQTT broker, for example 1883;
- MQTT_User: Username to authenticate into the MQTT broker;
- MQTT_Password: Password to authenticate into the MQTT broker;
- MQTT_Topic: The topic of the MQTT broker where publish the data;
- MQTT_QoS: Quality of Service level (0, 1 or 2);
- MQTT_Retain: True for retain MQTT messages of False for not retain;
Save and close the file with: Control+O, Enter, Control+X
-
Optionally, you can set this program runs automatically when the raspberry boots with these commands:
sudo cp rfxcom2mqtt.service /lib/systemd/system/rfxcom2mqtt.service sudo chmod 644 /lib/systemd/system/rfxcom2mqtt.service sudo systemctl daemon-reload sudo systemctl enable rfxcom2mqtt.service
-
For start manually the program you can use this command:
python3 rfxcom2mqtt.py
If you set the program to run after boots, reboot the raspberry with this command:
sudo reboot
After boot, you can control the process with these commands:
sudo systemctl start rfxcom2mqtt sudo systemctl status rfxcom2mqtt sudo systemctl stop rfxcom2mqtt
The values received by the rfxcom device will be published under the topic set in MQTT_Topic inside the program file into the MQTT topic MQTT_Topic/sensorAddress/value.
following there are some examples from Oregon sensors with MQTT_Topic set to "myTopic/rfxcom":
- myTopic/rfxcom/0500472/Temperature: {"state":"24.1","unit_of_measurement":"°C"}
- myTopic/rfxcom/0500472/Humidity: {"state":"22","unit_of_measurement":"%"}
- myTopic/rfxcom/0500472/BatteryLow: {"state":"0"}
- myTopic/rfxcom/0E00EC0/Rain rate: {"state":"0.0","unit_of_measurement":"mm/hr"}
- myTopic/rfxcom/0E00EC0/Rain total: {"state":"428.6","unit_of_measurement":"mm"}
- myTopic/rfxcom/0E00EC0/BatteryLow: {"state":"0"}
- myTopic/rfxcom/11006B0/Wind direction: {"state":"22.5","unit_of_measurement":"°"}
- myTopic/rfxcom/11006B0/Speed: {"state":"2.6","unit_of_measurement":"m/s"}
- myTopic/rfxcom/11006B0/SpeedAvg: {"state":"3.4","unit_of_measurement":"m/s"}
- myTopic/rfxcom/11006B0/Battery: {"state":"100","unit_of_measurement":"%"}
To get the values of the energy monitor in Home Assistant, enter a sensor entry for each monitored value in your configuration.yaml file:
sensor:
- platform: mqtt
state_topic: "myTopic/rfxcom/0500472/Temperature"
name: "rfxcom_0500472_temperature"
unit_of_measurement: "°C"
value_template: '{{ value_json.state }}'
- platform: mqtt
state_topic: "myTopic/rfxcom/0500472/Humidity"
name: "rfxcom_0500472_humidity"
unit_of_measurement: "%"
value_template: '{{ value_json.state }}'
- platform: mqtt
state_topic: "myTopic/rfxcom/0500472/BatteryLow"
name: "rfxcom_0500472_battery_low"
value_template: '{{ value_json.state }}'