ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
hdc302x.h
Go to the documentation of this file.
1#pragma once
2
7
8namespace esphome::hdc302x {
9
10enum HDC302XPowerMode : uint8_t {
12 BALANCED = 0x0b,
13 LOW_POWER = 0x16,
15};
16
24 public:
25 void setup() override;
26 void dump_config() override;
27 void update() override;
28
29 void start_heater(uint16_t power, uint32_t duration_ms);
30 void stop_heater();
31
32 void set_temp_sensor(sensor::Sensor *temp_sensor) { this->temp_sensor_ = temp_sensor; }
33 void set_humidity_sensor(sensor::Sensor *humidity_sensor) { this->humidity_sensor_ = humidity_sensor; }
34
36
37 protected:
40
42 bool heater_active_{false};
43
44 bool enable_heater_();
45 bool configure_heater_(uint16_t power_level);
46 bool disable_heater_();
47 void read_data_();
48 uint32_t conversion_delay_ms_();
49};
50
51template<typename... Ts> class HeaterOnAction : public Action<Ts...>, public Parented<HDC302XComponent> {
52 public:
53 TEMPLATABLE_VALUE(uint16_t, power)
55
56 void play(const Ts &...x) override {
57 auto power_val = this->power_.value(x...);
58 auto duration_val = this->duration_.value(x...);
59 this->parent_->start_heater(power_val, duration_val);
60 }
61};
62
63template<typename... Ts> class HeaterOffAction : public Action<Ts...>, public Parented<HDC302XComponent> {
64 public:
65 void play(const Ts &...x) override { this->parent_->stop_heater(); }
66};
67
68} // namespace esphome::hdc302x
Helper class to easily give an object a parent of type T.
Definition helpers.h:1618
This class simplifies creating components that periodically check a state.
Definition component.h:527
HDC302x Temperature and humidity sensor.
Definition hdc302x.h:23
sensor::Sensor * humidity_sensor_
Definition hdc302x.h:39
void start_heater(uint16_t power, uint32_t duration_ms)
Definition hdc302x.cpp:62
void set_power_mode(HDC302XPowerMode power_mode)
Definition hdc302x.h:35
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
Definition hdc302x.h:33
sensor::Sensor * temp_sensor_
Definition hdc302x.h:38
void set_temp_sensor(sensor::Sensor *temp_sensor)
Definition hdc302x.h:32
bool configure_heater_(uint16_t power_level)
Definition hdc302x.cpp:93
void play(const Ts &...x) override
Definition hdc302x.h:65
duration void play(const Ts &...x) override
Definition hdc302x.h:56
TEMPLATABLE_VALUE(uint16_t, power) TEMPLATABLE_VALUE(uint32_t
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:132
Base-class for all sensors.
Definition sensor.h:47
PowerMode power_mode
Definition msa3xx.h:3
uint8_t duration
Definition msa3xx.h:0
uint16_t x
Definition tt21100.cpp:5