DHT Temperature/Humidity Sensor

Example Usage

// Basic
App.make_dht_sensor("Outside Temperature", "Outside Humidity", 12);

See Application::make_dht_sensor().

API Reference

class DHTComponent : public PollingComponent

Component for reading temperature/humidity measurements from DHT11/DHT22 sensors.

Public Functions

DHTComponent(const std::string &temperature_name, const std::string &humidity_name, GPIOPin *pin, uint32_t update_interval = 15000)

Construct a DHTComponent.

Parameters
  • pin: The pin which DHT sensor is connected to.
  • update_interval: The interval in ms the sensor should be checked.

void set_dht_model(DHTModel model)

Manually select the DHT model.

Valid values are:

  • DHT_MODEL_AUTO_DETECT (default)
  • DHT_MODEL_DHT11
  • DHT_MODEL_DHT22
  • DHT_MODEL_AM2302
  • DHT_MODEL_RHT03

Parameters
  • model: The DHT model.

DHTTemperatureSensor *get_temperature_sensor() const
DHTHumiditySensor *get_humidity_sensor() const
void setup()

Set up the pins and check connection.

void dump_config()
void update()

Update sensor values and push them to the frontend.

float get_setup_priority() const

HARDWARE_LATE setup priority.

Protected Functions

bool HOT sensor::DHTComponent::read_sensor_(float * temperature, float * humidity, bool report_errors)

Protected Attributes

GPIOPin *pin_
DHTModel model_ = {DHT_MODEL_AUTO_DETECT}
bool is_auto_detect_ = {false}
DHTTemperatureSensor *temperature_sensor_
DHTHumiditySensor *humidity_sensor_