ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
dht.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
6
7namespace esphome::dht {
8
19
22inline int16_t decode_dht22_temperature(uint16_t raw) {
23 if (raw & 0x8000) {
24 if (!(raw & 0x4000))
25 return static_cast<int16_t>(-static_cast<int16_t>(raw & 0x7FFF));
26 } else if (raw & 0x800) {
27 raw |= 0xF000;
28 }
29 return static_cast<int16_t>(raw);
30}
31
33class DHT final : public PollingComponent {
34 SUB_SENSOR(temperature)
35 SUB_SENSOR(humidity)
36
37 public:
53 void set_dht_model(DHTModel model);
54
55 void set_pin(InternalGPIOPin *pin) {
56 this->t_pin_ = pin;
57 this->pin_ = pin->to_isr();
58 }
59
61 void setup() override;
62 void dump_config() override;
64 void update() override;
65
66 protected:
67 bool read_sensor_(float *temperature, float *humidity, bool report_errors);
68
72 bool is_auto_detect_{false};
73};
74
75} // namespace esphome::dht
uint8_t raw[35]
Definition bl0939.h:0
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition gpio_pin.h:98
This class simplifies creating components that periodically check a state.
Definition component.h:532
Component for reading temperature/humidity measurements from DHT11/DHT22 sensors.
Definition dht.h:33
bool is_auto_detect_
Definition dht.h:72
InternalGPIOPin * t_pin_
Definition dht.h:69
DHTModel model_
Definition dht.h:71
bool read_sensor_(float *temperature, float *humidity, bool report_errors)
Definition dht.cpp:63
ISRInternalGPIOPin pin_
Definition dht.h:70
ISRInternalGPIOPin to_isr() const
Definition gpio.cpp:96
@ DHT_MODEL_AUTO_DETECT
Definition dht.h:10
@ DHT_MODEL_DHT22
Definition dht.h:12
@ DHT_MODEL_AM2302
Definition dht.h:14
@ DHT_MODEL_SI7021
Definition dht.h:16
@ DHT_MODEL_DHT22_TYPE2
Definition dht.h:17
@ DHT_MODEL_AM2120
Definition dht.h:13
@ DHT_MODEL_RHT03
Definition dht.h:15
@ DHT_MODEL_DHT11
Definition dht.h:11
int16_t decode_dht22_temperature(uint16_t raw)
Convert a DHT22-family temperature reading to tenths of a degree.
Definition dht.h:22
uint16_t temperature
Definition sun_gtil2.cpp:12