Python API for interacting with ESPHome devices.
Project description
aioesphomeapi allows you to interact with devices flashed with ESPHome.
Installation
The module is available from the Python Package Index.
$ pip3 install aioesphomeapi
An optional cython extension is available for better performance, and the module will try to build it automatically.
The extension requires a C compiler and Python development headers. The module will fall back to the pure Python implementation if they are unavailable.
Building the extension can be forcefully disabled by setting the environment variable SKIP_CYTHON to 1.
Usage
It’s required that you enable the Native API component for the device.
# Example configuration entry
api:
password: 'MyPassword'
Check the output to get the local address of the device or use the name:``under ``esphome: from the device configuration.
[17:56:38][C][api:095]: API Server:
[17:56:38][C][api:096]: Address: api_test.local:6053
The sample code below will connect to the device and retrieve details.
import aioesphomeapi
import asyncio
async def main():
"""Connect to an ESPHome device and get details."""
# Establish connection
api = aioesphomeapi.APIClient("api_test.local", 6053, "MyPassword")
await api.connect(login=True)
# Get API version of the device's firmware
print(api.api_version)
# Show device details
device_info = await api.device_info()
print(device_info)
# List all entities of the device
entities = await api.list_entities_services()
print(entities)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Subscribe to state changes of an ESPHome device.
import aioesphomeapi
import asyncio
async def main():
"""Connect to an ESPHome device and wait for state changes."""
cli = aioesphomeapi.APIClient("api_test.local", 6053, "MyPassword")
await cli.connect(login=True)
def change_callback(state):
"""Print the state changes of the device.."""
print(state)
# Subscribe to the state changes
await cli.subscribe_states(change_callback)
loop = asyncio.get_event_loop()
try:
asyncio.ensure_future(main())
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
loop.close()
Other examples:
Development
For development is recommended to use a Python virtual environment (venv).
# Setup virtualenv (optional)
$ python3 -m venv .
$ source bin/activate
# Install aioesphomeapi and development depenencies
$ pip3 install -e .
$ pip3 install -r requirements_test.txt
# Run linters & test
$ script/lint
# Update protobuf _pb2.py definitions (requires a protobuf compiler installation)
$ script/gen-protoc
A cli tool is also available for watching logs:
aioesphomeapi-logs --help
A cli tool is also available to discover devices:
aioesphomeapi-discover
License
aioesphomeapi is licensed under MIT, for more details check LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for aioesphomeapi-27.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 305a90ab8006808c64663f871beddc5b01831c8041985ff9a3a4ff8e38e580dd |
|
MD5 | dfafcdc6dd96aac904c87ae6113b0625 |
|
BLAKE2b-256 | b9361265f9bdbe2f3cdb8f936ff307e9185494a8a3be19e01f01c66b4e15c45c |
Hashes for aioesphomeapi-27.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b125ba66ff348cf20b2bd41022c0e777850f44cb3e9505661dc55ebb6227faf6 |
|
MD5 | 1445db0842291161ffbe99d956f685da |
|
BLAKE2b-256 | 24fbad39441f4f9c2b3b4986131c4fd4c8f2f44fc4089f861686980605908eda |
Hashes for aioesphomeapi-27.0.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9b7b59b97342fd3968a00aeef09d1a4afc239e06f736c1278561624f3b50510 |
|
MD5 | 9ae72f140739c72ca991369d9a960ce3 |
|
BLAKE2b-256 | 28251bba3beb3693ef83ea7b107356baa112770ae7eb5a24616a8758da12885e |
Hashes for aioesphomeapi-27.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 340622559c4e3a99b5ed5b95b613bb95ff247908ae825cd9731826c9030dcbbf |
|
MD5 | 800ebef151094f3f8f6c9d834d8fcdc1 |
|
BLAKE2b-256 | 5bf5c93ef42e13319961356400967b9bcc7614fec364ac99176303f11802ec85 |
Hashes for aioesphomeapi-27.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd00ec050960d7f5c06fcbd52999559f8f24355d7853048eced524069553cf3b |
|
MD5 | 315ecea5860c34a4dac3907d3562b646 |
|
BLAKE2b-256 | 9964664b60057415b1e190ccf681b1634158857010334351d58275c2a9c7c8b1 |
Hashes for aioesphomeapi-27.0.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd8524c4fc0a3dcb5c1cfb24219400be7e964eb1fc8d2e94aab5f7a05506e55f |
|
MD5 | 241fc126f7b7aa1eb1b222bf8c84f6cc |
|
BLAKE2b-256 | f4773243b8809c76fdc9ed8fc767a96b930dbc6c59be36676c9f310f84b60d9a |
Hashes for aioesphomeapi-27.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f216b149faf96fb690034b81bf227fb0a624860f1813d928a6769530a799ffe9 |
|
MD5 | 4a3fbca06f2c519b1e90651aa9aa0e9c |
|
BLAKE2b-256 | 729ace80cb44cb4aa389eab275c5221d6d050ddcaa4d25269a91d7b96f196b4d |
Hashes for aioesphomeapi-27.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e55e01c1cbd01cc1f2b6a9fa61ecd2e14326da81ba2bbaa6a7f551f199e0077 |
|
MD5 | b1af8f45aaba6b4f7ba95a0eb3a2770a |
|
BLAKE2b-256 | 64cc5371bae64bb05d968e1035a979f842efcc601f128fc59a2205765f773967 |
Hashes for aioesphomeapi-27.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e7cf16d1c8c682637b7b6c33dc6228f89687c0ee7681f8c49f753888a92e766 |
|
MD5 | 71ffe8ba27c17a42c07bc3176cf5ff45 |
|
BLAKE2b-256 | 34c70ee0584b55d4cb1af9a158e4a405d2e46a798520834527997d785266395d |