diff --git a/esphome/components/dallas/dallas_component.cpp b/esphome/components/dallas/dallas_component.cpp index b1d28b8b4c..302422d6c7 100644 --- a/esphome/components/dallas/dallas_component.cpp +++ b/esphome/components/dallas/dallas_component.cpp @@ -134,7 +134,6 @@ void DallasComponent::update() { return; } if (!sensor->check_scratch_pad()) { - ESP_LOGW(TAG, "'%s' - Scratch pad checksum invalid!", sensor->get_name().c_str()); sensor->publish_state(NAN); this->status_set_warning(); return; @@ -241,13 +240,29 @@ bool DallasTemperatureSensor::setup_sensor() { return true; } bool DallasTemperatureSensor::check_scratch_pad() { + bool chksum_validity = (crc8(this->scratch_pad_, 8) == this->scratch_pad_[8]); + bool config_validity = false; + + switch (this->get_address8()[0]) { + case DALLAS_MODEL_DS18B20: + config_validity = ((this->scratch_pad_[4] & 0x9F) == 0x1F); + break; + default: + config_validity = ((this->scratch_pad_[4] & 0x10) == 0x10); + } + #ifdef ESPHOME_LOG_LEVEL_VERY_VERBOSE ESP_LOGVV(TAG, "Scratch pad: %02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X (%02X)", this->scratch_pad_[0], this->scratch_pad_[1], this->scratch_pad_[2], this->scratch_pad_[3], this->scratch_pad_[4], this->scratch_pad_[5], this->scratch_pad_[6], this->scratch_pad_[7], this->scratch_pad_[8], crc8(this->scratch_pad_, 8)); #endif - return crc8(this->scratch_pad_, 8) == this->scratch_pad_[8]; + if (!chksum_validity) { + ESP_LOGW(TAG, "'%s' - Scratch pad checksum invalid!", this->get_name().c_str()); + } else if (!config_validity) { + ESP_LOGW(TAG, "'%s' - Scratch pad config register invalid!", this->get_name().c_str()); + } + return chksum_validity && config_validity; } float DallasTemperatureSensor::get_temp_c() { int16_t temp = (int16_t(this->scratch_pad_[1]) << 11) | (int16_t(this->scratch_pad_[0]) << 3);