Rtl_433 mqtt gives error

Hi guys,

I have a RPI that runs a script that opens RTL_433 and outputs to MQTT:

#!/bin/bash

set -x

export LANG=C
PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"

/usr/local/bin/rtl_433 -F json |  while read line
do
        [ -w /tmp/rtl_433.log ] && echo $line >> rtl_433.log
        echo $line  | /usr/bin/mosquitto_pub -h 192.168.10.208 -i RTL_433 -l -t "RTL_433/Raw" -V mqttv311
done

This is my HA configuration:

mqtt:
  embedded:
    listeners:
        default:
            max-connections: 50000
            type: tcp
            bind: 0.0.0.0:1883
    timeout-disconnect-delay: 2
    auth:
        plugins: ['auth.anonymous']
        allow-anonymous: true
  broker: 0.0.0.0
  port: 1883

When I run the script I get the following error in HA:
BrokerProtocolHandler Unhandled exception in reader coro: IncompleteReadError('0 bytes read on a total of 1 expected bytes',)

I can’t really see what I’m doing wrong here, any suggestions?

Even when I try using the example from the docs:
mosquitto_pub -h 192.168.10.208 -V mqttv311 -t "hello" -m world

It’s throwing the same error.

Your HA configuration for mqtt seems unnecessarily complex. Try simplifying it to just

mqtt:

and then use the username homeassistant and the password for your web ui in the parameters to mosquitto_pub.

Incidentally, mosquitto_pub can take messages from stdin, so you could do something like

/usr/local/bin/rtl_433 -F json | mosquitto_pub -l --username homeassistant --pw <your api passwd> -t "RTL_433/Raw" -V mqttv311

mosquitto_pub isn’t available if you use the internal one. The config was a bit more complex because I needed to allow remote connections.

But as many other I have moved away from the embedded one and now using moquitto.

Both the brokers use the same MQTT protocol, so it is perfectly possible to use mosquitto_pub with the embedded broker.

If you are using mosquitto, the configuration for that is done in the mosquitto configuration files, not in HA configuration files. To use mosquitto, the HA configuration should be

mqtt:
  broker: <ip address of your broker machine>

If you are running mosquitto on the same machine as HA, you can refer to localhost rather than specifying an address.

Unforunately not, you have to specify it to fall back on the mqttv311 protocol, otherwise you get “invalid protocol” errors.

Sorry, I forgot you have to use the parameters -V mqttv311 to get mosquitto_pub to work with the HA embedded broker, but it does work fine.

However, this is not relevant to your problem, because you are using mosquitto. Have you tried removing all the unnecessary embedded configuration to see if that helps?

No I switched to moquitto, the original problem is embedded. I gave up on it because I read most people switched to mosquitto due to issues like this.