From cc9dc95cab6b2d3af358aec42670e9f9105b76cb Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 31 Aug 2026 18:24:40 -0400 Subject: [PATCH] Only dial immediately at boot for deep sleep devices --- esphome/components/api/api_outgoing_connection.cpp | 3 +-- esphome/components/api/api_outgoing_connection.h | 11 ++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/esphome/components/api/api_outgoing_connection.cpp b/esphome/components/api/api_outgoing_connection.cpp index 966a148221..5ce1e4d695 100644 --- a/esphome/components/api/api_outgoing_connection.cpp +++ b/esphome/components/api/api_outgoing_connection.cpp @@ -46,8 +46,7 @@ void OutgoingConnectionManager::loop(APIServer *server) { switch (this->state_) { case DialState::DIAL_STATE_IDLE: // The connected target went away; give it the configured delay to - // reconnect on its own before dialing. (Boot skips this state so a - // device whose client never reached it dials right away.) + // reconnect on its own before dialing. this->state_ = DialState::DIAL_STATE_WAITING; this->state_ts_ = now; this->wait_ = API_OUTGOING_CONNECTION_DELAY; diff --git a/esphome/components/api/api_outgoing_connection.h b/esphome/components/api/api_outgoing_connection.h index 5581c3e135..aa5a4b7eb2 100644 --- a/esphome/components/api/api_outgoing_connection.h +++ b/esphome/components/api/api_outgoing_connection.h @@ -91,12 +91,17 @@ class OutgoingConnectionManager { SavedOutgoingTarget saved_{}; #endif uint32_t backoff_{BACKOFF_MIN_MS}; + // Boot starts in WAITING, measured from boot: normally the client is + // expected to connect in first, so the full delay applies. A deep sleep + // device wakes for a short window where connecting out IS the wake state, + // so it dials as soon as the network is up. +#ifdef USE_DEEP_SLEEP uint32_t wait_{0}; +#else + uint32_t wait_{API_OUTGOING_CONNECTION_DELAY}; +#endif uint32_t state_ts_{0}; uint32_t last_poll_{0}; - // Boot starts in WAITING with wait_ 0: when no dial-back client has ever - // connected (a device its client could never reach), dial immediately. - // The configured delay only applies after a connected target goes away. DialState state_{DialState::DIAL_STATE_WAITING}; };