MQTT JSON Sensor not working (RTL433 Filtering)

Hi,
I must say beforehead I am not an experienced programmer, so I might be missing something really obvious and basic. In short, my problem is I can’t get my desired sensor definitions running and always get “unknown” Status/Value even tough I varied my config lots of times. I would highly appreciate your help:

My goal:
use (selected!) 433 MHz-Device data for creating multiple temp/humidity-Sensors in Home Assistant.

the relevant environment within the network:

  • Raspberry Pi 2 with Raspbian Lite: publishes JSON to an MQTT topic called “rtl433”, which is being produced by the program “rtl433” using a DVB-T2-Stick.
  • Intel-NUC with Ubuntu: Here my MQTT Broker is running (Mosquitto)
  • Raspberry Pi 3 with Home Assistant (more detail: I didn’t install any operating system other than inserting the Homeassistant-SD-Card, so I am almost sure this means I run HassOS).
  • Desktop PC and Laptop Computer: From those I can verify that the MQTT JSON messages are actually being correctly issued.

MQTT Data Format:
Here is some example data which is being posted to the topic “rtl433”:

{"time" : "2020-09-09 16:49:55", "model" : "Nexus-T", "id" : 135, "channel" : 1, "battery_ok" : 1, "temperature_C" : 26.600}
{"time" : "2020-09-09 16:49:44", "model" : "inFactory-TH", "id" : 212, "channel" : 1, "battery_ok" : 1, "temperature_C" : 22.722, "humidity" : 60, "mic" : "CRC"}
{"time" : "2020-09-09 16:49:34", "model" : "Ambientweather-F007TH", "id" : 85, "channel" : 3, "battery_ok" : 1, "temperature_C" : 20.389, "humidity" : 59, "mic" : "CRC"}
{"time" : "2020-09-09 16:47:26", "model" : "inFactory-TH", "id" : 212, "channel" : 1, "battery_ok" : 1, "temperature_C" : 22.722, "humidity" : 60, "mic" : "CRC"}
{"time" : "2020-09-09 16:46:54", "model" : "Ambientweather-F007TH", "id" : 110, "channel" : 1, "battery_ok" : 1, "temperature_C" : 22.944, "humidity" : 64, "mic" : "CRC"}

So this datastream contains different sensors, which includes:

  • desired information (Temperature, humidity of certain devices which would most likely be best identified by their id)
  • unnecessary information (devices of my neighbours, datafields like “CRC” or similar)

So what I want to do is to use the “id” to identify my desired sensors and use temperature and humidity as value (or attribute?) for a homeassistant sensor.

Basic information what I have been researching so far:

  • I don’t want to use Node-Red to transform the data into several MQTT topics for each sensor as this would add an extra layer of complexity and the other solutions within HA which I found in the forum seemed actually pretty straight forward, altough it isn’t working yet.
  • I could solve it via automations, but I have the suspicion this wouldn’t work either.
  • There seems to be an issue with JSON values longer than 255 chars, but from what I have seen none of those JSON messages are longer than that.
  • Concerning the proper functionality of receiving MQTT information to the HA I don’t have rock hard proof, but other things like MQTT-Shelly-Plugs are working and also I can see the MQTT messages on my other computers.

My config:

As suggested in different threads (for example this one) I tried to get the sensor running like this:

  - platform: mqtt
    state_topic: "rtl433/"
    name: "keller"
    unit_of_measurement: "°C"
    value_template: >
     {% if value_json.id == 85 %}
      {{ value_json.temperature_C }}
     {% else %}
      "blatestflo1" ## basically just a test to see if I would at least get this string as an Output
     {% endif %}

I have changed little details of this multiple times but still I can’t get it to work as I am still getting no values for this sensor:

To be sure, here is some additional information about my HA system:

I think you just made a small mistake

  - platform: mqtt
    state_topic: "rtl433"
    name: "keller"
    unit_of_measurement: "°C"
    value_template: >
     {% if value_json.id == 85 %}
      {{ value_json.temperature_C }}
     {% else %}
      "blatestflo1" ## basically just a test to see if I would at least get this string as an Output
     {% endif %}

Your template seems correct :

if that is not working, try with

state_topic: "rtl433/#"
1 Like

just check that the topic name is correct:
mosquitto_sub -h broker_ip -p port_number -u username -P password -t ‘#’ -v

wow. I have tried soo many different approaches for many hours today but this has now actually made a difference and I can now see values within my sensor!

There is just one thing which I didn’t yet understand:

Most people within the forum have used this “else” part to use a code similar like this:
states(sensor.keller)
which seems to have something to do with the periods where the sensor is not sending data. Does anyone have an idea if I need this or what this actually does?

It is not. MQTT never publishes an endpoint ending in ‘/’

thank you! unfortunately I couldn’t do this command directly on the HA as I haven’t figured out a way to check this on the HA but I have confirmed it on other devices.

However, adding the " # " did the trick.

You don’t need it, but it makes sure you don’t get ‘unavailable’ or ‘unknown’ as temperature.

1 Like

Thank you very much for the explanation and your hint!