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-18.0.8.tar.gz (71.4 kB view details)

Uploaded Source

Built Distributions

aioesphomeapi-18.0.8-cp312-cp312-musllinux_1_1_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.8-cp312-cp312-musllinux_1_1_i686.whl (2.1 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.8-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.1 MB view details)

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

aioesphomeapi-18.0.8-cp311-cp311-musllinux_1_1_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.8-cp311-cp311-musllinux_1_1_i686.whl (2.1 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.8-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.1 MB view details)

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

aioesphomeapi-18.0.8-cp310-cp310-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.8-cp310-cp310-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.8-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.9 MB view details)

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

aioesphomeapi-18.0.8-cp39-cp39-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.8-cp39-cp39-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.8-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.9 MB view details)

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

File details

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

File metadata

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

File hashes

Hashes for aioesphomeapi-18.0.8.tar.gz
Algorithm Hash digest
SHA256 e9adc41c9030a9fbf83dce20dbcf77ff784139c0ee1f8d156b5e59f206532c0d
MD5 87346aff85aed5abc3b0188329e56594
BLAKE2b-256 e69c71e24056c0b9f8306a28b4cc0dac1cafa0b7d999b5f5b64f722dbac99dc7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 2d3d7e227836873d83b71fe75636682cd92e9ba0a23558404716894d12aaf26e
MD5 ad32dff08d772772bb3928db98d52b46
BLAKE2b-256 b3afda8495a4d25823c01012a9adf45c173e36d2f8ca0a17451a655312741da4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 d4168d07c79def290d79dc47f795645683a5e0ac7c2f799cd94bbc296eebfe4e
MD5 0f232cf73e9cfc4e26037ea80d07b1a9
BLAKE2b-256 f21ba96b19f422f343e7672dafd8dbf4b261e08126e3bbea60283679cb25ad60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1fa9db15ff52237e3887726b531f02fe9f0c51eb5fe415b43a80141a91ec3d84
MD5 4f30e6f6ae12151c0071fb3fb9eca42c
BLAKE2b-256 8c2bdb32d977886ca77aa1073d000916a2962a463d828cd4836f2ba1df6b080d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 347c4e0d190cbf745465ca52f12bfdf75146d1a9df01fefa4f57933804c65e05
MD5 2bc33a9dd064d4195f45ec6ae0886952
BLAKE2b-256 fdad1885d6653caca933598c729e20cb929a0c9497e067ebc054734d55419b32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1182f299f16a836d20596fe8d808b7eb6d69337f70f96a2f22986305fa0f861c
MD5 4a06e3ed608bc84e27298033f89eb812
BLAKE2b-256 bad9220b3a7c3efd791da8f4f071fd1ae9788334d6fb56175881d4226f96cfec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 5219502ea531ba4f9bf7f4639acca60de154ebc5504604e9e994cd9d4686a647
MD5 7837ef4e4a8c9e63e1575a0f31f04d97
BLAKE2b-256 1117b532a7ed44861d866a83435ee76ed96e2c9749d4287fda7c30768001852a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f93809f35fad0afccd4e3a6b13e7ac1088295f15d0c5b62c0a22f48651e0761
MD5 a938a673663068f3805c095e944527f2
BLAKE2b-256 8366e87b3b2c79471b78b6e663152ce917288f607054b2866fc0346e60df2e9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 1a3c2ece55826ad6cb72c9b54b463224c81c155854e462c6b27e80d040660a37
MD5 4af9d1d7e5708ce39a963b3d7f2c52bc
BLAKE2b-256 ad1bcc6faebe9d9e74c318ff75b4c2242f2f2cd29c15c438d2848a2f1b0f830f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c12f9cb6d1cb56ba604264ec0e0fbeaafd367ce23a9fc810edb2c9fcc2b9fd93
MD5 f4f02d8af38621b70aa454043d11866f
BLAKE2b-256 6cfc87a618ab9a5a14428f3d9c68da653a022bed4cdcf1835daac75d8afe5730

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 24d40c4008e56ab672c014832c3409ae0ab07c218bd1ae8a82f52d968f2addf2
MD5 d96f926c30c2405f4d76fc45367bfc63
BLAKE2b-256 86832029fc133426f01aecddf41b10a5207b51595d069864c7c589d434888509

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4bd380669dbc025b7f41f606d9c87791e4d38683cbfae9d14b5cb8c45d49496c
MD5 da8044e2802428443a8605844126de5b
BLAKE2b-256 72cd149b98d72633d81e22fbd82930eef4b0674cf05cf4da900f4d21035a376f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 0896bec8367e1294d6b7622968ed00775486ddd070a3bd291aed3936f69916b5
MD5 dde6d8601c19bd9940705cc3f14d2f41
BLAKE2b-256 01fd248195cec2ba8037f51b7a927f4c9662200a9093b27de4e26333ff8f6220

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 af949c735cfda380ede41bcbe76f67958d409fcae50c85fb0424234af210e0db
MD5 c000580bfb2e970ccda0ba072f2e116d
BLAKE2b-256 9eb1facb5c37c9b6d609af7d00d52a59fde616b69dc4cb8523f92665853e74f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 7161733ef052d86f0e2555a41fdabffbc398362d652f369a9c9f2f7067cac458
MD5 8082a03373166833db62186db49f89eb
BLAKE2b-256 151a730850b7d0c49f35f7770f093dd6cabb42a14729c99388a8424a480f8279

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b7020c62965c32b8a8e0881c21c0c26f113ae1587c49f4a35ee13e129f1052cc
MD5 1ecb44ec2155f8570c6622268d5f7da4
BLAKE2b-256 ff7a098c0c4b1235f1d434c168cd4033989c5a8110b4a843eec3057ff30eaad8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.8-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 7723e49b670ace03e8f90bab6ff5acc98ff1bf9b25fac76370d2c47305fd056a
MD5 4382d557bf65eaf6d31be0e767492b5f
BLAKE2b-256 a21454fb223293661b9881479b654d18dab909a80ed49e9053a482327f6e0bfe

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