How To Keep RTL_433 Alive For Your Home Automation Using Supervisor

I run RTL_433 to push data from several sensors and a motion detector to an MQTT server for home automation.  For some reason as of late it is just not that stable. Could even be a hardware failure with the dongle….I dunno.  I generally just run the program command inside a terminal on the raspberry pi it is installed on and just walk away.  When it crashes I have to log back in the Pi and re-run the command.   Un-cool.

The command I use specifically is this:

rtl_433 -F json -M utc | mosquitto_pub -t home/rtl_433 -l

Again, that pushes data found on 433.920 MHz devices to publish a topic on my MQTT server called “home/rtl_433”.

Then I tried to do a cron job to start it but it still crashes.   The great thing about linux is that you can write scripts to monitor jobs and restart them but it’s always so clunky.

Then I found out about a program called Supervisor.  Install it on the Pi by

sudo apt-get install supervisor

I know this is a version or two behind but the way to install it through python “pip install supervisor”, I never could figure out how to make the conf file to control the darn thing.  None of the tutorial stuff worked.  So I have to sacrifice being a version or so behind by using the Pi repositories.

Anyway here’s how to quickly configure supervisor to monitor your instance of RTL_433 so it stays up and operational.

First create a script file for your command:

sudo nano rtl433.sh

Paste in the following:

#!/bin/bash
rtl_433 -F json -M utc | mosquitto_pub -t home/rtl_433 -l

Hit Ctl plus the X key, answer Y and hit enter to save. Now make it executable:

sudo chmod +x rtl433.sh

Now let’s do the supervisor conf file.

sudo nano /etc/supervisor/supervisord.conf

Paste in the following at the bottom of the file making sure your command path is correct.  I made my script file in the /home/pi directory.  Autostart starts at boot, autorestart restarts it if it crashes or fails :

[program:rtl_433]
command=/home/pi/rtl433.sh
autostart=true
autorestart=true
stderr_logfile=/var/log/long.err.log
stdout_logfile=/var/log/long.out.log

Screenshot

Hit CTL plus the X key, answer Y and hit enter to save the file.

Now restart the Pi or start rtl_433 then pull the RTL-SDR dongle out of the pi and plug it back in. Then check to see if the rtl_433 process is running.

top

Working.  You are the master of both time and space.

13 thoughts on “How To Keep RTL_433 Alive For Your Home Automation Using Supervisor

  1. anonymous

    Why not just run it as daemon? Just create file /etc/systemd/system/rtl_433.servce
    service rtl_433 start
    to start is when the system starts:
    systemctl enable rtl_433
    There’s “one” problem in my case. It crashes when working as a service while working perfectly fine as standalone program. So I got opposite scenario to one described here.

    Sample content of rtl_433.servce that restarts service when it crashes.
    [Unit]
    Description=433MHz receiver on DVB stick
    After=network.target

    [Service]
    Type=simple
    User=root
    ExecStart=/usr/local/bin/rtl_433 -F “mqtt://localhost:1883,devices=rtl_433[/model][/id]”

    RestartSec=0
    Restart=always
    RemainAfterExit=no

    [Install]
    WantedBy=multi-user.target

    Reply
    1. John Hagensieker Post author

      Yep, that’s the great thing about Linux……always multiple ways to do things! Thanks.

      Reply
  2. Mike

    HI

    I have tried exactly what you have done but unfortunately it will not work. If you sh the file containing

    #!/bin/bash
    rtl_433 -F json -M utc | mosquitto_pub -t sensors/rtl_433 -d -l -h 192.168.1.26

    all works as expected. If try and run is from supervisor it falls over with an exit status 1; not expected. If you look in the log files you get (truncated):

    rtl_433 version 20.02-61-gf82c025 branch master at 202005272108 inputs file rtl_tcp RTL-SDR
    Use -h for usage help and see https://triq.org/ for documentation.
    Trying conf file at “rtl_433.conf”…
    Trying conf file at “(null)/.config/rtl_433/rtl_433.conf”…
    Trying conf file at “/usr/local/etc/rtl_433/rtl_433.conf”…
    Trying conf file at “/etc/rtl_433/rtl_433.conf”…
    Invalid output format -F
    Generic RF data receiver and decoder for ISM band devices using RTL-SDR and SoapySDR.

    So it would appear that when .sh file is called by supervisor it does not recognize what follows after rtl_433

    Any ideas?

    Mike

    Reply
  3. douglas weiss

    Had the same problem. the entry in the .conf file is not -F ……. you have to replace the -F with the correct name of the option….so your entry would be:

    output json -M utc | mosquitto_pub -t sensors/rtl_433 -d -l -h 192.168.1.26

    Reply
  4. Andy

    It’s worth pointing out that rtl_433 supports publishing output directly to an MQTT service, so you do not need to separately pipe the output through mosquitto_pub.

    This means that:
    rtl_433 -F json -M utc | mosquitto_pub -t sensors/rtl_433 -d -l -h 192.168.1.26

    can be replaced with:
    rtl_433 -M utc -F “mqtt://192.168.1.26,devices=sensors/rtl_433” -t sensors/rtl_433

    Better still, you can include username/password details for better security, and the ‘devices’ parameter can be improved with “devices=/sensors/rtl_433/[/model][/id][/channel]” to make it easier to separate multiple radio sources.

    Even better still – put it all in a config file! 🙂

    — Begin Example Config —
    # RTL_433 Config File

    # Specify just the protocols I want to monitor:
    protocol 12 # Oregon Scientific Weather Sensor

    # Output Options:
    output mqtt://localhost:1883,user=MQTTUSER,pass=SOMESECRET,events=rtl_433[/model][/id][/channel]
    convert si
    report_meta time:unix
    — End Example Config —

    Reply
  5. Clay Jackson

    This file, in /etc/systemd/system/rtl_433.service works for me

    [Unit]
    Description=433MHz receiver on DVB stick
    After=network.target

    [Service]
    Type=simple
    User=root
    ExecStart=/usr/local/bin/rtl_433 -F mqtt:skyweather:1883

    RestartSec=0
    Restart=always
    RemainAfterExit=no

    [Install]
    WantedBy=multi-user.target

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *