diff --git a/esphome/components/sds011/sds011.cpp b/esphome/components/sds011/sds011.cpp index 1a5be0adc3..ddcbdbb712 100644 --- a/esphome/components/sds011/sds011.cpp +++ b/esphome/components/sds011/sds011.cpp @@ -50,6 +50,21 @@ void SDS011Component::setup() { this->sds011_write_command_(command_data); } +void SDS011Component::set_working_state(bool working_state) { + if (this->rx_mode_only_) { + // In RX-only mode we do not setup the sensor, it is assumed to be setup + // already + return; + } + uint8_t command_data[SDS011_DATA_REQUEST_LENGTH] = {0}; + command_data[0] = SDS011_COMMAND_SLEEP; + command_data[1] = SDS011_SET_MODE; + command_data[2] = working_state ? SDS011_MODE_WORK : SDS011_MODE_SLEEP; + command_data[13] = 0xff; + command_data[14] = 0xff; + this->sds011_write_command_(command_data); +} + void SDS011Component::dump_config() { ESP_LOGCONFIG(TAG, "SDS011:"); ESP_LOGCONFIG(TAG, " Update Interval: %u min", this->update_interval_min_); diff --git a/esphome/components/sds011/sds011.h b/esphome/components/sds011/sds011.h index 83f89df237..19e0cd3efe 100644 --- a/esphome/components/sds011/sds011.h +++ b/esphome/components/sds011/sds011.h @@ -25,6 +25,7 @@ class SDS011Component : public Component, public uart::UARTDevice { void set_update_interval(uint32_t val) { /* ignore */ } void set_update_interval_min(uint8_t update_interval_min); + void set_working_state(bool working_state); protected: void sds011_write_command_(const uint8_t *command);