palmarci's blog

a random blog mostly for myself, so i can remember stuff

Calibrating DHT sensors with ESP-01 in ESPHome


After receiving my DHT modules for the ESP-01S from Aliexpress, I was surprised by how inaccurate were they.

alt text

esphome:
  name: "weatherstation"
  name_add_mac_suffix: true
  platform: esp8266
  board: esp01_1m

wifi:
  ssid: "your_ssid"
  password: "your_pass"
  ap:
    ssid: "weatherstation_fallback"
    password: "fallback_password"

captive_portal:

# Enable logging
logger:

# Enable OTA updates
ota:
  - platform: esphome

# Web server to view and configure values
web_server:
  port: 80

# DHT11 Sensor Configuration
sensor:
  - platform: dht
    pin: GPIO2  # Adjust GPIO pin as needed
    model: DHT22
    temperature:
      name: "Temperature"
      accuracy_decimals: 1
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
            send_first_at: 15
        - lambda: return x - 7;
    humidity:
      name: "Humidity"
      accuracy_decimals: 1
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
            send_first_at: 15
        - lambda: return x + 29;
    update_interval: 4s

After creating the yaml config for it, it was very easy to compile the firmware using the ESPHome framework:

esphome compile weatherstation.yaml

Also, don't forget to buy the corresponding programmer too for the initial programmming.

Once ESPHome was flashed with the OTA functionality enabled, you can flash it over the network from the comfort of your room, without having to go to the basement or whatever.

esphome upload weatherstation.yaml --device weatherstation1.home

Next, I put my wallclock next to the ESP and started gathering data into an Excel sheet. alt text

alt text

The calibration can be done in the lambda: return lines in the config via a basic offset; this was enough for me to get trustable readings.