merbanan / rtl_433

Program to decode radio transmissions from devices on the ISM bands (and other frequencies)
GNU General Public License v2.0
6.1k stars 1.32k forks source link

Add Model and ID to MQTT topic #997

Closed DeadEnded closed 5 years ago

DeadEnded commented 5 years ago

Hello whoever is reading this. I am very new to github and just started toying the RTL_433. This may be the incorrect way to do this (I am thinking it might be a pull request) - but I know you prefer to keep this as simple as possible, so this might not be something you want to put into the repository.

BUT - I was very excited to figure this out (since I am so inexperienced). I have multiple identical devices that I want to use RTL_433 to send MQTT messages for. The problem is I want to be able to separate them with topics, but RTL_433 by default does not do this.

SO - my google-fu led me to a working solution. Here are the simple steps I used to do this:

1) Add jq to the apt install list 2) Add the following modification to rtl2mqtt.sh

After the first echo $line add:

DEVICE="$(echo $line | jq --raw-output '.model' | tr ' ' '_')" ID="$(echo $line | jq --raw-output '.id')"

Change the mosquitto_pub topic to:

"RTL_433/Raw/$DEVICE/$ID"

Well, that's it... This might be common knowledge for those here who are experienced, but I was happy to solve my problem, and wanted to share :-)

Cheers! DeadEnd

zuckschwerdt commented 5 years ago

That's a good post-processing hint. We currently rely on either that shell script to bridge to MQTT or something like https://github.com/zuckschwerdt/rtl_433_relay/blob/master/rtl_433_mqtt_relay.py – which is easier to customize and has better performance.

We also have working code for MQTT in rtl_433 to support that directly. It's just not clear how topics and payloads should be formed. E.g. identify the device by model/id or model/id/channel or model/(channel otherwise id)? Put JSON at that topic or split some/all values to sub-topic, e.g. model/channel/temperature seems nice. And what about units? Some one has to investigate all this, and make a proposal

mikejac commented 5 years ago

Maybe use the Homie convention: An MQTT Convention for IoT/M2M ??

/michael

bademux commented 5 years ago

Sorry for resurecting closed topic. @zuckschwerdt OpenHab (internaly runs MQTT broker) supports Homie 3.x specification and HomeAssistant MQTT Components specification so maybe one of those?

zuckschwerdt commented 5 years ago

Thanks for the suggestions and documentation links. Both formats seem very verbose if we need to support our very generic sensor types. But I guess we can add both as options. (e.g. something like -F mqtt:192.168.1.2:1883,homie=1,hamcs=1) For a first test and to develop the necessary translation we should use https://github.com/zuckschwerdt/rtl_433_relay/blob/master/rtl_433_mqtt_relay.py

bademux commented 5 years ago

Sounds great! Just small suggestion:

Anyway thanks for the project!