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

Uploaded Source

Built Distributions

aioesphomeapi-18.2.2-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.2.2-cp312-cp312-musllinux_1_1_i686.whl (2.1 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

aioesphomeapi-18.2.2-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.2.2-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.2.2-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.2.2-cp311-cp311-musllinux_1_1_i686.whl (2.1 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

aioesphomeapi-18.2.2-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.2.2-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.2.2-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.2.2-cp310-cp310-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-18.2.2-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.2.2-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.2.2-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.2.2-cp39-cp39-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-18.2.2-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.2.2-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.2.2.tar.gz.

File metadata

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

File hashes

Hashes for aioesphomeapi-18.2.2.tar.gz
Algorithm Hash digest
SHA256 c625355506b93cdaa27d40bd52fc6982bae878979dfe9143004965ea7464756d
MD5 bccbd1ff3262aee6e43d62f8b4bb142e
BLAKE2b-256 5c001b846b59e9049b7f12e448962dc0498eb114d915febada0411c93275f3f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1dc40a26ea5e1dbf3d0c0abe6e5c9fa4cc57361426f2796b783a531805096818
MD5 288407fba314de9e3b1dfbe6a3cb7447
BLAKE2b-256 4c2eff414b944d67eaf5436304658e68809541fb81482e7c3d2e2de4995eda43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 55db583741e8ccd833f8a5cfb153d4d7c64a50c11f14cd5a45d63f5e1dc1e231
MD5 4f42bb73c9ab9b0111284ad5780818f0
BLAKE2b-256 7e2f69bb1004dce159b56e35e5fdc47598a7b5e58cbce1e95d3b0c494eb38954

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0335919f679e58bc4f496091cd1071e37b3042511df9a7f8a2f1849b8feabea5
MD5 847d96e36b5d0f61227a3e680b56a32e
BLAKE2b-256 40cf700cc4b1a5659a42ff554090cef02f3196b0659f6070f65b7f501240cfd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 16ccdc4096c69e627f25d96bfb783ca89e6de5e821fb3a37317c180d889f9443
MD5 6efbd96e8800d220c83497dc0aac3c1e
BLAKE2b-256 1b45fea9e1bdd4fd00716f97fe42165f063e8c9ad6f9be8037c860f45c4f86cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e95c66d5540018b1ff2b7d8dcbe01c4b395f0fa6460e0917d173902dc7aa8179
MD5 2c505d2439f328999081fcf929d754ee
BLAKE2b-256 88edd76095f44815d2c5f1cdc0f77423a024a8ef97f8c763a4bc4b2b379c0d9e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 442020e115c53211596604c4a1e5d10f0d1eea655f9fc2ba0c26cb7c019c408d
MD5 0416b2ff28ecdb6104f55eb0609590ed
BLAKE2b-256 da931756fa04d832afd87cbd62bf66e3e7d43c8913cc61d6eac4eebc80525879

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0765d884aa9d917889ebe5e0d56475f614a45eef5fd26bc36e561f853a0a053b
MD5 74bb7bece3eb3866c8459dd87433a025
BLAKE2b-256 0e772d49fa6291ef01dcbc8065191248469ccd9f5c82d5e3c0295ccaa360744b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 0599ea8f0f088ca71a510c2456e678b8c2aac3eb8c79b22dd49c2d84f5742068
MD5 9470fe723223766254c0dcae6f419d47
BLAKE2b-256 bb76e68932cbf42b08180ced43d17faa918700c45e603e8797ba8103fe708ee6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 31598fbc73be209c7806d006eebf8c385077613a98b4ad0a132973f1b72db74b
MD5 a8a34a5a6406a24865c7c96da3754333
BLAKE2b-256 07304ccee9d3a8b94ca6207b104844e193b0690769289cfd89fd2aa6419ad303

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 4407ae655d8e9252f065d9ad774daec3a3af02f6e5d83d9b3a39fd981657c085
MD5 36d455f0936c3a6ae5a2b9c3cf2e5edd
BLAKE2b-256 7bb9abc5a681d2806a4679168d085b99e375128cd0a19e18d76aaebf5df3b92e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6f69054e7bd8b0a029683228f3c685d57e3f6d864b6d1cb90647b3e013f8b3d2
MD5 5b0ba9567931c3bcc139cb254f935e4e
BLAKE2b-256 253e430537bb6fb71fff7b641325c767694e7c48ca0785f7325e3eea59da9538

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 aa1ff426eff93aec81f42a4a8421fe50d799321a255555baaa5fa7c4f76b5be0
MD5 5b0540aac6f4b74c48c4bead94b1a1ad
BLAKE2b-256 17fa7c875fe290a032dd96330e1e328976ebdd3cf7e748b2f8ab73f0090588e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c9a6ff98ba1edb3aebc2f444b22fe17d1b1982210841d529fc36bdf765bf396f
MD5 5aad8fbae76df1d77e5d4e34646dfd3b
BLAKE2b-256 4f410f4a91485d17ad09377475292456ca970026233cfa921e3a3453f9559778

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 dc106d6d7bde0029cae8b89d680fb92227abb0bfb364fb3dc45f4f8e0470a413
MD5 97b5bc31937e63fa7b9aa5059b411655
BLAKE2b-256 9d2a90aef2eb51e28108eab7c9df2ce9a0e2c723ba7133ecdb8d6e4811c698d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 772f9c169bde9d34e683b937f1cbc661cb44ca76830159c4d380182dc5cd3404
MD5 09b2416caed865c9d5a78724308d9257
BLAKE2b-256 fb450daed0064464c07797fb42e7b276f61f691945058a50da0b7b43a44c2289

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 149da66469c0685898757e617143ee819e6670a6d08c31d3b305de8f499c7568
MD5 03d56be1c6a49a2db3529702af735718
BLAKE2b-256 e99e96b8f82715e0ba4b1b17fe06c33fc618dbc55da3592b79243d66b23cacb5

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