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}; };