Prerequisites
Before you begin, make sure you have:- Go 1.21 or later installed
- An ESPHome device with the Native API component enabled
- The device’s hostname or IP address and port (default port is
6053) - The
encryption.keyvalue from your ESPHome YAML (if the device uses encrypted connections)
Steps
Import the packages
Your Go file needs two import paths — the main client package and the generated protobuf types:
Connect with DialWithContext
Use Or use Connect to your device:
DialWithContext to connect with a parent context. The function signature is:Dial if you don’t need context cancellation:If your device does not use encryption, omit
WithEncryptionKey. The client will connect using a plain (unencrypted) TCP connection instead.List entities and subscribe to states
Discover the device’s entities, then subscribe to live state updates:
Complete example
Here is a full working program that puts all the steps together:main.go
Next steps
Library guide
Learn more about connecting, entity discovery, and subscriptions.
API reference
Full reference for all public types and methods.
CLI tool
Use the bundled CLI to inspect devices from the terminal.
Bluetooth proxy
Use ESPHome devices as BLE proxies for advertisement scanning and GATT.