8static const uint16_t SFA30_CMD_GET_DEVICE_MARKING = 0xD060;
9static const uint16_t SFA30_CMD_START_CONTINUOUS_MEASUREMENTS = 0x0006;
10static const uint16_t SFA30_CMD_READ_MEASUREMENT = 0x0327;
14 uint16_t raw_device_marking[16];
15 if (!this->
get_register(SFA30_CMD_GET_DEVICE_MARKING, raw_device_marking, 16, 5)) {
16 this->
mark_failed(LOG_STR(
"Unable to read device marking"));
20 for (
size_t i = 0; i < 16; i++) {
21 this->
device_marking_[i * 2] =
static_cast<char>(raw_device_marking[i] >> 8);
22 this->
device_marking_[i * 2 + 1] =
static_cast<char>(raw_device_marking[i] & 0xFF);
26 if (!this->
write_command(SFA30_CMD_START_CONTINUOUS_MEASUREMENTS)) {
27 this->
mark_failed(LOG_STR(
"Error starting measurements"));
32void SFA30Component::dump_config() {
33 ESP_LOGCONFIG(TAG,
"sfa30:");
35 LOG_UPDATE_INTERVAL(
this);
37 LOG_SENSOR(
" ",
"Formaldehyde", this->formaldehyde_sensor_);
38 LOG_SENSOR(
" ",
"Humidity", this->humidity_sensor_);
39 LOG_SENSOR(
" ",
"Temperature", this->temperature_sensor_);
42void SFA30Component::update() {
44 ESP_LOGW(TAG,
"Error reading measurement!");
52 ESP_LOGW(TAG,
"Error reading measurement data!");
57 PUBLISH_STATE(this->formaldehyde_sensor_,
static_cast<int16_t
>(raw_data[0]) / 5.0f);
58 PUBLISH_STATE(this->humidity_sensor_,
static_cast<int16_t
>(raw_data[1]) / 100.0f);
59 PUBLISH_STATE(this->temperature_sensor_,
static_cast<int16_t
>(raw_data[2]) / 200.0f);