Home Assistant Add-on: rtl_433 with MQTT auto discovery

Hi! I’ve been trying to streamline my 433MHz sensor setup in Home Assistant, and ended up creating two simple add-ons that work together to get data from rtl_433 into HA thru MQTT with automatic discovery. So now, whenever I turn on a new Acurite temperature sensor, it automagically shows up as a device under the MQTT integration, with separate entities for temperature, humidity and battery status. And the whole thing runs under the Home Assistant OS supervisor - no need to babysit separate scripts anymore.

This work is based on @hijinx RTL433-to-MQTT Bridge add-on and the rtl_433_mqtt_hass.py script included in the rtl_433 source code. Big thanks to @hijinx for inspiration.

Add-on Repository: rtl_433 Home Assistant Add-ons

rtl_433 Add-on

GitHub URL

This add-on launches rtl_433 with your configuration file in a container under Home Assistant OS. You configure it to listen to whatever frequencies/devices you need and to publish the data into MQTT.

rtl_433 MQTT Auto Discovery Add-on

GitHub URL

This add-on helps Home Assistant ingest and interpret the rtl_433 data by periodically publishing MQTT discovery topics based on the device and event information coming from rtl_433.

The script looks for specific bits of data in rtl_433’s output to figure out what kind of sensor the data is coming from and to help Home Assistant handle it appropriately.

More specifically, this script looks for the following keys in rtl_433’s event data:

alarm
battery_ok
depth_cm
gust_speed_km_h
gust_speed_m_s
humidity
lux
moisture
noise
power_W
pressure_hPa
rain_in
rain_mm
rain_mm_h
rain_rate_in_h
rssi
snr
storm_dist
strike_count
strike_distance
tamper
temperature_1_C
temperature_2_C
temperature_C
temperature_F
uv
wind_avg_km_h
wind_avg_m_s
wind_avg_mi_h
wind_dir_deg
wind_max_m_s
wind_speed_km_h
wind_speed_m_s

In cases where none of the keys above appear, the script ignores the device that the event came from and doesn’t notify Home Assistant about it.

Hope someone finds this useful. Reply with questions, feature requests etc. Thanks!

28 Likes

Hi, tomorrow I will try this addon.
I already have a question: how did you solve the problem of dynamic sensor id, as it changes randomly after replacing the sensor batteries?
Thank you,
Piero

Not sure - I haven’t seen that problem yet. I have two Acurite 592TXs and a Kerui motion sensor, and they seem to keep their IDs between battery changes - just did a quick test. I guess it depends on the sensor’s hardware implementation.

If you have one sensor of a particular kind/model/brand, then I’d look at the scripts to try and hardcode an ID and ignore what sensor returns. If you have several, some more complicated scheme might be necessary, where you could hardcode unchanging IDs and find a way to assign the random IDs back to the stable ones during battery changes… Sounds complicated.

Sorry for the beginner question - I have not yet implemented any 433Mhz sensors into Home Assistant but have been looking at rtl_433, RFLINK & Sonoff RFBridge.

Will these add-ons allow me to use a Realtek RTL2832 USB dongle and have the 433Mhz sensors appear in Home Assistant via MQTT?

Yup, that’s the idea. I’m using a Nooelec Nesdr dongle connected to the Raspberry Pi running Home Assistant OS, works great with rtl_433. Check rtl_433’s “supported hardware” page here: https://triq.org/rtl_433/HARDWARE.html

@allmyhinges

Most of my sensors are very common, seen as generic “Nexus”:

I discussed about the changing ID problem with AhmadK, see here Best way to template definitions of MQTT 433MHz temp/humid sensors?

Ah I see, thanks for the pointer. Maybe it makes sense to fork rtl_433_mqtt_hass.py and let people add custom logic like what AhmadK was suggesting to override friendly_names with a mapping…

Anyone had trouble with wind speed not “auto discovering”?
i see its there on the mqtt server but it never shows up


i can see WS is there and it has a value mapped but nothing ever shows up in HASS
image

image

Hi, mind posting a screenshot with the contents of that “…-WD” topic? Then I’ll check HA source code to see what kind of support it has for windspeed and what keys it might be expecting.

Here is the WD topic

{"name": "LaCrosse-BreezePro-548561-WD", "unit_of_measurement": "\u00b0", "value_template": "{{ value|float }}", "state_topic": "rtl_433/9b13b3f4-rtl433/devices/LaCrosse-BreezePro/548561/wind_dir_deg", "unique_id": "LaCrosse-BreezePro-548561-WD", "device": {"identifiers": "LaCrosse-BreezePro-548561", "name": "LaCrosse-BreezePro-548561", "model": "LaCrosse-BreezePro", "manufacturer": "rtl_433"}}

Here is the WS topic as well

{"device_class": "weather", "name": "LaCrosse-BreezePro-548561-WS", "unit_of_measurement": "mi/h", "value_template": "{{ value|float }}", "state_topic": "rtl_433/9b13b3f4-rtl433/devices/LaCrosse-BreezePro/548561/wind_avg_mi_h", "unique_id": "LaCrosse-BreezePro-548561-WS", "device": {"identifiers": "LaCrosse-BreezePro-548561", "name": "LaCrosse-BreezePro-548561", "model": "LaCrosse-BreezePro", "manufacturer": "rtl_433"}}

I though it might be the device class but the temperature is working

{"device_class": "temperature", "name": "LaCrosse-BreezePro-548561-F", "unit_of_measurement": "\u00b0F", "value_template": "{{ value|float }}", "state_topic": "rtl_433/9b13b3f4-rtl433/devices/LaCrosse-BreezePro/548561/temperature_F", "unique_id": "LaCrosse-BreezePro-548561-F", "device": {"identifiers": "LaCrosse-BreezePro-548561", "name": "LaCrosse-BreezePro-548561", "model": "LaCrosse-BreezePro", "manufacturer": "rtl_433"}}

Browsing the logs i found this

Logger: homeassistant.util.logging
Source: util/logging.py:106
First occurred: 6:18:58 PM (1 occurrences)
Last logged: 6:18:58 PM

Exception in async_discover when dispatching 'mqtt_discovery_new_sensor_mqtt': ({'device_class': 'weather', 'name': 'LaCrosse-BreezePro-548561-WS', 'unit_of_measurement': 'mi/h', 'value_template': '{{ value|float }}', 'state_topic': 'rtl_433/9b13b3f4-rtl433/devices/LaCrosse-BreezePro/548561/wind_avg_mi_h', 'unique_id': 'LaCrosse-BreezePro-548561-WS', 'device': {'identifiers': 'LaCrosse-BreezePro-548561', 'name': 'LaCrosse-BreezePro-548561', 'model': 'LaCrosse-BreezePro', 'manufacturer': 'rtl_433'}, 'platform': 'mqtt'},) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/mqtt/mixins.py", line 152, in async_discover config = schema(discovery_payload) File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__ return self._compiled([], data) File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict return base_validate(path, iteritems(data), out) File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping raise er.MultipleInvalid(errors) voluptuous.error.MultipleInvalid: value must be one of ['battery', 'current', 'energy', 'humidity', 'illuminance', 'power', 'power_factor', 'pressure', 'signal_strength', 'temperature', 'timestamp', 'voltage'] for dictionary value @ data['device_class']

Hmm… this:

I’m looking at the source code for the auto-discovery script now.

Once again, thanks for letting me know about the issue.

Short story: I removed all references to the now-invalid “weather” device_class - please update the add-on.

Long story is described in a GitHub issue for those interested in the gory details.

Please update the add-on to version 0.1.6 and let me know whether that fixes the issue. Thanks!

1 Like

Hello,

thanks for this great addon. Thanks to him, I can measure the amount of water in the well.
I would like to ask what should I add to the configuration file so that the addon runs with all protocols?
If I enter rtl_433 -G 4 then the addon will not start properly.

output      mqtt://core-mosquitto:1883,user=homeassistant,pass=xxx
frequency   433.92M
rtl_433 -G 4

To use the “-G” command line option in the config file, specify this:

register_all true

You can find more info in the example config file in rtl_433’s repository on GitHub.

THANK YOU, this fixed my issue

Thank you for answer. Unfortunately, if I add to the configuration file register_all true, then the addon does not work.
If I delete this line, it will start correctly right away.
Can you please see where the error is?

Log:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
Starting rtl_433 -c /config/rtl_433/rtl_433.conf
rtl_433 version 20.11-66-gc2124fa6 branch master at 202102071317 inputs file rtl_tcp RTL-SDR
Use -h for usage help and see https://triq.org/ for documentation.
Publishing MQTT data to core-mosquitto port 1883
Publishing device info to MQTT topic "rtl_433/9b13b3f4-rtl433/devices[/type][/model][/subtype][/channel][/id]".
Publishing events info to MQTT topic "rtl_433/9b13b3f4-rtl433/events".
Publishing states info to MQTT topic "rtl_433/9b13b3f4-rtl433/states".
	Use -G for testing only. Enable with -G 4 if you really mean it.
[cmd] /run.sh exited 1
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.


Configuration file :

output      mqtt://core-mosquitto:1883,user=homeassistant,pass=XXX
frequency   433.92M
register_all true

1 Like

Looking at rtl_433’s source code, I’m not seeing a way to specify “-G 4” via a config file. You have a couple of options:

  1. Explicitly specify all protocols that you need, one per line in the config file, something like this:
protocol 1
protocol 2
protocol ...
...

This is tedious, but do you really need all 100+ protocols enabled? Full list can be found here.
2. Fork my addons repository on GitHub, pass “-G 4” on the command line to rtl_433 in run.sh, and install the add-on from your GitHub fork instead of mine.
3. Copy the add-on to your Home Assistant server’s addons file share (as described in the dev documentation), and change run.sh to pass “-G 4” to rtl_433.