Overview
The Nest thermostat initiates all connections. The server never dials out to the device. Instead, the device maintains a persistent long-poll connection and relies on the server to push data on it.Device Lifecycle (Full Flow)
WoWLAN — How the Device Sleeps
The thermostat is battery-powered and aggressively manages CPU sleep. After the server sends chunked response headers, the device:- Hands the open TCP socket to its WiFi hardware chipset
- Puts the main CPU to sleep
- Relies on the WiFi hardware to monitor the socket for incoming data (WoWLAN — WiFi Wake-on-LAN)
- When data arrives, the WiFi hardware wakes the CPU in ~100–500ms
Subscribe Cycle Timing
The server drives the reconnect cycle by closing the connection. The device’s
X-nl-suspend-time-max timer (default 300s) is a safety net, not the primary trigger.
Two-Port Architecture
The self-hosted server runs two independent HTTP services:Overlapping Subscriptions
When a device wakes early (user turns the dial), it sends a new subscribe request before the previous connection has closed. The server briefly sees two active subscriptions for the same device. The correct handling:- Track each subscription with a server-generated ID (not the device’s
sessionfield) - Push data to all active subscriptions when a change occurs
- Remove a subscription only when its specific connection closes
session field is reused across all subscribe requests during normal operation — it is not a unique connection identifier.