ESPHome 2026.2.4
Loading...
Searching...
No Matches
mhz19.h
Go to the documentation of this file.
1#pragma once
2
7
8namespace esphome::mhz19 {
9
15
22
24 public:
25 void setup() override;
26 void update() override;
27 void dump_config() override;
28
29 void calibrate_zero();
30 void abc_enable();
31 void abc_disable();
32 void range_set(MHZ19DetectionRange detection_range);
33
34 void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
35 void set_co2_sensor(sensor::Sensor *co2_sensor) { co2_sensor_ = co2_sensor; }
36 void set_abc_enabled(bool abc_enabled) { abc_boot_logic_ = abc_enabled ? MHZ19_ABC_ENABLED : MHZ19_ABC_DISABLED; }
37 void set_warmup_seconds(uint32_t seconds) { warmup_seconds_ = seconds; }
38 void set_detection_range(MHZ19DetectionRange detection_range) { detection_range_ = detection_range; }
39
40 protected:
41 bool mhz19_write_command_(const uint8_t *command, uint8_t *response);
42
46
48
50};
51
52template<typename... Ts> class MHZ19CalibrateZeroAction : public Action<Ts...>, public Parented<MHZ19Component> {
53 public:
54 void play(const Ts &...x) override { this->parent_->calibrate_zero(); }
55};
56
57template<typename... Ts> class MHZ19ABCEnableAction : public Action<Ts...>, public Parented<MHZ19Component> {
58 public:
59 void play(const Ts &...x) override { this->parent_->abc_enable(); }
60};
61
62template<typename... Ts> class MHZ19ABCDisableAction : public Action<Ts...>, public Parented<MHZ19Component> {
63 public:
64 void play(const Ts &...x) override { this->parent_->abc_disable(); }
65};
66
67template<typename... Ts> class MHZ19DetectionRangeSetAction : public Action<Ts...>, public Parented<MHZ19Component> {
68 public:
70
71 void play(const Ts &...x) override { this->parent_->range_set(this->detection_range_.value(x...)); }
72};
73
74} // namespace esphome::mhz19
virtual void play(const Ts &...x)=0
Helper class to easily give an object a parent of type T.
Definition helpers.h:1471
This class simplifies creating components that periodically check a state.
Definition component.h:512
void play(const Ts &...x) override
Definition mhz19.h:64
void play(const Ts &...x) override
Definition mhz19.h:59
void play(const Ts &...x) override
Definition mhz19.h:54
void range_set(MHZ19DetectionRange detection_range)
Definition mhz19.cpp:106
void set_abc_enabled(bool abc_enabled)
Definition mhz19.h:36
void set_detection_range(MHZ19DetectionRange detection_range)
Definition mhz19.h:38
void dump_config() override
Definition mhz19.cpp:140
MHZ19DetectionRange detection_range_
Definition mhz19.h:49
sensor::Sensor * temperature_sensor_
Definition mhz19.h:43
sensor::Sensor * co2_sensor_
Definition mhz19.h:44
bool mhz19_write_command_(const uint8_t *command, uint8_t *response)
Definition mhz19.cpp:126
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition mhz19.h:34
MHZ19ABCLogic abc_boot_logic_
Definition mhz19.h:45
void set_warmup_seconds(uint32_t seconds)
Definition mhz19.h:37
void set_co2_sensor(sensor::Sensor *co2_sensor)
Definition mhz19.h:35
TEMPLATABLE_VALUE(MHZ19DetectionRange, detection_range) void play(const Ts &...x) override
Definition mhz19.h:69
Base-class for all sensors.
Definition sensor.h:43
@ MHZ19_ABC_DISABLED
Definition mhz19.h:13
@ MHZ19_ABC_ENABLED
Definition mhz19.h:12
@ MHZ19_ABC_NONE
Definition mhz19.h:11
MHZ19DetectionRange
Definition mhz19.h:16
@ MHZ19_DETECTION_RANGE_0_10000PPM
Definition mhz19.h:20
@ MHZ19_DETECTION_RANGE_0_5000PPM
Definition mhz19.h:19
@ MHZ19_DETECTION_RANGE_0_2000PPM
Definition mhz19.h:18
@ MHZ19_DETECTION_RANGE_DEFAULT
Definition mhz19.h:17
uint16_t x
Definition tt21100.cpp:5