ESPHome, Nodemcu32 and DHT

Hya,

i have the nodemcu-32s with esphome. a DHT sensor on gpio13.

# temparature and humidity
  - platform: dht
    pin: GPIO13
    temperature:
      name: "DHT Temperature"
      id: dht_temperature
    humidity:
      name: " DHT Humidity"
      id: dht_humidity 
    update_interval: 15s 

no errors, but no output. shows NA.

By measuring the tensions, nodemcu by USB, 5V present, 3V3 present and by gpio13 (connected to DHT) 3V9.

Is it normal? And why does it shows NA?

Thx for any advise.

Do you need to add a 4K7 to 10K Ohm resistor?

Also not using the default auto device model can help:

# temparature and humidity
  - platform: dht
    model: DHT22  # <---- add the correct model
    pin: GPIO13
    temperature:
      name: "DHT Temperature"
      id: dht_temperature
    humidity:
      name: " DHT Humidity"
      id: dht_humidity 
    update_interval: 15s 

You don’t mention which model DHT you are using. The valid options for model are listed here: DHT Temperature+Humidity Sensor — ESPHome

Thx for the answer.

Yes, i have a 10K pullup between gpio13 (pin2 dht) and 3V3 (pin 1 nodemcu).

Voltage by gpio13 is 3V9… normal?

And DHT model AM2302.

DHT22 devices are often marked with AM2302. Try specifying DHT22 as the model.

How long are the cables to the DHT device?

Yes the voltage on GPIO13 is normal. It is being pulled up by the resistor. If you had a meter that reacted fast enough (or an oscilloscope) you would see this pulled to ground as data was transferred.

cable lenght: none. soldered to protoboard, next to the nodemcu.

I fixed the code to:

  - platform: dht
    model: AM2302
    pin: GPIO13
    temperature:
      name: "DHT Temperature"
      id: dht_temperature
    humidity:
      name: " DHT Humidity"
      id: dht_humidity 
    update_interval: 15s 

I get:

[17:05:16][W][dht:169]: Requesting data from DHT failed!
[17:05:16][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[17:05:26][C][dht:017]: DHT:
[17:05:26][C][dht:018]:   Pin: GPIO13
[17:05:26][C][dht:024]:   Model: DHT22 (or equivalent)
[17:05:26][C][dht:027]:   Update Interval: 15.0s
[17:05:26][C][dht:029]:   Temperature 'DHT Temperature'
[17:05:26][C][dht:029]:     Device Class: 'temperature'
[17:05:26][C][dht:029]:     State Class: 'measurement'
[17:05:26][C][dht:029]:     Unit of Measurement: '°C'
[17:05:26][C][dht:029]:     Accuracy Decimals: 1
[17:05:26][C][dht:030]:   Humidity ' DHT Humidity'
[17:05:26][C][dht:030]:     Device Class: 'humidity'
[17:05:26][C][dht:030]:     State Class: 'measurement'
[17:05:26][C][dht:030]:     Unit of Measurement: '%'
[17:05:26][C][dht:030]:     Accuracy Decimals: 0

fixed to model: DHT22,

output:

[17:14:27][W][dht:169]: Requesting data from DHT failed!
[17:14:27][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).

cable lenght: none. soldered to protoboard, next to the nodemcu.

Double check your wiring.

already did. it’s all ok. no shorts. pin 1 from dht to 3V3, pin 2 to gpio13, pin 4 to gnd and 10K resistor between pin 2 and pin 1 (pullup). :frowning:

Pin numbering left to right looking at the front of the device (with the vent holes)?

If so, then you may have a dead sensor. Where did you buy it?

yes, sir.

i had it on my desk. how do i test if it’s alive or dead?

You pretty much just did.

tried another DHT22. same error.

replaced by a ds18b20, replacing the 10K by a 4.7K, and… nothing…

is the GPIO13 useable by ESPHome?

I’m using this board.

Yeah I did check that earlier, it is fine. See: ESP32 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials

[19:55:19][C][dallas.sensor:075]: DallasComponent:
[19:55:19][C][dallas.sensor:076]:   Pin: GPIO13
[19:55:19][C][dallas.sensor:077]:   Update Interval: 60.0s
[19:55:19][W][dallas.sensor:080]:   Found no sensors!

this is what i get.

What board definition are you using?

Try another GPIO, and try configuring a GPIO input to GPIO13 to test it with 3.3v and gnd.

connected to gpio27.

dallas:
  pin:
    number: 27
    inverted: true
    mode:
      input: true
      output: true
[20:24:31][C][dallas.sensor:075]: DallasComponent:
[20:24:31][C][dallas.sensor:076]:   Pin: GPIO27
[20:24:31][C][dallas.sensor:077]:   Update Interval: 60.0s
[20:24:31][W][dallas.sensor:080]:   Found no sensors!

i just don’t understand.

my entire yaml. maybe i’m doing something terrible wrong. All the i2c devices are working. I’m just not being able to make a sensor work.


substitutions:
  esphome_name: weather-station
  friendly_name: "Weather Station"
  esphome_comment: Weather Station
  esphome_project_name: PJW.Weather_Station_ESP32
  software_version: 2023 12 29 V01
  esphome_project_version: Weather Station ESP32, $software_version
  devicename: weather_station
  upper_devicename: "Weather Station"
  log_level: debug # Enable levels logging https://esphome.io/components/logger.html
  # none, error, warn, info, debug (default), verbose, very_verbose

esphome:
  name: $esphome_name
  platform: ESP32
  board: nodemcu-32s
  project:
    name: $esphome_project_name
    version: $esphome_project_version
#  on_boot:
#    priority: -10
#    then:
#      - script.execute: flashing

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

# Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${name} Fallback"
    password: !secret fallback_hotspot_password

captive_portal:

ota:
  password: !secret esphome_ota_password

api:
  encryption:
    key: !secret esphome_api_encrypt_key
  reboot_timeout: 0s
  
web_server:
  port: 80  

sun:
  latitude: !secret latitude
  longitude: !secret longitude

time:
  - platform: sntp
    timezone: UTC-3

logger:
  level: ${log_level}
  logs:
    text_sensor: WARN

i2c:
  frequency: 100kHz
  sda: GPIO26
  scl: GPIO25


ads1115:
  - address: 0x48

dallas:
  pin:
    number: 27
    inverted: true
    mode:
      input: true
      output: true

binary_sensor:
  - platform: gpio
    pin:
      number: 13
      mode:
        input: true
        pullup: true
    name: ds18b20  

sensor:  

# analog to digital 4 channels
  - platform: ads1115
    name: "${friendly_name} ADS1115-0"
    multiplexer: 'A0_GND'
    id: ads1115_A0
    gain: 6.144
  - platform: ads1115
    name: "${friendly_name} ADS1115-1"
    multiplexer: 'A1_GND'
    id: ads1115_A1
    gain: 6.144
  - platform: ads1115
    name: "${friendly_name} ADS1115-2"
    multiplexer: 'A2_GND'
    id: ads1115_A2
    gain: 6.144
  - platform: ads1115
    name: "${friendly_name} ADS1115-3"
    multiplexer: 'A3_GND'
    id: ads1115_A3
    gain: 6.144    

# anemometer - wind speed detector - in VCC 10 to 14V, out 0 to 5V * 6 = meters / second , meters / second * 3.6 = km/h
  - platform: ina226
    address: 0x40
    shunt_resistance: 0.1 ohm
    current:
      name: "${friendly_name} wind speed current"
    power:
      name: "${friendly_name} wind speed power"
    bus_voltage:
      name: "${friendly_name} wind speed voltage"
      id: wind_speed_voltage
      filters:
      - calibrate_linear:
         datapoints:
          - 0.0 -> 0.0
          - 5.0 -> 30.0
    shunt_voltage:
      name: "${friendly_name} wind speed shunt voltage"
    max_current: 3.2A
    update_interval: 5s

  - platform: copy
    name: '${friendly_name} wind speed (km/h)'
    id: wind_speed_kmh
    source_id: wind_speed_voltage
    unit_of_measurement: 'km/h'
    icon: 'mdi:weather-windy'
    filters:
      - multiply: 3.6

  - platform: copy
    name: '${friendly_name} wind speed average'
    icon: 'mdi:weather-windy'
    id: wind_speed_avg
    source_id: wind_speed_voltage
    unit_of_measurement: 'm/s'
    filters:
      - throttle_average: 5s

  - platform: copy
    name: '${friendly_name} wind speed average (km/h)'
    icon: 'mdi:weather-windy'
    id: wind_speed_kmh_avg
    source_id: wind_speed_voltage
    unit_of_measurement: 'km/h'
    filters:
      - multiply: 3.6
    on_value:
      lambda: |-
        if (x < 1) {
          id(wind_scale_code).publish_state("0");
          id(wind_scale).publish_state("Calm");
        } else if (x >= 1 && x < 6) {
          id(wind_scale_code).publish_state("1");
          id(wind_scale).publish_state("Light Air");
        } else if (x >= 6 && x < 12) {
          id(wind_scale_code).publish_state("2");
          id(wind_scale).publish_state("Light Breeze");
        } else if (x >= 12 && x < 20) {
          id(wind_scale_code).publish_state("3");
          id(wind_scale).publish_state("Gentle Breeze");
        } else if (x >= 20 && x < 29) {
          id(wind_scale_code).publish_state("4");
          id(wind_scale).publish_state("Moderate Breeze");
        } else if (x >= 29 && x < 39) {
          id(wind_scale_code).publish_state("5");
          id(wind_scale).publish_state("Fresh Breeze");
        } else if (x >= 39 && x < 50) {
          id(wind_scale_code).publish_state("6");
          id(wind_scale).publish_state("Strong Breeze");
        } else if (x >= 50 && x < 62) {
          id(wind_scale_code).publish_state("7");
          id(wind_scale).publish_state("Near Gale");
        } else if (x >= 62 && x < 75) {
          id(wind_scale_code).publish_state("8");
          id(wind_scale).publish_state("Gale");
        } else if (x >= 75 && x < 89) {
          id(wind_scale_code).publish_state("9");
          id(wind_scale).publish_state("Severe Gale");
        } else if (x >= 89 && x < 103) {
          id(wind_scale_code).publish_state("10");
          id(wind_scale).publish_state("Storm");
        } else if (x >= 103 && x < 118) {
          id(wind_scale_code).publish_state("11");
          id(wind_scale).publish_state("Violent Storm");
        } else if (x >= 118) {
          id(wind_scale_code).publish_state("12");
          id(wind_scale).publish_state("Hurricane Force");
        } else {
          ESP_LOGD("main", "It shouldn't happen (wind_speed_kmh_avg: %f)", x);
        }

# wind direction indicator
  - platform: ina226
    address: 0x41
    shunt_resistance: 0.1 ohm
    current:
      name: "${friendly_name} wind direction current"
    power:
      name: "${friendly_name} wind direction power"
    bus_voltage:
      name: "${friendly_name} wind direction voltage"
      id: wind_direction_voltage
    shunt_voltage:
      name: "${friendly_name} wind direction shunt voltage"
    max_current: 3.2A
    update_interval: 5s

# wind direction sensor voltage decoding
  - platform: copy
    name: '${friendly_name} wind direction heading'
    id: wind_direction_heading
    source_id: wind_direction_voltage
    on_value_range:
      - below: 0.70
        then:
           - text_sensor.template.publish:
              id: wind_dir_card
              state: "N"
           - sensor.template.publish:
              id: wind_heading
              state: 0.0
      - above: 0.70
        below: 1.42
        then:
          - text_sensor.template.publish:
              id: wind_dir_card
              state: "NE"
          - sensor.template.publish:
              id: wind_heading
              state: 45.0
      - above: 1.42
        below: 2.14
        then:
          - text_sensor.template.publish:
              id: wind_dir_card
              state: "E"
          - sensor.template.publish:
              id: wind_heading
              state: 90.0
      - above: 2.14
        below: 2.84
        then:
          - text_sensor.template.publish:
              id: wind_dir_card
              state: "SE"
          - sensor.template.publish:
              id: wind_heading
              state: 135.0
      - above: 2.84
        below: 3.56
        then:
          - text_sensor.template.publish:
              id: wind_dir_card
              state: "S"
          - sensor.template.publish:
              id: wind_heading
              state: 180.0
      - above: 3.56
        below: 4.27
        then:
          - text_sensor.template.publish:
              id: wind_dir_card
              state: "SW"
          - sensor.template.publish:
              id: wind_heading
              state: 225.0
      - above: 4.27
        below: 4.99
        then:
          - text_sensor.template.publish:
              id: wind_dir_card
              state: "W"
          - sensor.template.publish:
              id: wind_heading
              state: 270.0
      - above: 4.99
        then:
          - text_sensor.template.publish:
              id: wind_dir_card
              state: "NW"
          - sensor.template.publish:
              id: wind_heading
              state: 315.0

  - platform: template
    name: "${friendly_name} wind heading"
    id: wind_heading
    unit_of_measurement: "°"

# rain volume - tippet bucket - reed switch (pulse)
  - platform: pulse_counter
    pin:  # Don't forget to add a pulling resistor 10K,  . 3V3 ---10 K----(gpio 38)-- reed swicth from tippet bucket--- GND
      number: GPIO38
      mode: INPUT
    unit_of_measurement: 'mm'
    name: "${friendly_name} rain gauge"
    icon: 'mdi:weather-rainy'
    id: rain_gauge
    internal: true
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    internal_filter: 13us
    update_interval: 60s
    filters:
      # Each 0.011" (0.2794mm) of rain causes one momentary contact closure
      - multiply: 0.2794
    accuracy_decimals: 4

  - platform: integration
    name: "${friendly_name} rainfall per min"
    id: rain_per_min
    time_unit: min
    unit_of_measurement: 'mm'
    icon: 'mdi:weather-rainy'
    sensor: rain_gauge

  - platform: total_daily_energy
    name: "${friendly_name} total daily rain"
    power_id: rain_gauge
    unit_of_measurement: 'mm'
    icon: 'mdi:weather-rainy'
    # x60 To convert to aggregated rain amount
    filters:
      - multiply: 60

# temparature and humidity
# dallas or dht 
   

# temparature, pressure and humidity
  - platform: bme280
    address: 0x76
    temperature:
      name: "${friendly_name} temperature"
      id: bme280_temperature
    pressure:
      name: "${friendly_name} pressure"
      id: bme280_pressure
    humidity:
      name: "${friendly_name} relative humidity"
      id: bme280_humidity
    update_interval: 10s

  - platform: template
    name: "Altitude"
    lambda: |-
      const float STANDARD_SEA_LEVEL_PRESSURE = 1013.25; //in hPa, see note
      return ((id(bme280_temperature).state + 273.15) / 0.0065) *
        (powf((STANDARD_SEA_LEVEL_PRESSURE / id(bme280_pressure).state), 0.190234) - 1); // in meter
    update_interval: 15s
    icon: 'mdi:signal'
    unit_of_measurement: 'm'

  - platform: absolute_humidity
    name: "Absolute Humidity"
    temperature: bme280_temperature
    humidity: bme280_humidity

  - platform: template
    name: "Dew Point"
    lambda: |-
      return (243.5*(log(id(bme280_humidity).state/100)+((17.67*id(bme280_temperature).state)/
      (243.5+id(bme280_temperature).state)))/(17.67-log(id(bme280_humidity).state/100)-
      ((17.67*id(bme280_temperature).state)/(243.5+id(bme280_temperature).state))));
    unit_of_measurement: °C
    icon: 'mdi:thermometer-alert'

# ambient light
  - platform: tsl2561
    address: 0x39
    name: "${friendly_name} tsl 2561 ambient light"
    id: tsl_2561_ambient_light
    is_cs_package: false
    update_interval: 4s
    integration_time: 14ms
    gain: 1x

# UV and Ambient Light
  - platform: ltr390
    address: 0x53
    uv_index:
      name: "${friendly_name} ltr390 uv index"
      id: ltr390_uv_index
    uv:
      name: "${friendly_name} ltr390 uvs"
      id: ltr390_uvs
      filters:
        lambda: |-
            float wfac = 1.0;   // wfac
            float gain = 3.0;   // gain
            return ( ((id(ltr390_uvs).state * wfac) / 2300) * 4 * ( 18 / gain ));
    #    - multiply: 0.010434782608695652173913 # UVI = ( uv / 2300 * wfac ) * 4 * ( 18 / gain ); gain=3, wfac=1
    #    - sliding_window_moving_average:
    #        window_size: 15
    #        send_every: 1
    light:
      name: "${friendly_name} ltr390 light"  
      id: ltr390_light
    #  filters:
    #    - sliding_window_moving_average:
    #        window_size: 12
    #        send_every: 6
    ambient_light:
      name: "${friendly_name} ltr390 ambient light"
      id: ltr390_ambient_light
    resolution: 18
    gain: X3
    window_correction_factor: 1.0 # wfac
    update_interval: 4s 
  
text_sensor:
  - platform: version # Expose ESPHome version as sensor.
    name: $esphome_name ESPHome Version
    hide_timestamp: false
  - platform: wifi_info
    ip_address:
      name: "$esphome_name IP"
    ssid:
      name: "$esphome_name SSID"
    bssid:
      name: "$esphome_name BSSID"

  - platform: template
    name: "${friendly_name} wind cardinal direction"
    id: wind_dir_card

  - platform: template
    name: '${friendly_name} Beaufort wind scale'
    icon: 'mdi:tailwind'
    id: wind_scale
    update_interval: never

  - platform: template
    name: '${friendly_name} Beaufort wind scale code'
    icon: 'mdi:tailwind'
    id: wind_scale_code


display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
      // Print the string "Weather Station" at [1,11]
      //it.print(0, 10, id(roboto), "Weather Station");

      if (id(bme280_temperature).has_state()) {
        it.printf(0, 0, id(roboto),  "%.1f°", id(bme280_temperature).state);
      }
      if (id(bme280_humidity).has_state()) {
        it.printf(35, 0, id(roboto),  "%.1f %%", id(bme280_humidity).state);
      }
      if (id(bme280_pressure).has_state()) {
        it.printf(70, 0, id(roboto),  "%.2f kpa", id(bme280_pressure).state);
      }

      if (id(wind_speed_voltage).has_state()) {
        it.printf(0, 13, id(roboto),  "%.2f V-1", id(wind_speed_voltage).state);
      }

      if (id(wind_direction_voltage).has_state()) {
        it.printf(0, 25, id(roboto),  "%.2f V-2", id(wind_direction_voltage).state);
        it.printf(54, 25, id(roboto),  "%.1f", id(wind_heading).state);
        it.printf(90, 25, id(roboto),  "%s", id(wind_dir_card).state.c_str());
      }
      if (id(wind_speed_kmh_avg).has_state()) {
        it.printf(0, 38, id(roboto),  "%.2f V-2", id(wind_speed_kmh_avg).state);
        it.printf(54, 38, id(roboto),  "%.1f", id(wind_scale_code).state);
        it.printf(90, 38, id(roboto),  "%s", id(wind_scale).state.c_str());
      }
#       if (id(dht_temperature).has_state()) {
#        it.printf(0, 51, id(roboto),  "%.1f°", id(dht_temperature).state);
#      }

        
      

#      if (id(battery_voltage).has_state()) {
#        it.printf(0, 47, id(roboto),  "%.1f V", id(battery_voltage).state);
#      }

font:
  - file: "fonts/Roboto-Regular.ttf"
    id: my_font
    size: 10

  # gfonts://family[@weight]
  - file: "gfonts://Roboto"
    id: roboto
    size: 10

  - file:
      type: gfonts
      family: Roboto
      weight: 900
    id: font2
    size: 10

This might be why your dallas component is not working:

dallas:
  pin:
    number: 27
    inverted: true
    mode:
      input: true
      output: true

Should only be:

dallas:
  pin:
    number: 27

There should also be a 4K7 pull-up resistor to 3.3V on this GPIO.

Did your GPIO13 binary sensor work?

this i how it was, and yes, with a 4k7 pull-up from signal to 3V3 and GPIO.

after your advise regarding digging gpio binary sensor, i tried the conf with input, output… nothing is working.

gpio13 did not work either. from gpio 13 to gnd voltmeter shows 4V2.

?

It’s an input.

Short it to 3.3v and it should turn on. Short it to GND and it should turn off.

Floating it could be anything.