ESP32 DHT11 - sensor storing "0" Zero values when device is offline

Hello All

I have and ESP32 board where I have integrated Temperature / Humidity sensor DHT11. All works actually above expectations, there is just this one little problem which I cant get solved.
From time to time I have to disconnect the ESP32 from power , or I even loose electricity at all for short amount of time. During this time, the sensor values stored in Hassio are always “0” zeros. At the end is not such a big deal, but the graphs then looks strange. Its not so easy to read the graphs if it displays the range from 0 to 80, comparing to for example 65 to 80 , which would normally displayed as min and max values. See example below.

Anyone got an idea how to get rid of the zeros?
I know that in general configuration.yaml one could use availibilty: attribute for sensor, but how to use it in ESPHome i dont know.

Below you can find the configuration of my sensor within ESPhome

sensor:
  - platform: dht
    pin: 23
    temperature:
      name: "Spalna Teplota"
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
    humidity:
      name: "Spalna Vlhkost"
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
    model: AM2302
    update_interval: 10s

Thank you all for help

filters:
  - lambda: |-
      if (x >= 0) return x;
      else return {};

perhaps it must read x=0 in case your readings should also cover below 0 but then you would run into another problem because if temperature is idling around 0 you’ll loose lots of sensor readings. But it works ok if you’re sure that 0 is out of the expected range.

1 Like