Debug ESPHOME sensors?

Trying esphome and esp8266 stuff for the first time. It’s amazingly easy to get things running.

But…

I have a problem. I have a NodeMCU, a AM2302 temp & humidity sensor, and a soil moisture sensor. The device comes up nicely, joins the internet, OTA works, the soil moisture meter is on a ADC and works very nicely all the time.

When the T&H sensor is working it is quite accurate and fast. When it fails, it reports 1C for temperature and 2% for humidity. Always exactly those numbers.

It always fails after a flash, whether OTA or via USB.

It either always, or almost always works after a power cycle. For a while, anywhere from minutes to hours.

It never goes from failed to working other than a power cycle.

I have tried two different nodeMCU chips, two different AM2302 chips, three different power supplies. I have checked (only with a meter no scope) all voltages at all points. I have tried the AM2302 without pullup (it shouldn’t need one), and a couple different ones. Tried different pings for the T&H digital signal. Nothing changes – it works (or rather fails) exactly the same way each time.

Are there any options for trying to figure out what is happening? Turning on debugging did not show me anything informative. The logging messages are identical for failing or working mode (except the actual values), except that the overall devices mqtt status node says ‘offline’ occasionally when failing (it seems to flip back and forth).

Short of starting over with all new, and different, hardware is there any kind of debugging I can do?

Here’s the sensor definition by the way:

sensor:
  - platform: dht
    pin: D1
    temperature:
      name: "Test3 Temperature"
    humidity:
      name: "Test3 Humidity"
    update_interval: 60s

How long are the connecting leads to the AM2302?

Have you tried specifying model: AM2302 in your sensor config?

@tom_l thanks.

The wire is about 3" long, just standard breadboard wire.

But the model is interesting. I had missed that option entirely. I added “am2302” and it started up working, which is a first. Will leave it running over night and see what happens.

Thank you! Your answer may get me going, but I am still curious – other than being a more careful reader, how could I have found this? Is there something I could do to determine (if indeed that is it) that the auto mode default determined it was the wrong type chip? I do not see anything in the debug log about sensor type at all (unless the code after it is that, i.e. 092).

I.e. to the general question, when things go wrong, is there an approach to start digging?

Always check the logs first. Though when there are no generated errors it can be tricky.

So re-read the documentation, very carefully. Compare the examples to your own code. Then double check it.

Then if you find nothing wrong search the forums or github for issues.

Then post a question on the forums if that all fails.

I had a few trials and tribulations with DHT sensors. One of them was that I found the default mode (AUTO-DETECT) was not good at recognising my DHT22s. So I had a bit of a head start on you for this one :slight_smile:

1 Like

You could have fixed it yourself if you read to the bottom of the help page: https://esphome.io/components/sensor/dht.html documenting is hard we don’t want to write any useless redundant information there but we want to tell all relevant information.

However people is always willing to help in a case like yours when you put a lot of effort to get it working and also explaining all you’ve already tried which is not little.

Both this makes esphome great. The docs and the community.

@glmnet, I definitely missed it. What’s odd is I somehow registered the pullup part, because I tried that numerous ways including a meter to check the pullup on the am2302. I plead selective blindness while thanking you guys for your patience.

I seems to have problems with my ESP8266 based temperature sensors and I thought that perhaps my issue were similar to yours (but I guess if yours is fixed my problem is different)
I’m using this combination ( ESP/DHT22)

The problem I have is getting consistent temperature and humidity readings from the setup.
Here is a log output:

[15:04:33][D][dht:048]: Got Temperature=27.9°C Humidity=40.9%
[15:04:43][D][dht:048]: Got Temperature=27.9°C Humidity=40.4%
WARNING Disconnected from API: Timeout while waiting for message response!
WARNING Error resolving IP address of raindance_esp1_temp2.local. Is it connected to WiFi?
WARNING (If this error persists, please set a static IP address: https://esphome.io/components/wifi.html#manual-ips)
WARNING Couldn't connect to API (Error resolving IP address: Error resolving address with mDNS: Did not respond. Maybe the device is offline., [Errno -5] No address associated with hostname). Trying to reconnect in 1 seconds
INFO Connecting to raindance_esp1_temp2.local:6053 (10.0.1.118)
INFO Successfully connected to raindance_esp1_temp2.local
[15:05:14][W][dht:120]: Requesting data from DHT failed!
[15:05:14][W][dht:058]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
ERROR Error while reading incoming messages: No socket!
WARNING Disconnected from API: Timeout while waiting for message response!
WARNING Error resolving IP address of raindance_esp1_temp2.local. Is it connected to WiFi?
WARNING (If this error persists, please set a static IP address: https://esphome.io/components/wifi.html#manual-ips)
WARNING Couldn't connect to API (Error resolving IP address: Error resolving address with mDNS: Did not respond. Maybe the device is offline., [Errno -5] No address associated with hostname). Trying to reconnect in 1 seconds
INFO Connecting to raindance_esp1_temp2.local:6053 (10.0.1.118)
INFO Successfully connected to raindance_esp1_temp2.local
[15:05:37][D][dht:048]: Got Temperature=28.0°C Humidity=41.5%

You’ll see that the device correctly reports temp & humidity at 15:04:33 and 15:04:43. After this I reset the device (pushbutton on the device) and after the device is back I get an error (see 15:05:14). This error persist until I power cycle the device which I did prior to 15:05:37.

While the setup seems to consistently not work after a reset but fine after a power cycle I have observed that over an extended period the device can start reporting that it “requesting data from DHT failed”

I’ve tried several things including:

  1. Trying different ESP01’s
  2. Trying different DHT22 devices
  3. Trying with model in the YAML-file set to;
    a) AM2302 (this is what’s printed on the temp sensor)
    b) AUTO_DETECT
    c) DHT22
    d) left blank

Anyone has any suggestions or solutions?

For completeness here is my YAML file:

esphome:
  name: raindance_esp1_temp2
  platform: ESP8266
  board: esp01_1m

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

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

sensor:
  - platform: dht
    pin: GPIO2
    model: AM2302
    update_interval: 10s
    temperature:
      name: "Temperature"
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
            send_first_at: 15
    humidity:
      name: "Humidity"
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
            send_first_at: 15

Which error repeated after 15:05:14, the “invalid readings”? I was getting those at times when I was moving wires around (ok, should not have with power applied but did). Any chance of something loose?

If it’s the other errors those look like it is dropping off wifi. I’d look at the router or monitor the network, maybe it’s disassociating. The time stamped errors are from the device, the others are from the logging tool on your side. Sorry if that’s obvious…

No loose wires - the 2 units are connected via a 2x4 pin header.
Also - the warning about disconnecting from the WiFi is normal and to be expected. To generate the log I did a reset and I did a power cycle. In both these cases it’s normal that the device disappear from WiFi until it’s done rebooting and reattaching.

“Which error repeated after 15:05:14, the “invalid readings”?”
I get the message that requesting data from DHT failed. This error message repeats every 10 seconds until I power cycle the device.

Do you have a pull-up resistor on the data line?

Anything between 4.7K to 10K Ohm.

Yes I do have the pull up resistor 4.7k

How long are your leads to the sensor?

Between the pin of ESP8266 and the sensor -properly 10 mm.

Well that’s not your problem.

Are you using 5V or 3.3V power to the DHT?

the sensor gets 3.3V like the ESP8266

On a related question: if the sensor says it operates on both, is one better than the other to use in terms of reliability?

Hey rssorensen,
I’m having EXACTLY the same issue with a DHT22 and ESP8266 (ESP01), did you ever figure out a solution? I’ve posted a bug report here:

Sound like the same as the problem you’re having?

Hopefully this is not the same problem. Try specifically setting the model of DHT sensor you have. The auto detect is very hit and miss.

sensor:
  - platform: dht
    pin: 2
    model: DHT22 ## or whatever model you are using
    temperature:
      name: "Living Room Temperature"
    humidity:
      name: "Living Room Humidity"
    update_interval: 10s

I have eight of these scattered around the house reporting perfectly for well over 18 months with this config (I keep the esphome version up to date on them too):

sensor:
  - platform: dht
    pin: D5
    model: DHT22
    update_interval: 15s
    temperature:
      name: "Dining Room Temperature"
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
            send_first_at: 15
    humidity:
      name: "Dining Room Humidity"
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
            send_first_at: 15

This gives 3m45s updates which is plenty for house temperatures.

Hi William.

I did not figure out what was causing this and I haven’t looked into it much lately.
Also - to comment on tom_I’s proposal on setting the model - I did try this including the auto detect option but the result remained the same.
FWIW - I do have another sensor using DHT11 and that works fine with the same ESP8266.

Did you ever find solution ? I have arduino like board D1 r2 . Exactly same issue not getting DHT22 sensor to work with esp home but andruido code it is working with same board and same pin. I tested 3 different sensors.