Sonoff Zigbee SNZB-02 mqtt

Hello.

I’m having trouble with parsing json from this sensor, it send sometimes only temperature:

21:56:59 MQT: tele/tasmota_D9B52C/3D3B/SENSOR = {"0x3D3B":{"Device":"0x3D3B","Name":"Room","Temperature":25.86,"Endpoint":1,"LinkQuality":168}}

sometimes humidity:

21:57:39 MQT: tele/tasmota_D9B52C/3D3B/SENSOR = {"0x3D3B":{"Device":"0x3D3B","Name":"Room","Humidity":58.74,"Endpoint":1,"LinkQuality":168}}

but sometimes both:

21:54:49 MQT: tele/tasmota_D9B52C/3D3B/SENSOR = {"0x3D3B":{"Device":"0x3D3B","Name":"Room","Temperature":26.36,"Humidity":78.67,"Endpoint":1,"LinkQuality":131}}

The problem is when it send only one attribute, es Humidity or Temperature, when they are send both, the all is ok. But when it sends only one attribute, the second one is overwritten in the lovelace and shows nothing.

Here is my config:

sensor:
- platform: mqtt
    name: "Temperature"
    unit_of_measurement: '°C'
    unique_id: "m_temperature" 
    device_class: temperature
    qos: 1
    state_topic: "tele/tasmota_D9B52C/3D3B/SENSOR"
    value_template: > 
     {% if "Temperature" in value_json["0x3D3B"] %} {{ value_json["0x3D3B"]["Temperature"] }}{% endif %}

- platform: mqtt
    name: "Humidity"
    unit_of_measurement: '%'
    unique_id: "m_humidity" 
    device_class: humidity
    qos: 1
    state_topic: "tele/tasmota_D9B52C/3D3B/SENSOR"
    value_template: >
     {% if "Humidity" in value_json["0x3D3B"] %} {{ value_json["0x3D3B"]["Humidity"] }}{% endif %}

I’m doing something wrong?

Regards.

Try

sensor:
- platform: mqtt
    name: "Temperature"
    unit_of_measurement: '°C'
    unique_id: "m_temperature" 
    device_class: temperature
    qos: 1
    state_topic: "tele/tasmota_D9B52C/3D3B/SENSOR"
    value_template: > 
     {% if "Temperature" in value_json["0x3D3B"] %} 
        {{ value_json["0x3D3B"]["Temperature"] }}
     {% else %}
       {{states('sensor.temperature') }}
    {% endif %}

- platform: mqtt
    name: "Humidity"
    unit_of_measurement: '%'
    unique_id: "m_humidity" 
    device_class: humidity
    qos: 1
    state_topic: "tele/tasmota_D9B52C/3D3B/SENSOR"
    value_template: >
     {% if "Humidity" in value_json["0x3D3B"] %} 
          {{ value_json["0x3D3B"]["Humidity"] }}
     {% else %}
       {{states('sensor.humidity') }}
    {% endif %}

Thanks, working.

But the logic is very strange for me.