Skip to main content

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

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

aioesphomeapi-17.1.4.tar.gz (383.3 kB view details)

Uploaded Source

Built Distributions

aioesphomeapi-17.1.4-cp312-cp312-musllinux_1_1_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

aioesphomeapi-17.1.4-cp312-cp312-musllinux_1_1_i686.whl (1.5 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

aioesphomeapi-17.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

aioesphomeapi-17.1.4-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.5 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

aioesphomeapi-17.1.4-cp311-cp311-musllinux_1_1_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

aioesphomeapi-17.1.4-cp311-cp311-musllinux_1_1_i686.whl (1.5 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

aioesphomeapi-17.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

aioesphomeapi-17.1.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.5 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

aioesphomeapi-17.1.4-cp310-cp310-musllinux_1_1_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

aioesphomeapi-17.1.4-cp310-cp310-musllinux_1_1_i686.whl (1.4 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-17.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

aioesphomeapi-17.1.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.4 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

aioesphomeapi-17.1.4-cp39-cp39-musllinux_1_1_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

aioesphomeapi-17.1.4-cp39-cp39-musllinux_1_1_i686.whl (1.4 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-17.1.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

aioesphomeapi-17.1.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

File details

Details for the file aioesphomeapi-17.1.4.tar.gz.

File metadata

  • Download URL: aioesphomeapi-17.1.4.tar.gz
  • Upload date:
  • Size: 383.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for aioesphomeapi-17.1.4.tar.gz
Algorithm Hash digest
SHA256 a3047a37e724a3db8da73088b10160aa1278e6cddf4073a53dcee7e4fa0b0368
MD5 1728c3dcb0f685f90428e42a22e953d6
BLAKE2b-256 39d8ad5addcef9bc78aa7fc46493cc6bf417c3d15ce3b0d4f43329faaf04bfa0

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp312-cp312-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 9100feea12afd7b8e12e54b7c0cfe2f478569ec7674fee9e45ca7f857acf3533
MD5 f35a325105494e7e00e03ae047c46f73
BLAKE2b-256 022759b6ea2d486a8d441b74776883519ebc6260eeea788f2a21dce21294496b

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp312-cp312-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 12513557051918ca60820c0a2849a7174d9a411505a74c281b84444bb56c5dd9
MD5 8d7479e4b5b37cdf0da17189ee946f3c
BLAKE2b-256 d715864ca98841c1bdac5df4148f5ab134ce253edd049e0a81c943deaf8fed3e

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 59de41c2b985483c02575c22e16b1f7ebf70f0ffbfd15dd3c300f4eb556a6afb
MD5 5c18f46ef10119fc668deef13506c3d8
BLAKE2b-256 c65b9300c2a1191f17c2fddb8c1f73d0546486d4d4e11883096463314c5272d5

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 5ee4d89256d18e9d1f01c3c19ad230ce894fb87c3878345c1955b88528c1e6a0
MD5 78342ee70368ada9ccb0a6776b093726
BLAKE2b-256 0454deaf265ba7aca8a23f26c56b7daa120ef4db0c634232d69ac3a01560e067

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 fb8688c83796be0eb23b333e1d35d96521a38344f752545f4cbf6e80dcc9970e
MD5 6295b86497d16a6beb1533fdabec39d0
BLAKE2b-256 3899611d64db4e168dbe017c6d4566d92825d45b4c5008d8570b8cd080155e97

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp311-cp311-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 9d351c12fc9e498773ba9a574f05e45d7396d7e2d40b9cb8f0cb7b54eaa03b54
MD5 1086b45e05f2d49204d6ff5fef3a7a43
BLAKE2b-256 08ebc8634318bf3c1e0d99ed4cc75de883f2573089629d99500b91a65c0a7c99

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ce5301bd640a8409c1bd0cdb8aba2cda4a96e9a1ecd2b494e7d32ab4c0bfaeca
MD5 232eec170bbce4480fc969302949674e
BLAKE2b-256 0e0a972876d589a4ee630e1b86e2a72f208dce45d7c6fe4f9d9dd796090732f3

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 48377d4e29d119170725004d3f703dbc68eb760bfe3a741894d0ce9cf767d773
MD5 f67be41030ea2b48ff9ecb6fc3260801
BLAKE2b-256 0c5b492b987526563c03c27e14a5c413ea7b271d354f663fe394da6a408840cb

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 2d06d00ad0d360b9236d19bc5c5cc87e6f0804598285ecb5d48e8f5e8fa2a7a4
MD5 aac69ee8fccf1f0fef6cae662d613ea1
BLAKE2b-256 2eb92343194d50dc3239a7a00e4548e40b9cb3a5700b26551d5b680928986eee

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp310-cp310-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 29eb50dfaa46436eccaa76a07d6ca2517b168f36b81e389e08e5e95adc7d7c2f
MD5 df6f49e82ad2b077d1979121797034af
BLAKE2b-256 a9fd2121dcd4f842d3b3c6f338274a5f579b4e1cdf9221d33ba35feed67df8ab

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef37c115453983e595ebf5821b87266d36cc5fc8a19884305eba5361b63d9e47
MD5 1687b4ce8f7626e36decc04135187e59
BLAKE2b-256 bb94efacceae45a7eb353d1fa34f14e46d7ed356e44d1afbd3ac31fdb0854db7

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ec5497a3f7120f1a9cf57516c187231fe460c3560fb2b84cdb6851229424d22b
MD5 441247fd36621b00f60d8ca398fbc70b
BLAKE2b-256 948cc41430477110704bbb36559e10414961a1e94aad3e013eb5a4bec9a3e63f

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6cc249f73b0fbb521976ae1215b6bb7a85f70b5a6d1589e6e971a9336bc841b3
MD5 c4e9c9014b5ee4c193fc7997318dd6fb
BLAKE2b-256 cc8e62977e6815db3af21dcf164e09226b727607b6d7f6f4a78ff20a9cc24da3

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp39-cp39-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 d9513873bd3c5d0cff54668dc7774d790478eb4b4dac3156cac3853acab14421
MD5 c88bde70348b544ef1e455ef066798a5
BLAKE2b-256 a64cb7c061e7f3a338f6b1f49c3f021cd43175a5e07e69f970abcfac03811083

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fc03a1769d86c7bb172978eb76f7fc70da01f5e44783b9c94ae6b28910ae4599
MD5 bf156b683ab3d812e2e775e925ad892b
BLAKE2b-256 9bd4a5e7468ff7f89e046d03f9b41c394a053a101afddbe17fddbb8cda79cf4d

See more details on using hashes here.

File details

Details for the file aioesphomeapi-17.1.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-17.1.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b34c3c86215f34bdfbe732bdbf77d99a70bf3d2bb01a256bfee671fc0f94c3ed
MD5 c83f7a170d43a3cb4245fafc22c173aa
BLAKE2b-256 a86f08430633ed1d8982a6a2f5e620e35bc6b09ac8334ba0c55a59f1d3fb99f1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page