mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 06:58:11 +01:00
scd30: Allow setting temperature offset (#1400)
This commit is contained in:
parent
0ea41e2f71
commit
b3169deda7
4 changed files with 17 additions and 0 deletions
|
@ -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_);
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue