Tasmota sonoff zigbee MQTT temperature and humidity sensor problem

Hi there,

I have a Sonoff SNZB-02 connected to Sonoff Zigbee Bridge ZBBridge flashed with latest Tasmota firmware.

I managed to connect the bridge to Home Assistant via MQTT broker. I can read values from the temperature/humidity sensor.

The problem is, that the MQTT message is sometimes missing Temperature or Humidity value.

e.q.

{
  "ZbReceived": {
    "tasmotatest": {
      "Device": "0x1F94",
      "Name": "tasmotatest",
      "Temperature": 23.78,
      "Endpoint": 1,
      "LinkQuality": 100
    }
  }
}

MQTT message without Temperature:

{
  "ZbReceived": {
    "tasmotatest": {
      "Device": "0x1F94",
      "Name": "tasmotatest",
      "BatteryPercentage": 59.5,
      "Endpoint": 1,
      "LinkQuality": 100
    }
  }
}

So when I get Temperature value to HA and later the device sends message just with the battery percentage (without Temperature) - the temperature value in HA is set to 0. How can I tell HA, that if the Temperature value is not present in the MQTT message, then the HA would not update the sensor?

Here is my HA configuration:

- platform: mqtt
    name: "Tasmota Temperature"
    state_topic: "aaa/tasmota1/SENSOR"
    value_template: "{{ value_json.ZbReceived.tasmotatest.Temperature }}"
    unit_of_measurement: "°C" 
    availability_topic: "aaa/tasmota1/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    device_class: temperature

Thank you for help/guidance.

This should work for you.

Thank you, very much appreciated

Max

Hi! Could you show how your configuration was with the VDRainer solution? I was unable to configure it here on my HA.

1 Like

Hello,

I’m spending my weekend on a fucking bug and I couldn’t find it… so I post my nightmare:
I would like to recover the humidity via a tasmota (MQTT,…).
1- I put a Zigbee sensor that sends humidity to Tasmota (it works!).
image

2 - Tasmota posts the temperature of the device (0XAE6D) on my MQTT broker. I can see it in the console and via MQTT.fx: (it works!)

3 - Then on Home Assistant, I write in my config.yaml:

and in my entity, the value is not:

Any ideas are very very welcomed!!!

François

I solved it… alone!
Here is the functionnal code:

mqtt:
  sensor:
    - name: "Humidité Cave"
      unique_id: "Cellar_hum"
      state_topic: "tele/Cave/SENSOR"
      value_template: >-
        {% if value_json['ZbReceived']['0xAE6D']['Humidity'] > 0 %}
          {{ value_json['ZbReceived']['0xAE6D']['Humidity'] }}
        {% else %}
          {{ states(entity_id) }}
        {% endif %} 
      availability_topic: "tele/Cave/LWT"
      payload_available: "Online"
      payload_not_available: "Offline"
      qos: 0
      device_class: "humidity"
      expire_after: 86400
      unit_of_measurement: '%'
      
    - name: "Température Cave"
      unique_id: "Cellar_tem"
      state_topic: "tele/Cave/SENSOR"
      value_template: >-
        {% if value_json['ZbReceived']['0xAE6D']['Temperature'] > 0 %}
          {{ value_json['ZbReceived']['0xAE6D']['Temperature'] }}
        {% else %}
          {{ states(entity_id) }}
        {% endif %} 
      availability_topic: "tele/Cave/LWT"
      payload_available: "Online"
      payload_not_available: "Offline"
      qos: 0
      device_class: "Temperature"
      expire_after: 86400
      unit_of_measurement: '°C'      

Please note that values are displayed ONLY if there are new values… No buffering!!!
Then if you want to test it, the best way is to publish a faked post on your MQTT broker with MQTT.fx: