diff --git a/esphome/components/as7343/as7343.cpp b/esphome/components/as7343/as7343.cpp index a02b49b1a9..485df1fec8 100644 --- a/esphome/components/as7343/as7343.cpp +++ b/esphome/components/as7343/as7343.cpp @@ -269,6 +269,10 @@ void AS7343Component::calculate_and_publish() { ESP_LOGD(TAG, " ,Lux(XYZ) , %f, lx", lux2); ESP_LOGD(TAG, " ,Color temp(XYZ) , %f, K", cct); + if (this->ct_ != nullptr) { + this->ct_->publish_state(cct); + } + if (this->illuminance_ != nullptr) { this->illuminance_->publish_state(lux2); } diff --git a/esphome/components/as7343/as7343.h b/esphome/components/as7343/as7343.h index 5847d541b0..73e5eb37ee 100644 --- a/esphome/components/as7343/as7343.h +++ b/esphome/components/as7343/as7343.h @@ -35,6 +35,7 @@ class AS7343Component : public PollingComponent, public i2c::I2CDevice { void set_irradiance_photopic_sensor(sensor::Sensor *sensor) { irradiance_photopic_ = sensor; } void set_ppfd_sensor(sensor::Sensor *sensor) { ppfd_ = sensor; } void set_saturation_sensor(sensor::Sensor *sensor) { this->saturated_ = sensor; } + void set_color_temperature_sensor(sensor::Sensor *sensor) { ct_ = sensor; } void set_gain(AS7343Gain gain) { gain_ = gain; } void set_atime(uint8_t atime) { atime_ = atime; } @@ -114,6 +115,7 @@ class AS7343Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *irradiance_{nullptr}; sensor::Sensor *irradiance_photopic_{nullptr}; sensor::Sensor *ppfd_{nullptr}; + sensor::Sensor *ct_{nullptr}; sensor::Sensor *saturated_{nullptr}; diff --git a/esphome/components/as7343/sensor.py b/esphome/components/as7343/sensor.py index 507716b51b..8e5604017d 100644 --- a/esphome/components/as7343/sensor.py +++ b/esphome/components/as7343/sensor.py @@ -2,6 +2,7 @@ import esphome.codegen as cg import esphome.config_validation as cv from esphome.components import i2c, sensor from esphome.const import ( + CONF_COLOR_TEMPERATURE, CONF_GAIN, CONF_ID, CONF_NAME, @@ -10,8 +11,10 @@ from esphome.const import ( CONF_GLASS_ATTENUATION_FACTOR, ICON_BRIGHTNESS_5, STATE_CLASS_MEASUREMENT, + UNIT_KELVIN, UNIT_LUX, UNIT_PERCENT, + ICON_THERMOMETER, ) @@ -163,6 +166,15 @@ CONFIG_SCHEMA = ( ), key=CONF_NAME, ), + cv.Optional(CONF_COLOR_TEMPERATURE): cv.maybe_simple_value( + sensor.sensor_schema( + unit_of_measurement=UNIT_KELVIN, + icon=ICON_THERMOMETER, + accuracy_decimals=0, + state_class=STATE_CLASS_MEASUREMENT, + ), + key=CONF_NAME, + ), } ) .extend(cv.polling_component_schema("60s")) @@ -188,6 +200,7 @@ SENSORS = { CONF_IRRADIANCE_PHOTOPIC: "set_irradiance_photopic_sensor", CONF_PPFD: "set_ppfd_sensor", CONF_SATURATION: "set_saturation_sensor", + CONF_COLOR_TEMPERATURE: "set_color_temperature_sensor", }