New EspHome version broke HTU21D component

I have two ESPHome devices that uses the HTU21D temperature and humidity sensors.
One of them is an ESP32 and the other is an ESP01.
Both have been working fine for some time.
Even though I updated ESPHome many times since I made these devices, I never needed to update the firmware on these devices since they were working fine. I recently had to update the firmware on these devices for some other reason. Now both of them are not working.

This is what the ESP01 shows:

[11:42:14][C][i2c.arduino:038]: I2C Bus:
[11:42:14][C][i2c.arduino:039]:   SDA Pin: GPIO0
[11:42:14][C][i2c.arduino:040]:   SCL Pin: GPIO2
[11:42:14][C][i2c.arduino:041]:   Frequency: 50000 Hz
[11:42:14][C][i2c.arduino:044]:   Recovery: bus successfully recovered
[11:42:14][I][i2c.arduino:054]: Results from i2c bus scan:
[11:42:14][I][i2c.arduino:056]: Found no i2c devices!
[11:42:15][C][htu21d:028]: HTU21D:
[11:42:15][C][htu21d:029]:   Address: 0x40
[11:42:15][E][htu21d:031]: Communication with HTU21D failed!
[11:42:15][C][htu21d:033]:   Update Interval: 60.0s
[11:42:15][C][htu21d:034]:   Temperature 'HTU21D-01 Temperature'
[11:42:15][C][htu21d:034]:     Device Class: 'temperature'
[11:42:15][C][htu21d:034]:     State Class: 'measurement'
[11:42:15][C][htu21d:034]:     Unit of Measurement: '°C'
[11:42:15][C][htu21d:034]:     Accuracy Decimals: 1
[11:42:15][C][htu21d:035]:   Humidity 'HTU21D-01 Humidity'
[11:42:15][C][htu21d:035]:     Device Class: 'humidity'
[11:42:15][C][htu21d:035]:     State Class: 'measurement'
[11:42:15][C][htu21d:035]:     Unit of Measurement: '%'
[11:42:15][C][htu21d:035]:     Accuracy Decimals: 1
[11:42:15][C][captive_portal:088]: Captive Portal:

the ESP32 device used to give the same exact error, since I updated it with a firmware compiled from an even newer version of ESPHome, It won’t give the same error as the above ESP01. However for some reason it finds more than one I2C device now but there is actually only one device.

[13:17:05][I][i2c.arduino:054]: Results from i2c bus scan:
[13:17:05][I][i2c.arduino:060]: Found i2c device at address 0x08
[13:17:05][I][i2c.arduino:060]: Found i2c device at address 0x40
[13:17:05][E][i2c.arduino:062]: Unknown error at address 0x4E
[13:17:05][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Balcony Water Sensor A'
[13:17:05][C][gpio.binary_sensor:016]:   Pin: GPIO18
[13:17:05][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Balcony Water Sensor B'
[13:17:05][C][gpio.binary_sensor:016]:   Pin: GPIO19
[13:17:05][C][switch.gpio:050]: GPIO Switch 'Balcony Switch A'
[13:17:05][C][switch.gpio:050]:   Inverted: YES
[13:17:05][C][switch.gpio:051]:   Pin: GPIO5
[13:17:05][C][switch.gpio:073]:   Restore Mode: Always OFF
[13:17:05][C][switch.gpio:050]: GPIO Switch 'Balcony Switch B'
[13:17:05][C][switch.gpio:050]:   Inverted: YES
[13:17:05][C][switch.gpio:051]:   Pin: GPIO17
[13:17:05][C][switch.gpio:073]:   Restore Mode: Always OFF
[13:17:05][C][switch.gpio:050]: GPIO Switch 'Balcony Switch C'
[13:17:05][C][switch.gpio:050]:   Inverted: YES
[13:17:05][C][switch.gpio:051]:   Pin: GPIO16
[13:17:05][C][switch.gpio:073]:   Restore Mode: Always OFF
[13:17:05][C][switch.gpio:050]: GPIO Switch 'Balcony Switch D'
[13:17:05][C][switch.gpio:050]:   Inverted: YES
[13:17:05][C][switch.gpio:051]:   Pin: GPIO4
[13:17:05][C][switch.gpio:073]:   Restore Mode: Always OFF
[13:17:05][C][htu21d:028]: HTU21D:
[13:17:05][C][htu21d:029]:   Address: 0x40
[13:17:05][E][htu21d:031]: Communication with HTU21D failed!
[13:17:05][C][htu21d:033]:   Update Interval: 60.0s
[13:17:05][C][htu21d:034]:   Temperature 'Balcony Temperature'
[13:17:05][C][htu21d:034]:     Device Class: 'temperature'
[13:17:05][C][htu21d:034]:     State Class: 'measurement'
[13:17:05][C][htu21d:034]:     Unit of Measurement: '°C'
[13:17:05][C][htu21d:034]:     Accuracy Decimals: 1
[13:17:05][C][htu21d:035]:   Humidity 'Balcony Humidity'
[13:17:05][C][htu21d:035]:     Device Class: 'humidity'
[13:17:05][C][htu21d:035]:     State Class: 'measurement'
[13:17:05][C][htu21d:035]:     Unit of Measurement: '%'
[13:17:05][C][htu21d:035]:     Accuracy Decimals: 1

I tried different HTU21D modules. I tried different power supplies, I checked cabling, I checked the code, everything seems normal.

The important thing is that they were working fine until I updated their firmware.

I left an issue on ESPHome GitHub page about this as well.
https://github.com/esphome/issues/issues/3646

I would really appreciate any help on the matter.

Thanks.

I have another device with HTU21D on an ESP01 in working condition since I never updated it’s firmware after ESPHome got an update. I can try to compile a new firmware with updated ESPHome to see if it will fail too with the updated firmware.

Well, I’m interested in this issue, as I’m going to but some HTU21D and use with ESP8266/ESP32 + esphome…let us know if it will fail too.

I will try to manually use the arduino i2c library and and create a custom component in ESPHome.
I’ll first try it on the Arduino IDE then with ESPHome.
I’ll post here the result.

Can please someone confirm that the HTU21D module is not working with EspHome anymore?
I seem to not be able to get my message across or maybe HTU21D is not cared or supported in EspHome anymore or maybe I’m missing somethings else…
I really don’t understand…

1 Like

Here is an update to this problem.

I still can not get the HTU21D module to work with the ESP01 module.

However, I used to be able to get it to work on my laptop which had EspHome 2021.9.3 installed.
But it is not working with compiling on the laptop too now.
EspHome 2021.9.3 normally requires platformio 5.2.0.
For some reason now it complains about requiring platformio core 6 to be install, which is really stupid because it is not compatible with EspHome 2021.9.3
This makes me think that maybe the problem is not with EspHome but maybe it is with platformio.

I can not get EspHome 2021.9.3 to work with platformio 5.2.0 at this point.
You can easily try this.
on your computer do the following:

pip install esphome==2021.9.3
pip install platformio==5.2.0
esphome compile yourcode.yaml
esphome upload yourcode.yaml --device 192.168..

this used to work back in 2022 when HTU21D support got broken, but it doesn’t now.
Now It complains about platformio6 and you will have to do pip install platformio==6.0.0 got get it to compile. It then compiles but still results with HTU21D not detected problem.

This makes me think that maybe the problm is with platformio6 rather than EspHome.

when you run esphome compile yourcode.yaml it then runs platformio run -d yourcode
maybe there is a command with platformio to make it disregard a newer version of platformio.

On the ESP32, try setting the I2C bus speed to 10000. (10kHz).

I had an issue with some MCP9600s when using the figure stated in the ESPHome data sheet which says it must be set to a minimum of 100kHz for them.

Same result as you - No device found.

This was an ESP32 that was working fine with two devices, prior to changing to HA.

I had quite a few of these devices working together, when in the Arduino IDE environment at 100kHz ok.

In HA, setting to 400,100,50kHz didn’t work.
Set to 10kHz and they burst into life.

Worth a try?

Thanks a lot for you suggestion.
Unfortunately it didn’t work
:frowning:

[11:35:14][C][i2c.arduino:053]: I2C Bus:
[11:35:14][C][i2c.arduino:054]:   SDA Pin: GPIO0
[11:35:14][C][i2c.arduino:055]:   SCL Pin: GPIO2
[11:35:14][C][i2c.arduino:056]:   Frequency: 10000 Hz
[11:35:14][C][i2c.arduino:059]:   Recovery: bus successfully recovered
[11:35:14][I][i2c.arduino:069]: Results from i2c bus scan:
[11:35:14][I][i2c.arduino:071]: Found no i2c devices!
[11:35:14][C][htu21d:028]: HTU21D:
[11:35:14][C][htu21d:029]:   Address: 0x40
[11:35:14][E][htu21d:031]: Communication with HTU21D failed!
[11:35:14][C][htu21d:033]:   Update Interval: 60.0s
[11:35:14][C][htu21d:034]:   Temperature 'HTU21D-01 Temperature'
[11:35:14][C][htu21d:034]:     Device Class: 'temperature'
[11:35:14][C][htu21d:034]:     State Class: 'measurement'
[11:35:14][C][htu21d:034]:     Unit of Measurement: '°C'
[11:35:14][C][htu21d:034]:     Accuracy Decimals: 1
[11:35:14][C][htu21d:035]:   Humidity 'HTU21D-01 Humidity'
[11:35:14][C][htu21d:035]:     Device Class: 'humidity'
[11:35:14][C][htu21d:035]:     State Class: 'measurement'
[11:35:14][C][htu21d:035]:     Unit of Measurement: '%'
[11:35:14][C][htu21d:035]:     Accuracy Decimals: 1

Sorry to hear that didn’t work.
The only other thing I could suggest would be to change the SCL and SDA pins used.

I don’tknow what type of ESP32 is being used, but GPIO0 and 2 are not the norm I2C pins… even though they worked before?
GIO0 is a ‘boot’ pin on at least one device I’ve seen.

The ‘standard’ seems to be
SDA = 21
SCL =22

Which works for me.

I’m using ESP8266 on an ESP01 module.
There is no problem when the same thing is programmed under arduino so it is not a pin issue.
This used to be working when platformio was v5.x.x. which is also around ESPHome v2021.9.3
This stopped working since platformio is v6.x.x

No sure if everyone else have already solved it but I want to share my experience the component htu21d.sensor was marked as failed issue.

I was trying to set up the following i2c sensor on the standard i2c pins (sda: 21, scl: 22) on an esp32:

  • HTU21D
  • BMP280
  • BH1750

While the latter 2 worked, HTU21D kept failing.
After a lot or trial and error what seems to have worked for me is to

  • leave the HTU21D on the standard i2c pins
  • connect the other 2 on a secondary i2c but

The other way around did not work.

This is my config

i2c:
  - id: bus_a
    sda: 21
    scl: 22
    scan: true
    frequency: 10kHz
  - id: bus_b
    sda: 25
    scl: 26
    scan: true
    frequency: 10kHz

sensor:
  - platform: bmp280
    i2c_id: bus_b
    temperature:
      name: "Temperature BMP"
      oversampling: 16x
    pressure:
      name: "Pressure"
    address: 0x76
    update_interval: 5s

  - platform: htu21d
    i2c_id: bus_a
    update_interval: 5s
    temperature:
      name: "Temperature HTU"
      id: air_temperature
    humidity:
      name: "Humidity"
      id: relative_humidity 

  - platform: bh1750
    i2c_id: bus_b
    name: "Illuminance"
    address: 0x23
    update_interval: 1s

Note: The 10kHz frequency on the i2c bus is something I experimented with and by the time I got it working I could not bear to flash a new firmware for one more time to use the default frequency. So I am not sure if using the default frequency would have any impact.

I have the same issue. It used to be working. Even though I posted this error multiple times this have always been ignored.
I have made more than 15 devices on EspHome but I’m leaving EspHome and moving all my devices to Arduino Home Assistant integraion aka ArduinoHA. It works with MQTT and devices automatically integrates into home assistant.
By the way you have more control of everything with proper c++ code anyways.

Eventually the issue I experienced had to do with some pull up resistors integrated on the sensor’s breakout board.
On the AliExpress listing description it says

This breakout board has built in 4.7k pull up resistors for I2C communications. If you are hooking up multiple I2C devices on the same bus, you may want to disable these resistors

So to overcome this issue without removing those resistor I simply used a second i2c bus and made sure the HTU21 is the only sensor on that bus.

As far as I can remember, the ESP32 should have 2 I2C ports but they are multiplexed meaning you can use either bus on various pins.

The ESP-01 module, an ESP8266 module has only one multiplexed I2C port. In my case I’m using ESP-01 modules and they only have a couple exposed pins meaning there’s not much to experiment with pins.

However, this Communication with HTU21D failed! and Found no i2c devices! problem does not happen if you don’t use EspHome and use standard Arduino C++ programming with an available HTU21D library. So this means that this is not a hardware problem and most probably it is an issue with platform.io which EspHome is based on.