Integrating weather sensors with Home Assistant

We have a thermometer/hygrometer kit to keep track data:

Home Assistant temperature tile

It is actually easy to capture and decode RF signals using a DVB-T USB dongle, the RTL-SDR driver and the RTL-433 decoding software.

An RTL8232-based DVB-T dongle is normally used to receive Digital Video Broadcasting TV signal in Europe. Even though it is useless for TV in North America (where the DVB standard is ATSC), a DVB-T receiver can also be used to decode a wide range of radio signals including FM or 433 MHz data signals.

It so happens that besides the base sensors embedded in the display, the three separate sensors transmit data using 433 MHz RF signals.

I purchased a RTL8232 DVB-T dongle for approximately $20 and used spare Raspberry Pi (original B+) to run RTL-433. I installed Raspbian and set up RTL-433 as follows:

1. Install rtl-sdr

sudo apt-get install rtl-sdr

This is the driver module. You need this for the OS to communicate with the DVB-T dongle.

2. Install packages needed to build RTL-433

Currently RTL-433 is not in the Raspbian sofware main repository, and when enabling the testing repos, I start running into dependy issues, so I figured that building rtl-433 from source would probably be a safer bet.

sudo apt-get install git git-core cmake build-essential     # build tools
sudo apt-get install libtool libusb-1.0.0-dev librtlsdr-dev doxygen  # needed to build rtl-433

4. Build rtl-433

git clone https://github.com/merbanan/rtl_433.git
cd rtl_433
mkdir build
cd build
cmake ../
make
sudo make install

If everything went well you now have rtl_433 in /usr/local/bin

5. Create a shell script to run rtl_433 with the parameters that correspond to your RF device's protocol

In my case, the transmitters are LaCrosse-TX141THBv2 units, which corresponds to protocol 73 in the rtl-433 documentation.

#!/bin/bash

# For LaCrosse TX141THB v2
rtl_433 -R73 -F mqtt://localhost:1883,retain=1,devices=sensors/rtl_433[/model][/channel] -M time:iso

# For LaCrosse TX141THB v2 and RediCheck ET-731 BBQ thermometer
# The ET-731 uses protocol 71. It transmits at a sligtly different frequency, therefore
# I need to alternate between frequencies every 120 seconds
#rtl_433 -f 433.92M -f 433.75M -H 120 -R73 -R71 -F mqtt://localhost:1883,retain=1,devices=sensors/rtl_433[/model][/channel] -M time:iso

6. Install and run an MQTT broker (if you don't already have one)

I went quick and dirty, installed it on the Pi itself, with anonymous updates allowed. You should proabaly set up proper authentication.

sudo apt-get install mosquitto

Edit the mosquitto configuration /etc/mosquitto/mosquitto.conf:

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

password_file /etc/mosquitto/pwfile
allow_anonymous true

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

Enable and run mosquitto:

systemctl enable mosquitto
systemctl start mosquitto

I collect MQTT information from HomeAssistant, using the MQTT integration.

7. Install and configure Supervisor

Supervisor allows you to automatically start rtl433 and watch that it is still running. If rtl433 stops, supervisor will restart it automatically.

sudo apt-get install supervisor

Then add an rtl_433.conf config file in /etc/supervisor/conf.d/rtl_433.conf

[program:rtl_433]
command=/usr/local/bin/rtl433.sh
autostart=true
autrestart=true
stderr_logfile=/var/log/rtl433.err.log
stdout_logfile=/var/log/rtl433.log

Enable and start the supervisor service

systemctl enable supervisor
systemctl start supervisor