james-fry / hassio-addons

Repository for hass.io add ons
99 stars 96 forks source link

Malformed json sent to the mqtt broker ? #30

Closed yvesle closed 4 years ago

yvesle commented 4 years ago

Hi and thank you for the great work !

Using hass.io 0.103.3 installed on Beaglebone black I installed your add-on and used the official mosquitto broket add-on v5.1

When I run the add-on, nothing special shows in the log but the broker received one set of data only, no updates. The broker gives a message about "socket error on client xxxx disconnecting" and nothing else.

I am using a current cost transmitter and when using rtl_433 alone and the json format looks like this : {"time" : "2019-12-24 10:46:53", "model" : "CurrentCost-TX", "id" : 2972, "power0" : 0, "power1" : 0, "power2" : 0} However when I increased the log level in your script I got this ouput : echo '{"time"' : '"2019-12-24' '11:27:49",' '"model"' : '"CurrentCost-TX",' '"id"' : 2972, '"power0"' : 0, '"power1"' : 0, '"power2"' : '0}' Notice there are single quotes missing around double quotes at the beginning and the end. I guess this messed up with the broker. I used the workaround mentionned in another issue and it works now althought I lost the autodiscovery part.

Hope that helps !

yvesle commented 4 years ago

I continued to dig and I think I found a good solution. It turns out the rtl_433 program can now have its output sent directly to a MQTT broker. So from line 183 down of the rtl2mqtt.sh script here is my replacement solution :

/usr/local/bin/rtl_433 -M newmodel -R $PROTOCOL -f $FREQUENCY -g $GAIN -p $OFFSET -F "mqtt://$MQTT_HOST:1883,user=$MQTT_USER,pass=$MQTT_PASS,retain=0,events=rtl_433[/model][/id]"

and....that's it ! :)

The topic for my current cost meter becomes "rtl_433/CurrentCost-TX/2972" and is available in hass.io. No stalls yet and works like a charm. I used "-M newmodel" because the models names are more consistent and make use of dashes "-" instead of space in their name.

I did not try to make autodiscovery work as it seemed too complicated to setup for my need. My only last "hack" was that I wanted to monitor two protocols and I had to hardcode the second one (add -R XX as needed).

Hope that helps others !

james-fry commented 4 years ago

Thanks for the inputs @yvesle It would be nice if I had time to maintain this properly! Great that you got it working, and I think that using rtl433 built in mqtt client is the right approach. If you are able to submit a pr I’d be happy to merge it. Cheers!