diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index b93bcf9fad..ea19e4642a 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -242,7 +242,7 @@ void APIConnection::loop() { // Section: Process Queue start_time = millis(); - if (this->helper_->can_write_without_blocking()) { + if (!this->deferred_message_queue_.empty() && this->helper_->can_write_without_blocking()) { this->deferred_message_queue_.process_queue(); } duration = millis() - start_time; diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index 5fb0d16d8d..7a6cf93db3 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -57,6 +57,7 @@ class DeferredMessageQueue { DeferredMessageQueue(APIConnection *api_connection) : api_connection_(api_connection) {} void process_queue(); void defer(void *source, send_message_t send_message); + bool empty() const { return deferred_queue_.empty(); } }; class APIConnection : public APIServerConnection {