The ESPHome native API provides a highly optimized, low-latency TCP protocol based on protocol buffers for direct communication between ESPHome devices and clients such as Home Assistant and ioBroker. AddingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/esphome/esphome.io/llms.txt
Use this file to discover all available pages before exploring further.
api: to your configuration is all that’s needed — Home Assistant will automatically discover the device (within ~5 minutes) and offer one-click integration setup. Compared to MQTT, the native API is roughly 10× more efficient for binary sensor payloads, requires no external broker, and supports real-time bidirectional data exchange including user-defined actions.
Minimal Example
Configuration Variables
The TCP port the API server listens on. Defaults to
6053.Enable noise-protocol encryption for all API traffic. Highly recommended for production deployments.
- key (Optional, string): A 32-byte base64-encoded encryption key. Generate one from the ESPHome dashboard or the native API docs page. If omitted, the key can be set at runtime, but encryption will not be active until it is.
How long to wait without any client connecting before rebooting. Catches cases where the low-level IP stack reports a connection but the API cannot actually accept clients. Set to
0s to disable. Defaults to 15min.Batching window for outgoing state update messages. Larger values group more updates per packet (less traffic); smaller values reduce latency. Range:
0ms–65535ms. Defaults to 100ms.Maximum simultaneous API client connections (1–20). Statically allocated at compile time. Defaults to
4 on ESP8266/RP2040, 5 on ESP32/BK72xx/RTL87xx/LN882x, 8 on host platform. Each active connection uses approximately 500–1000 bytes of RAM.Maximum pending connection queue depth (1–10). Defaults to
1 on ESP8266/RP2040, 4 on other platforms.Maximum queued outgoing messages per connection before the client is disconnected (1–64). Prevents memory exhaustion from slow/stalled clients. Defaults to
5 on ESP8266/RP2040, 8 on ESP32, 16 on host.User-defined actions exposed as Home Assistant services (prefixed with
esphome.<node_name>_). Each action may define variables to receive typed parameters from Home Assistant. Supported types: bool, int, float, string, and their array variants.Enable compilation of custom API services for external components that register their own services via the
CustomAPIDevice C++ class. Only needed for external components using this mechanism. Defaults to false.Enable compilation of Home Assistant service call support for external components using
CustomAPIDevice::call_homeassistant_service() or fire_homeassistant_event(). Automatically enabled when using homeassistant.service, homeassistant.event, or the homeassistant platform for number or switch. Defaults to false.Enable compilation of Home Assistant state subscription support for external components using
CustomAPIDevice::subscribe_homeassistant_state(). Automatically enabled when using any homeassistant platform component. Defaults to false.Triggered when a client connects. Provides
client_address (string) and client_info (string) variables.Triggered when a client disconnects. Same variables as
on_client_connected.Advanced Example
User-Defined Actions
Actions are callable from Home Assistant automations and scripts. They appear automatically after flashing.Action Response Handling
Actions can return data back to the calling client (ESPHome 2025.10.0+).Calling Home Assistant Actions
Firing Home Assistant Events
api.connected Condition
Set
state_subscription_only: true in api.connected to differentiate between Home Assistant connections (which subscribe to state updates) and logger-only connections from the ESPHome CLI (esphome logs). Using the default false may trigger your automation prematurely.Advantages Over MQTT
| Feature | Native API | MQTT |
|---|---|---|
| Message encoding | Protocol buffers (~10× smaller) | Plain text or JSON |
| Setup in Home Assistant | One-click auto-discovery | Manual broker + config |
| Single point of failure | None — each device is its own server | Broker required |
| Latency | Typically < 5 ms | Varies, broker-dependent |
| TLS encryption | Built-in noise protocol | Optional, broker-dependent |