Mqtt extract data on same topic

Hi Guys,

i have some strange things happening.

I have 3 sensor state publishes that looks like:

19:38:12.321 MQT: tele/zbbridge_buero/0C6B/SENSOR = {"ZbReceived":{"0x0C6B":{"Device":"0x0C6B","Name":"TempBuero","Temperature":28.9,"Endpoint":1,"LinkQuality":79}}}
19:38:12.850 MQT: tele/zbbridge_buero/0C6B/SENSOR = {"ZbReceived":{"0x0C6B":{"Device":"0x0C6B","Name":"TempBuero","Humidity":47.1,"Endpoint":1,"LinkQuality":92}}}
19:38:13.394 MQT: tele/zbbridge_buero/0C6B/SENSOR = {"ZbReceived":{"0x0C6B":{"Device":"0x0C6B","Name":"TempBuero","BatteryVoltage":2.5,"BatteryPercentage":100,"Endpoint":1,"LinkQuality":92}}}

I have this sensors installed:

- platform: mqtt
  name: "Working Temperature"
  state_topic: "tele/zbbridge_buero/0C6B/SENSOR"
  value_template: "{{ value_json.ZbReceived['0x0C6B'].Temperature }}"
  unit_of_measurement: "°C"
- platform: mqtt
  name: "Working Humidity"
  state_topic: "tele/zbbridge_buero/0C6B/SENSOR"
  value_template: "{{ value_json.ZbReceived['0x0C6B'].Humidity }}"
  unit_of_measurement: "%"
- platform: mqtt
  name: "Working BatteryPercentage"
  state_topic: "tele/zbbridge_buero/0C6B/SENSOR"
  unit_of_measurement: "%"
  value_template: "{{ value_json.ZbReceived['0x0C6B'].BatteryPercentage }}"

I used an example from MQTT Sensor - Home Assistant part “TEMPERATURE AND HUMIDITY SENSORS”. But when all 3 sensor-datas will be sent to HASSIO only one attribute will be shown.

You can see all 3 attributes updating but when the next attribute updates, the previous attribute gets cleared and disapears.

How can i solve this issue?

as you are read form the same topic

tele/zbbridge_buero/0C6B/SENSOR

and as the other bits is not all bits are in the data all the time the other will go BLANK

you could make a rule to just send each data point to its own topic

im wing this bit been a while i wrote a rule but here goes

rule1 on 0x0C6B#Temperature do publish 0x0C6B/Temperature value endon

that off top of head mite need a bit of reading

then change the MQTT sensor

- platform: mqtt
  name: "Working Temperature"
  state_topic: "0x0C6B/Temperature"

I have different files for temperature(with humidity) sensor, wind, rain.
for the temperature sensor, my yaml is:

- platform: mqtt
  state_topic: "home/rtl_433"
  name: "Outdoor Humidity"
  unit_of_measurement: '%'
  value_template: >
    {% if value_json is defined and value_json.model == 'THGR810' %}
      {{ value_json.humidity }}
    {% else %}
      {{ states('sensor.outdoor_humidity') }}
    {% endif %}
    
- platform: mqtt
  state_topic: "home/rtl_433"
  name: "Outdoor Temperature"
  unit_of_measurement: '°C'
  value_template: >
    {% if value_json is defined and value_json.model == 'THGR810' %}
      {{ value_json.temperature_C }}
    {% else %}
      {{ states('sensor.outdoor_temperature') }}
    {% endif %}

the wind sensor:

- platform: mqtt
#wind gust
  state_topic: "home/rtl_433"
  name: "Wind Gust"
  unit_of_measurement: 'm/s'
  value_template: >
    {% if value_json is defined and value_json.model == 'WGR800' %}
      {{ value_json.gust }}
    {% else %}
      {{ states('sensor.wind_gust') }}
    {% endif %}    
    
- platform: mqtt
  state_topic: 'home/rtl_433'
  name: 'Wind Direction'
  unit_of_measurement: ''
  value_template: >-
    {% if value_json is defined and value_json.model == 'WGR800' %}
      {% set wd = value_json.direction | int %}
      {% if wd <= 11 or wd > 348 %}North
      {% elif wd >11 and wd <=34 %}North North East
      {% elif wd >34 and wd <=56 %}North East
      {% elif wd >56 and wd <=79 %}East North East
      {% elif wd >79 and wd <=101 %}East
      {% elif wd >101 and wd <=124 %}East South East
      {% elif wd >124 and wd <=146 %}South East
      {% elif wd >146 and wd <=169 %}South South East
      {% elif wd >169 and wd <=191 %}South
      {% elif wd >191 and wd <=214 %}South South West
      {% elif wd >214 and wd <=236 %}South West
      {% elif wd >236 and wd <=259 %}West South West
      {% elif wd >259 and wd <=281 %}West
      {% elif wd >281 and wd <=304 %}West North West
      {% elif wd >304 and wd <=326 %}West North West
      {% elif wd >326 and wd <=348 %}North North West
      {% endif %}
    {% else %}       
      {{ states('sensor.wind_direction') }}
    {% endif %}
1 Like

Hi oldfart,

i did it the same way as you did. But now it gets strange.

If i do an mqtt.reload event all data gets “unknown”. I need to press the update-button on my zigbee-devices so i get new status updates. After that, all values are known.

But this is not the correct behavior. The values should never get “unknown”.

How to fix this issue?

“unknown” just means there is no data.
you need to watch the messages on your mqtt server to see what is going on

No, i mean there is data. But as i run mqtt.reload all the data becomes unknown.

This is not correct.

Something must be happening on the MQTT bus to cause this. You need to watch the messages on your MQTT server to see what is going on.

This topic may help: seems like a similar issue: