ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
airthings_wave_plus.cpp
Go to the documentation of this file.
2
3#ifdef USE_ESP32
4
6
7static const char *const TAG = "airthings_wave_plus";
8
9void AirthingsWavePlus::read_sensors(uint8_t *raw_value, uint16_t value_len) {
10 auto *value = (WavePlusReadings *) raw_value;
11
12 if (sizeof(WavePlusReadings) <= value_len) {
13 ESP_LOGD(TAG, "version = %d", value->version);
14
15 if (value->version == 1) {
16 if (this->humidity_sensor_ != nullptr) {
17 this->humidity_sensor_->publish_state(value->humidity / 2.0f);
18 }
19
20 if ((this->radon_sensor_ != nullptr) && this->is_valid_radon_value_(value->radon)) {
21 this->radon_sensor_->publish_state(value->radon);
22 }
23
24 if ((this->radon_long_term_sensor_ != nullptr) && this->is_valid_radon_value_(value->radon_lt)) {
25 this->radon_long_term_sensor_->publish_state(value->radon_lt);
26 }
27
28 if (this->temperature_sensor_ != nullptr) {
29 this->temperature_sensor_->publish_state(value->temperature / 100.0f);
30 }
31
32 if (this->pressure_sensor_ != nullptr) {
33 this->pressure_sensor_->publish_state(value->pressure / 50.0f);
34 }
35
36 if ((this->co2_sensor_ != nullptr) && this->is_valid_co2_value_(value->co2)) {
37 this->co2_sensor_->publish_state(value->co2);
38 }
39
40 if ((this->tvoc_sensor_ != nullptr) && this->is_valid_voc_value_(value->voc)) {
41 this->tvoc_sensor_->publish_state(value->voc);
42 }
43
44 if (this->illuminance_sensor_ != nullptr) {
45 this->illuminance_sensor_->publish_state(value->ambientLight);
46 }
47 } else {
48 ESP_LOGE(TAG, "Invalid payload version (%d != 1, newer version or not a Wave Plus?)", value->version);
49 }
50 }
51
52 this->response_received_();
53}
54
55bool AirthingsWavePlus::is_valid_radon_value_(uint16_t radon) { return radon <= 16383; }
56
57bool AirthingsWavePlus::is_valid_co2_value_(uint16_t co2) { return co2 <= 16383; }
58
60 // these really don't belong here, but there doesn't seem to be a
61 // practical way to have the base class use LOG_SENSOR and include
62 // the TAG from this component
63 LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
64 LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
65 LOG_SENSOR(" ", "Pressure", this->pressure_sensor_);
66 LOG_SENSOR(" ", "TVOC", this->tvoc_sensor_);
67 LOG_SENSOR(" ", "Battery Voltage", this->battery_voltage_);
68
69 LOG_SENSOR(" ", "Radon", this->radon_sensor_);
70 LOG_SENSOR(" ", "Radon Long Term", this->radon_long_term_sensor_);
71 LOG_SENSOR(" ", "CO2", this->co2_sensor_);
72 LOG_SENSOR(" ", "Illuminance", this->illuminance_sensor_);
73}
74
76 const char *service_uuid;
77 const char *characteristic_uuid;
78 const char *access_control_point_characteristic_uuid;
79
80 // Change UUIDs for Wave Radon Gen2
81 switch (this->wave_device_type_) {
83 service_uuid = SERVICE_UUID_WAVE_RADON_GEN2;
84 characteristic_uuid = CHARACTERISTIC_UUID_WAVE_RADON_GEN2;
85 access_control_point_characteristic_uuid = ACCESS_CONTROL_POINT_CHARACTERISTIC_UUID_WAVE_RADON_GEN2;
86 break;
87 default:
88 // Wave Plus
89 service_uuid = SERVICE_UUID;
90 characteristic_uuid = CHARACTERISTIC_UUID;
91 access_control_point_characteristic_uuid = ACCESS_CONTROL_POINT_CHARACTERISTIC_UUID;
92 }
93
94 this->service_uuid_ = espbt::ESPBTUUID::from_raw(service_uuid);
95 this->sensors_data_characteristic_uuid_ = espbt::ESPBTUUID::from_raw(characteristic_uuid);
97 espbt::ESPBTUUID::from_raw(access_control_point_characteristic_uuid);
98}
99
100} // namespace esphome::airthings_wave_plus
101
102#endif // USE_ESP32
void read_sensors(uint8_t *raw_value, uint16_t value_len) override
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68