The ESPHome native API is a custom binary TCP protocol built on Protocol Buffers that provides highly efficient, low-latency communication between an ESPHome device and connected clients. Home Assistant uses this API exclusively for its ESPHome integration — no MQTT broker or additional middleware required. The Python library aioesphomeapi implements the full protocol and is available for building custom integrations.Documentation 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.
Enabling the Native API
Addapi: to your configuration. All options are optional — a bare api: block with no sub-keys is a valid and complete configuration for most use cases:
<node_name>.local or the device IP.
Protocol Overview
The native API operates on TCP port 6053. The protocol is message-framed: each message is prefixed with its length (varint-encoded) followed by a protobuf message type identifier and the serialized payload. The full message schema is defined in:esphome/components/api/api.proto
A typical client session follows this sequence:
The client opens a TCP connection to port 6053 and exchanges a hello/handshake message. If encryption is enabled, a Noise Protocol handshake occurs at this stage.
The client sends a
ListEntitiesRequest. The device responds with one message per configured entity — sensors, switches, lights, covers, etc. — describing each entity’s name, unique ID, and capabilities.After listing entities, the client sends a
SubscribeStatesRequest. The device immediately sends the current state of every entity, then pushes state-change messages in real time whenever a value changes.The client sends command messages such as
LightCommandRequest, SwitchCommandRequest, or user-defined action calls to control the device. User-defined actions defined in YAML under api: actions: appear in Home Assistant as callable services prefixed with esphome.<node_name>_.Encryption
The native API supports Noise Protocol encryption using a pre-shared 32-byte base64-encoded key. Enabling encryption is strongly recommended for production devices.Configuration Variables
TCP port to listen on. Defaults to
6053.A 32-byte base64-encoded string used as the Noise Protocol encryption key. Without this, all traffic is sent in plaintext.
How long to accumulate state updates before sending them as a batch. Lower values reduce latency; higher values reduce network packets. Range:
0ms–65535ms. Defaults to 100ms. Set to 0ms for maximum responsiveness (e.g., IR remote sensors with rapid ON→OFF transitions).Maximum simultaneous client connections. Defaults to
4 for ESP8266/RP2040, 5 for ESP32 and similar platforms. Each connection uses approximately 500–1000 bytes of RAM.Time to wait before rebooting if no client is connected. Compensates for cases where the ESP reports network connectivity when it actually has none. Set to
0s to disable. Defaults to 15min.User-defined actions exposed to Home Assistant. See User-defined Actions in the component docs.
Using aioesphomeapi
aioesphomeapi is the official Python client library for the native API. It is used internally by Home Assistant and by ESPHome’s ownesphome logs command.
Installation
Connecting and Subscribing to States
Controlling a Device
Streaming Logs
Theaioesphomeapi-logs CLI tool (bundled with ESPHome) provides log streaming without writing Python code:
Triggers and Conditions
The native API exposes two useful automation hooks in ESPHome YAML:api.connected condition checks whether at least one client is currently connected:
Native API vs. Web Server API
| Native API | Web Server API | |
|---|---|---|
| Protocol | Custom TCP + protobuf | HTTP REST + SSE |
| Port | 6053 | 80 (configurable) |
| Encryption | Noise Protocol (optional) | HTTPS (optional) |
| Efficiency | Very high — binary, batched | Moderate — text-based |
| Home Assistant | ✅ Primary integration | ❌ Not used by default |
| Custom scripts | aioesphomeapi (Python) | curl, fetch, any HTTP client |
| Real-time push | ✅ Native state subscription | ✅ SSE at /events |
| Best for | Home Assistant, performance | Web browsers, simple scripting |