ESPHome  2024.3.2
sgp30.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include <cinttypes>
9 #include <cmath>
10 
11 namespace esphome {
12 namespace sgp30 {
13 
15  uint16_t eco2;
16  uint16_t tvoc;
17 } PACKED;
18 
21  public:
22  void set_eco2_sensor(sensor::Sensor *eco2) { eco2_sensor_ = eco2; }
23  void set_tvoc_sensor(sensor::Sensor *tvoc) { tvoc_sensor_ = tvoc; }
24  void set_eco2_baseline_sensor(sensor::Sensor *eco2_baseline) { eco2_sensor_baseline_ = eco2_baseline; }
25  void set_tvoc_baseline_sensor(sensor::Sensor *tvoc_baseline) { tvoc_sensor_baseline_ = tvoc_baseline; }
26  void set_store_baseline(bool store_baseline) { store_baseline_ = store_baseline; }
27  void set_eco2_baseline(uint16_t eco2_baseline) { eco2_baseline_ = eco2_baseline; }
28  void set_tvoc_baseline(uint16_t tvoc_baseline) { tvoc_baseline_ = tvoc_baseline; }
29  void set_humidity_sensor(sensor::Sensor *humidity) { humidity_sensor_ = humidity; }
31 
32  void setup() override;
33  void update() override;
34  void dump_config() override;
35  float get_setup_priority() const override { return setup_priority::DATA; }
36 
37  protected:
38  void send_env_data_();
39  void read_iaq_baseline_();
40  bool is_sensor_baseline_reliable_();
41  void write_iaq_baseline_(uint16_t eco2_baseline, uint16_t tvoc_baseline);
42  uint64_t serial_number_;
43  uint16_t featureset_;
48 
49  enum ErrorCode {
54  UNKNOWN
55  } error_code_{UNKNOWN};
56 
57  sensor::Sensor *eco2_sensor_{nullptr};
58  sensor::Sensor *tvoc_sensor_{nullptr};
59  sensor::Sensor *eco2_sensor_baseline_{nullptr};
60  sensor::Sensor *tvoc_sensor_baseline_{nullptr};
61  uint16_t eco2_baseline_{0x0000};
62  uint16_t tvoc_baseline_{0x0000};
64 
66  sensor::Sensor *humidity_sensor_{nullptr};
67  sensor::Sensor *temperature_sensor_{nullptr};
68 };
69 
70 } // namespace sgp30
71 } // namespace esphome
void setup()
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
uint32_t seconds_since_last_store_
Definition: sgp30.h:45
void set_eco2_baseline_sensor(sensor::Sensor *eco2_baseline)
Definition: sgp30.h:24
void set_tvoc_baseline_sensor(sensor::Sensor *tvoc_baseline)
Definition: sgp30.h:25
void set_eco2_sensor(sensor::Sensor *eco2)
Definition: sgp30.h:22
float temperature
Definition: qmp6988.h:71
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_store_baseline(bool store_baseline)
Definition: sgp30.h:26
void set_eco2_baseline(uint16_t eco2_baseline)
Definition: sgp30.h:27
SGP30Baselines baselines_storage_
Definition: sgp30.h:46
struct esphome::sgp30::SGP30Baselines PACKED
ESPPreferenceObject pref_
Definition: sgp30.h:47
void set_humidity_sensor(sensor::Sensor *humidity)
Definition: sgp30.h:29
uint32_t required_warm_up_time_
Definition: sgp30.h:44
void set_temperature_sensor(sensor::Sensor *temperature)
Definition: sgp30.h:30
Implementation of a i2c functions for Sensirion sensors Sensirion data requires crc checking...
Definition: i2c_sensirion.h:17
This class implements support for the Sensirion SGP30 i2c GAS (VOC and CO2eq) sensors.
Definition: sgp30.h:20
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57
void set_tvoc_sensor(sensor::Sensor *tvoc)
Definition: sgp30.h:23
void set_tvoc_baseline(uint16_t tvoc_baseline)
Definition: sgp30.h:28
float get_setup_priority() const override
Definition: sgp30.h:35