HTU21D on Raspberry Pi

Hi,
I would like to use HTU21D sensor. The sensor is connected on Raspberry Pi (GPIO2 and GPIO3) and I can see it on address 0X40

pi@hassbian:~ $ /usr/sbin/i2cdetect -y 1

 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

00: – -- – -- – -- – -- – -- – -- – -- – --
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: 40 – -- – -- – -- – -- – -- – -- – -- –
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: – -- – -- – -- – --

I enabled htu21d platform in configuration file but I cannot see the values of the sensor in HA.
What else do I need to add to make it works?

Thanks!

Hi!

I had exactly the same problem: HTU21D sensor was correctly connected and configured, but didn’t work with Home Assistant. What I was seeing in the log file was either error “Bad reading: 5” or “Bad writing in bus: 121”, followed by “HTU21D sensor not detected in bus 1”. Searching for these errors didn’t give me anything…

I followed this post to download and build a C program that could actually give me some temperature/humidity values. So far, I could confirm that the sensor itself is wired properly and works.

I dug a bit deeper and tried to use the python library that Home Assistant was using to read HTU21D data (the hass module was written by the same guy), and confirmed that the test command
i2csense -s htu21d
resulted in the same errors, either 5 or 121, as above. Now I could see that these errors come from either write_byte or read_i2c_block_data in the smbus package. That was a clue…

Finally, I was able to find a workaround from somebody with similar symptoms: using an old I2C module driver, i2c_bcm2708, instead of the new one.

  1. Download the old module here.
  2. Copy this file into /boot/overlays.
  3. In /boot/config.txt add the line dtoverlay=i2c1-bcm2708 at the end.

After a reboot, my new sensors finally showed up in the Home Assistant.
Hope this helps!

3 Likes

Thank you for the reply.

However, I had already followed the directions of your suggested post when I initially set up my htu21d sensor.

/boot/config.txt

JTB - Enable HTU21D temperature sensor (HTU21D on Raspberry Pi)

dtoverlay=i2c1-bcm2708

ls -la i2c1*
-rwxr-xr-x 1 root root 886 Aug 7 01:53 i2c1-bcm2708.dtbo

As for how I am surviving in the meantime, I rolled back to an old version I had backed up last summer. It took a while to bring the interfaces up to date, but at least it works and I have heat again.

Home Automation is still for the tech-savvy, I am afraid, i.e., not ready for hoi polloi use.