ESPHome  2024.11.0
dht.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
6 
7 namespace esphome {
8 namespace dht {
9 
10 enum DHTModel {
19 };
20 
22 class DHT : public PollingComponent {
23  public:
39  void set_dht_model(DHTModel model);
40 
41  void set_pin(InternalGPIOPin *pin) { pin_ = pin; }
42  void set_model(DHTModel model) { model_ = model; }
43  void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
44  void set_humidity_sensor(sensor::Sensor *humidity_sensor) { humidity_sensor_ = humidity_sensor; }
45 
47  void setup() override;
48  void dump_config() override;
50  void update() override;
52  float get_setup_priority() const override;
53 
54  protected:
55  bool read_sensor_(float *temperature, float *humidity, bool report_errors);
56 
59  bool is_auto_detect_{false};
62 };
63 
64 } // namespace dht
65 } // namespace esphome
sensor::Sensor * temperature_sensor_
Definition: dht.h:60
DHTModel model_
Definition: dht.h:58
void set_dht_model(DHTModel model)
Manually select the DHT model.
Definition: dht.cpp:70
InternalGPIOPin * pin_
Definition: dht.h:57
Component for reading temperature/humidity measurements from DHT11/DHT22 sensors. ...
Definition: dht.h:22
bool is_auto_detect_
Definition: dht.h:59
sensor::Sensor * humidity_sensor_
Definition: dht.h:61
This class simplifies creating components that periodically check a state.
Definition: component.h:283
float get_setup_priority() const override
HARDWARE_LATE setup priority.
Definition: dht.cpp:69
void dump_config() override
Definition: dht.cpp:16
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
Definition: dht.h:44
void set_model(DHTModel model)
Definition: dht.h:42
DHTModel
Definition: dht.h:10
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: dht.h:43
uint16_t temperature
Definition: sun_gtil2.cpp:26
bool read_sensor_(float *temperature, float *humidity, bool report_errors)
Definition: dht.cpp:74
void setup() override
Set up the pins and check connection.
Definition: dht.cpp:10
void update() override
Update sensor values and push them to the frontend.
Definition: dht.cpp:33
void set_pin(InternalGPIOPin *pin)
Definition: dht.h:41
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57