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