HTU21D Temperature/Humidity Sensor

The HTU21D component allows you get accurate temperature and humidity readings from your HTU21D (datasheet, adafruit) sensors with esphomelib. To use these i2c-based devices, first initialize the i2c bus using the pins you have for SDA and SCL and then create the sensors themselves as in below example.

Example Usage

// inside setup()
App.init_i2c(SDA_PIN, SCL_PIN); // change these values for your pins.
// create sensors
App.make_htu21d_sensor("Outside Temperature", "Outside Humidity");

See Application::make_htu21d_sensor().

API Reference

class HTU21DComponent : public PollingComponent, public I2CDevice

This component represents the HTU21D i2c temperature+humidity sensor in esphomelib.

It’s basically an i2c-based accurate temperature and humidity sensor. See for more information.

Public Functions

HTU21DComponent(I2CComponent *parent, const std::string &temperature_name, const std::string &humidity_name, uint32_t update_interval = 15000)

Construct the HTU21D with the given update interval.

HTU21DTemperatureSensor *get_temperature_sensor() const

Get a pointer to the temperature sensor object used to expose temperatures as a sensor.

HTU21DHumiditySensor *get_humidity_sensor() const

Get a pointer to the humidity sensor object used to expose humidities as a sensor.

void setup()

Setup (reset) the sensor and check connection.

void dump_config()
void update()

Update the sensor values (temperature+humidity).

float get_setup_priority() const

priority of setup().

higher -> executed earlier

Defaults to 0.

The setup priority of this component

Protected Attributes

HTU21DTemperatureSensor *temperature_ = {nullptr}
HTU21DHumiditySensor *humidity_ = {nullptr}