This post describes how I have setup an RFXtrx433E device with a Raspberry Pi to transform data from inexpensive 433 MHz motion- and climate-sensors into MQTT messages on my local network. With the data available as MQTT messages I can store the data in InfluxDB for viewing in Grafana, show the data in Home Assistant and route the data to cloud services.
I have some home made sensor devices scattered around our home that sends detection and climate information via 433 MHz using my own simple protocol. The signals are registered by an ESP8266 device that transforms the messages to MQTT messages over IP. These MQTT messages then go into a database, to the cloud and into Home Assistant. See these posts for details:
I recently bought some inexpensive off-the-shelf 433 MHz sensor devices that I want to include in my home automation system. As they use proprietary protocols for communication, I looked for different solutions for parsing their data and finally settled on RFXtrx433E which is a 433 MHz transceiver that can read and write a set of different protocols.
My new sensors
The new sensors that I want to include in my system are a Telldus motion sensor and a Telldus outdoor temperature/humidity sensor. I also have an old no-name thermometer that I want to add to my system.
Getting started with Rfxtrx433E
RFXtrx433E is a USB-attached device that supports a wide range of 433.92MHz protocols for incoming- and outgoing data.
For reducing noise when reading data, it is preferable to activate only the protocols that are needed in your setup. To change active protocols and also test what works with your devices, rfxcom’s RFXmngr has to be used. It can be downloaded from rfxcom’s site http://www.rfxcom.com/.
Unfortunately it is a Windows-only application, so I had to boot up an old Windows PC to configure my RFX-device. I started out with all protocols activated and noted in rfxmngr what protocols and ID:s my new sensors used (by watching the log window when my devices transmitted data). I came up with these protocols and ID:s:
After reducing the number of active protocols to these ones and storing the settings on the device, I could move the RFXtrx433E to my Raspberry Pi / Linux environment.
Using the rfxtrx platform in Home Assistant
After attaching the RFXtrx433E to my Raspberry Pi, my first experiment was to let Home Assistant read from the device via USB. I set up the rfxtrx platform according to:
It worked fine, but as I want the data and events to also go into other destinations like a database, I figured it would be better to have the RFXtrx433E messages transformed into MQTT messages first and then let Home Assistant and other applications subscribe to these messages. How to achieve this? I found a solution with Node-RED, see below.
Using Node-RED for transforming RFXtrx433 messages to MQTT
Node-RED is a NodeJS-based platform that can be tailored for a lot of different purposes. It is very useful for transforming data from one format to another and let data go in different directions depending on conditions that you define. Node-RED is easy to install on a Raspberry Pi (see https://nodered.org/docs/hardware/raspberrypi) and it can be configured via a browser on port 1880 (default).
Node-RED is configured with “flows” that typically reads data from a set of sources, checks some conditions, transforms the data and outputs it to different destinations. I want to transform data from RFXtrx433E to MQTT. It turns out that there is a perfect Node-RED package (by Maxwell Hadley) for this purpose:
With this package installed for Node-RED, I was able to create a flow that transforms the data from my two climate devices (temperature, temperature+humidity) and my motion detector to MQTT messages:
Node-Red flow details
This node reads from the rfxtrx device connected to the Raspberry pi. The msg.payload object will contain a temperature and a humidity property for my Telldus outdoor sensor and a temperature object for my no-name sensor. The msg.topic property is the name and ID of the device. (The structure of the rfxtrx objects can be investigated by adding a debug node to the rfx-sensor read node and checking the logs)
Route RFX to MQTT
This node routes the data to different nodes depending on the topic (which is the name and ID of the device):
Create message and topic
These nodes takes the sensor value and sets it as msg.payload. The msg.topic is set to the desired MQTT topic. For the Telldus outdoor temperature, the node would be configured like this:
Publish MQTT package
This node uses the msg.topic and msg.payload (from the previous node) as MQTT topic and MQTT message and publishes it to an MQTT broker (my broker is on IP address 192.168.1.16 with the default port 1883):
The Telldus motion sensor sends on-events via a Lighting protocol. I thus use the rfx-lights input node to read the data:
Check if porch motion sensor
To check that the on-event is actually from my device, I setup a switch node that only routes the message if it matches my device.
Increase motion count as msg.payload
A counter in the flow is used for creating messages with values from 0-100 (and then the counter starts from 0 again).
As the message for the motion sensor was created in the previous node, I only have to set the proper topic before publishing the MQTT message:
Testing the setup
The setup can be tested by using mosquitto_sub on a computer on the local network (where the -h switch specifies the ip-address where the mosquitto broker is running):
mosquitto_sub -h 192.168.1.16 -t "Home/#" -v
This command will subscribe to all MQTT topics starting with Home/ and outputs the topic and value when a message is received. With my sensors active, it should produce an output similar to:
Home/Porch/Temperature -2.6 Home/Outdoor/Temperature -3.6 Home/Outdoor/Humidity 82 Home/Porch/Motion 3
Configuring Home Assistant with MQTT sensors
I removed the rfxtrx-platform configurations from Home Assistant and added some MQTT sensors instead:
I use customization to give the entities dedicated icons and friendly names for the display:
so that they look nice in my Outdoor group:
For the motion sensor to display when the last motion was detected, I use a template sensor:
It will appear as:
Storing the new MQTT messages in a database and viewing them with Grafana
In InfluxDB and Grafana for sensor time series I have described how I store all “Home/” messages in InfluxDB so that I can view them via Grafana. With my new topics available in the database, I can just add some new graphs to Grafana:
Routing the new MQTT messages to a cloud service
In A self-hosted MQTT environment for Internet of Things – Part 3 I have shown how I route MQTT message to the Adafruit IO cloud service. I can simply modify my routing rules to send my new topics to Adafruit IO. With Adafruit IO I can connect to IFTTT and build event chains depending on the data content.
As the RFXtrx433E is a transceiver, it can also be used for sending commands. I have created a new Node-RED flow for controlling a set of Telldus 433 MHz outlets via MQTT. The Node-RED flow is available from my GitHub repository.
My Home Assistant and Node-RED configurations are available from GitHub: