ESPHome  2022.12.8
sgp30.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include <cmath>
8 
9 namespace esphome {
10 namespace sgp30 {
11 
13  uint16_t eco2;
14  uint16_t tvoc;
15 } PACKED;
16 
19  public:
20  void set_eco2_sensor(sensor::Sensor *eco2) { eco2_sensor_ = eco2; }
21  void set_tvoc_sensor(sensor::Sensor *tvoc) { tvoc_sensor_ = tvoc; }
22  void set_eco2_baseline_sensor(sensor::Sensor *eco2_baseline) { eco2_sensor_baseline_ = eco2_baseline; }
23  void set_tvoc_baseline_sensor(sensor::Sensor *tvoc_baseline) { tvoc_sensor_baseline_ = tvoc_baseline; }
24  void set_store_baseline(bool store_baseline) { store_baseline_ = store_baseline; }
25  void set_eco2_baseline(uint16_t eco2_baseline) { eco2_baseline_ = eco2_baseline; }
26  void set_tvoc_baseline(uint16_t tvoc_baseline) { tvoc_baseline_ = tvoc_baseline; }
27  void set_humidity_sensor(sensor::Sensor *humidity) { humidity_sensor_ = humidity; }
29 
30  void setup() override;
31  void update() override;
32  void dump_config() override;
33  float get_setup_priority() const override { return setup_priority::DATA; }
34 
35  protected:
36  void send_env_data_();
37  void read_iaq_baseline_();
38  bool is_sensor_baseline_reliable_();
39  void write_iaq_baseline_(uint16_t eco2_baseline, uint16_t tvoc_baseline);
40  uint64_t serial_number_;
41  uint16_t featureset_;
46 
47  enum ErrorCode {
52  UNKNOWN
53  } error_code_{UNKNOWN};
54 
55  sensor::Sensor *eco2_sensor_{nullptr};
56  sensor::Sensor *tvoc_sensor_{nullptr};
57  sensor::Sensor *eco2_sensor_baseline_{nullptr};
58  sensor::Sensor *tvoc_sensor_baseline_{nullptr};
59  uint16_t eco2_baseline_{0x0000};
60  uint16_t tvoc_baseline_{0x0000};
62 
64  sensor::Sensor *humidity_sensor_{nullptr};
65  sensor::Sensor *temperature_sensor_{nullptr};
66 };
67 
68 } // namespace sgp30
69 } // namespace esphome
void setup()
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:18
uint32_t seconds_since_last_store_
Definition: sgp30.h:43
void set_eco2_baseline_sensor(sensor::Sensor *eco2_baseline)
Definition: sgp30.h:22
void set_tvoc_baseline_sensor(sensor::Sensor *tvoc_baseline)
Definition: sgp30.h:23
void set_eco2_sensor(sensor::Sensor *eco2)
Definition: sgp30.h:20
float temperature
Definition: qmp6988.h:71
This class simplifies creating components that periodically check a state.
Definition: component.h:267
void set_store_baseline(bool store_baseline)
Definition: sgp30.h:24
void set_eco2_baseline(uint16_t eco2_baseline)
Definition: sgp30.h:25
SGP30Baselines baselines_storage_
Definition: sgp30.h:44
struct esphome::sgp30::SGP30Baselines PACKED
ESPPreferenceObject pref_
Definition: sgp30.h:45
void set_humidity_sensor(sensor::Sensor *humidity)
Definition: sgp30.h:27
uint32_t required_warm_up_time_
Definition: sgp30.h:42
void set_temperature_sensor(sensor::Sensor *temperature)
Definition: sgp30.h:28
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:18
Definition: a4988.cpp:4
Base-class for all sensors.
Definition: sensor.h:50
void set_tvoc_sensor(sensor::Sensor *tvoc)
Definition: sgp30.h:21
void set_tvoc_baseline(uint16_t tvoc_baseline)
Definition: sgp30.h:26
float get_setup_priority() const override
Definition: sgp30.h:33