From 4822abde860670ada7733338548be4ccf6e4c4f2 Mon Sep 17 00:00:00 2001 From: Massimo Cetra Date: Tue, 10 May 2022 12:03:40 +0200 Subject: [PATCH] Fix BLE280 setup when the sensor is marked as failed. (#3396) --- esphome/components/bme280/bme280.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/esphome/components/bme280/bme280.cpp b/esphome/components/bme280/bme280.cpp index fcb293afa0..a4ea8d608e 100644 --- a/esphome/components/bme280/bme280.cpp +++ b/esphome/components/bme280/bme280.cpp @@ -81,6 +81,11 @@ static const char *iir_filter_to_str(BME280IIRFilter filter) { void BME280Component::setup() { ESP_LOGCONFIG(TAG, "Setting up BME280..."); uint8_t chip_id = 0; + + // Mark as not failed before initializing. Some devices will turn off sensors to save on batteries + // and when they come back on, the COMPONENT_STATE_FAILED bit must be unset on the component. + this->component_state_ &= ~COMPONENT_STATE_FAILED; + if (!this->read_byte(BME280_REGISTER_CHIPID, &chip_id)) { this->error_code_ = COMMUNICATION_FAILED; this->mark_failed();