diff --git a/esphome/components/scd30/scd30.cpp b/esphome/components/scd30/scd30.cpp index 31e78b4109..443deda3cc 100644 --- a/esphome/components/scd30/scd30.cpp +++ b/esphome/components/scd30/scd30.cpp @@ -51,6 +51,14 @@ void SCD30Component::setup() { return; } + if (this->temperature_offset_ != 0) { + if (!this->write_command_(SCD30_CMD_TEMPERATURE_OFFSET, (uint16_t)(temperature_offset_ * 100.0))) { + ESP_LOGE(TAG, "Sensor SCD30 error setting temperature offset."); + this->error_code_ = MEASUREMENT_INIT_FAILED; + this->mark_failed(); + return; + } + } // The start measurement command disables the altitude compensation, if any, so we only set it if it's turned on if (this->altitude_compensation_ != 0xFFFF) { if (!this->write_command_(SCD30_CMD_ALTITUDE_COMPENSATION, altitude_compensation_)) { @@ -95,6 +103,7 @@ void SCD30Component::dump_config() { } ESP_LOGCONFIG(TAG, " Automatic self calibration: %s", ONOFF(this->enable_asc_)); ESP_LOGCONFIG(TAG, " Ambient pressure compensation: %dmBar", this->ambient_pressure_compensation_); + ESP_LOGCONFIG(TAG, " Temperature offset: %.2f °C", this->temperature_offset_); LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "CO2", this->co2_sensor_); LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); diff --git a/esphome/components/scd30/scd30.h b/esphome/components/scd30/scd30.h index b017da0d99..f11b7cc1f4 100644 --- a/esphome/components/scd30/scd30.h +++ b/esphome/components/scd30/scd30.h @@ -18,6 +18,7 @@ class SCD30Component : public PollingComponent, public i2c::I2CDevice { void set_ambient_pressure_compensation(float pressure) { ambient_pressure_compensation_ = (uint16_t)(pressure * 1000); } + void set_temperature_offset(float offset) { temperature_offset_ = offset; } void setup() override; void update() override; @@ -39,6 +40,7 @@ class SCD30Component : public PollingComponent, public i2c::I2CDevice { bool enable_asc_{true}; uint16_t altitude_compensation_{0xFFFF}; uint16_t ambient_pressure_compensation_{0x0000}; + float temperature_offset_{0.0}; sensor::Sensor *co2_sensor_{nullptr}; sensor::Sensor *humidity_sensor_{nullptr}; diff --git a/esphome/components/scd30/sensor.py b/esphome/components/scd30/sensor.py index 53b9d86688..e1e66b636e 100644 --- a/esphome/components/scd30/sensor.py +++ b/esphome/components/scd30/sensor.py @@ -14,6 +14,7 @@ SCD30Component = scd30_ns.class_('SCD30Component', cg.PollingComponent, i2c.I2CD CONF_AUTOMATIC_SELF_CALIBRATION = 'automatic_self_calibration' CONF_ALTITUDE_COMPENSATION = 'altitude_compensation' CONF_AMBIENT_PRESSURE_COMPENSATION = 'ambient_pressure_compensation' +CONF_TEMPERATURE_OFFSET = 'temperature_offset' def remove_altitude_suffix(value): @@ -31,6 +32,7 @@ CONFIG_SCHEMA = cv.Schema({ cv.int_range(min=0, max=0xFFFF, max_included=False)), cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION, default=0): cv.pressure, + cv.Optional(CONF_TEMPERATURE_OFFSET): cv.temperature, }).extend(cv.polling_component_schema('60s')).extend(i2c.i2c_device_schema(0x61)) @@ -46,6 +48,9 @@ def to_code(config): if CONF_AMBIENT_PRESSURE_COMPENSATION in config: cg.add(var.set_ambient_pressure_compensation(config[CONF_AMBIENT_PRESSURE_COMPENSATION])) + if CONF_TEMPERATURE_OFFSET in config: + cg.add(var.set_temperature_offset(config[CONF_TEMPERATURE_OFFSET])) + if CONF_CO2 in config: sens = yield sensor.new_sensor(config[CONF_CO2]) cg.add(var.set_co2_sensor(sens)) diff --git a/tests/test1.yaml b/tests/test1.yaml index ca6ad6fba6..dff679115c 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -621,6 +621,7 @@ sensor: automatic_self_calibration: true altitude_compensation: 10m ambient_pressure_compensation: 961mBar + temperature_offset: 4.2C - platform: sgp30 eco2: name: 'Workshop eCO2'