Elektor_Mag_-_January-February_2021

([email protected]) #1

30 January & February 2021 http://www.elektormagazine.com


With the example configuration file, rtl_433 now shows the output
of each sensor as a JSON dictionary (Figure 5). This is already a big
step forward to integrate your 433.92 MHz sensors into your home
automation setup, but the final step is to publish these values to
your MQTT broker.

Publishing 433.92 MHz sensor values to MQTT
The rtl_433 program has already support for sending the sensor
values it receives to an MQTT broker. Open the configuration file
(/home/pi/containers/rtl433tomqtt/rtl_433.conf) and find the line
that says:

output json

You can keep this line here because you can specify multiple
outputs, or change it to output kv if you prefer the default more
human-friendly output. Add the following line to define an MQTT
output:

output mqtt://mosquitto:1883,user=home,pass=PASSWORD

Make sure to enter the correct username and password for your
MQTT broker.

Warning: The rtl_433 program doesn’t support MQTT over TLS. If
you’re running the rtl_433toMQTT container on the same Raspberry
Pi as your mosquitto container, it’s no problem that they communi-
cate unencrypted: they’re on the same machine anyway. If you have
your RTL-SDR receiver on another machine than your MQTT broker
(for instance because you have better coverage there), I recom-
mend you run a mosquitto container aside from the rtl_433toMQTT
container and configure it as a bridge to your main MQTT broker
over an encrypted connection. See the appendix at the end of this
book for the details.

After a restart of your container, you should see an MQTT message
published under the rtl_433 main topic for each sensor value. You
can view this with:

mosquitto_sub -t ’rtl_433/#’ -v

For instance, every time the temperature and humidity sensor in
my freezer transmits a message, I see data like in Figure 6.

Now, you can still tweak a couple of things from the MQTT config-
uration. Consult the comments in the example configuration file
for the details. For instance, this configuration changes the MQTT
topics to something shorter:

output
mqtt://mosquitto:1883,user=home,pass=PASSWORD,device
s=rtl433/[model]/ [channel]/[id]

And if you’re not interested in the low-level metadata about the
radio connection, such as modulation, frequency, RSSI (received
signal strength indicator), SNR (signal-to-noise ratio) and noise,
just remove or comment out the report_meta level line in the
configuration file.

ration, which was fine for testing but didn’t use MQTT. Now let’s copy
an example configuration file to a path where rtl_433 is searching:


docker cp rtl433tomqtt:/usr/local/etc/rtl_433/
rtl_433.example.conf /home/pi/containers/
rtl433tomqtt/rtl_433.conf


Because I have mapped the directory containers/rtl433tomqtt in
your pi user’s home directory to /home/user/.config/rtl_433 in the
container, you can now edit this configuration file and restart the
container to use this configuration. For instance, you can disable
protocols you don’t need, or enable protocols that are disabled
by default.


The configuration file is heavily commented, which should help
you figure out what to change. Moreover, you can find a lot of
information in rtl_433’s online documentation (https://triq.org/
rtl_433/), including steps to add support for a sensor that is not
(yet) supported.


After the changes to your configuration file, restart the container:


docker restart rtl433tomqtt


If all goes well, the logs should show that rtl_433 stops searching
for a configuration file after the second file and finds it:


Reading conf from "/home/user/.config/rtl_433/
rtl_433.conf".


Figure 6: The rtl_433 command can send the received sensor values to your
MQTT broker.


Figure 5: The rtl_433 command can show the sensor values in many
formats, including JSON.

Free download pdf