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

Uploaded Source

Built Distributions

aioesphomeapi-18.0.0-cp312-cp312-musllinux_1_1_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.0-cp312-cp312-musllinux_1_1_i686.whl (2.6 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.6 MB view details)

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

aioesphomeapi-18.0.0-cp311-cp311-musllinux_1_1_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.0-cp311-cp311-musllinux_1_1_i686.whl (2.6 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.6 MB view details)

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

aioesphomeapi-18.0.0-cp310-cp310-musllinux_1_1_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.0-cp310-cp310-musllinux_1_1_i686.whl (2.5 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view details)

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

aioesphomeapi-18.0.0-cp39-cp39-musllinux_1_1_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.0-cp39-cp39-musllinux_1_1_i686.whl (2.5 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.5 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.0.tar.gz.

File metadata

  • Download URL: aioesphomeapi-18.0.0.tar.gz
  • Upload date:
  • Size: 590.7 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.0.tar.gz
Algorithm Hash digest
SHA256 0780adab821401fb3ca0a278376d3b45bae27dfd496f8bfa6233a30366c34e8b
MD5 54c95f481727e2a233535f9c785c018c
BLAKE2b-256 01ea2518339453a17900af45ef2432f7d92ab50287d408de29a07bf28cf31b50

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6b61b0be0b983015397d830130f3d63b0698e4ec86ff3b170305ecbf62340116
MD5 cca54e60720be370c65f949104c257ee
BLAKE2b-256 062c2974258eaec5747c060fb149ceb135a9fcb14f40d622fc3ff7e9e0820d59

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 05610ffbbd8d6d0e8cf78f7723696177ff4bb8a960a22e42cd8f1a894dc72ae9
MD5 743fb82133743bc240b0ca9f8b9b8924
BLAKE2b-256 64ffbd2d0dd6b52db1fbd0f258adebdf3c1b0db3ffbd5c676ba47abc311cfb32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2df0747d89e063fb2a41676315cf37c31319646e59ada5cfc153da511e388e09
MD5 48483cf3498d1acac38138bab273d02b
BLAKE2b-256 9459fc2b40e774f541ac5f1235b2102d555cb712afefe211219ae4a3d6a72b96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4fc4915e9fe783b1499de77d34a7bdb716881890dbe23608cc622614b03eb5e3
MD5 79854a583f3845c3cb115ade50dc9c14
BLAKE2b-256 0e25a369f1d3ad4a265dd7f42eefc56da045ded3bdff8b9a3d487ba5316e4405

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d43de431ff9bda1ac2c97cb05efc8c03465f00a491cf7cc8ec18c9fce6cca9eb
MD5 317461d4225336799894861b6a7e0f1c
BLAKE2b-256 406629fd48577343c9bd51024c2f41cab91d529a0953250a7655f0da71754c8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 64b64f459226a2d04e836cfc6384d2dd17e255e0c427aff60e5a1130a1b6736d
MD5 1253b990c804663ecc9e8892d5faf2aa
BLAKE2b-256 71ebad38e75c6fefa62278ce2dd01145e9bbcb30a377fa5eb156b07cc943e272

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c0d1ea457eba538b53059a6d08c1b9f8e800afad3a1dc8e8f86addc295c44bda
MD5 34a3d1721735e73e82c79ac4d0be680e
BLAKE2b-256 26cc2207bbc1c98e92ab3e29955f6a5673ba6affeb5d5594842c7b5acd3eff8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 aad34150dff6c5f105118d517ba243568e55169a2e07db5ba53ae9ad4405dc26
MD5 2ba1bcb73d64467779c49e8fec0d36b7
BLAKE2b-256 ae925f64a48b65a82d9af6820badbc3614527bbeb7f65241bef5d3690f875830

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d5f5f4da113ceab635d2489a19f0291c49358a23054fe250b83d65cc86c5a693
MD5 da4f5772f1c54939dc029fe2bde33b12
BLAKE2b-256 036e5de54812d357bc25bafd75ffa2f4f0c54cca6ce8e488f09e8b40f0c366da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 54bc6340d6df84528a14ba38104e646ae85b5f1f96b236bdeb4ce3581e3524ff
MD5 dcf334a5a15af20d0bc3121bcc3de51f
BLAKE2b-256 709710e0a5a4e30108a164998af7555a91dec534d469d1ac6d25788d87df2370

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6d0bdd3368e0375f172e11b70458f343dac26fe238b65db1784a83438df1f325
MD5 c96f8375fc15f36192d73d90396c6e86
BLAKE2b-256 1a25d065230f4ab7e50d8916c1d8a1f8f4c56a5642a4c89431435bc285c51ced

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 a079f680eba8c5ab7c397f913ca8404fafecd276dc79545d5b8c8be920b4c0aa
MD5 dd7473ba285ca3d5e4699a3d4c796ed1
BLAKE2b-256 9e045265777367c12826ea0fc6026f8ba90a183ae965e3a6c1bb5da93016b413

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 81c4380fe2caf9cb0915805cee400fe3c276032577d81b7509bd1d66d63f6526
MD5 256b1a3a39da2514c1a423075694d61e
BLAKE2b-256 4235cace457384024bc2726a914966be3f75661b681254725ca67a8e7a6fe210

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 a67ec21d7f40d765063044ab9f92518cbdb9fe30387a0aa4f036885d91080a3d
MD5 c48cca738290416c45462990283ee152
BLAKE2b-256 8aa6e6ff694d24aba40cc9091f8f7176ff0040ad69d0fff16faf51aefbd31e17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc5f830f6d7584802228cee582b6b9c63702863dc5c30d891bba88a0b450155e
MD5 42ebf533e9824f9081d4c334679e6354
BLAKE2b-256 6344778a5dcd5cf10cc372109905da1c5dbeda3ad83957d2bfffee7ebe67202e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e7bbc06506e8331a120e2bc4809a6e64ccc0160345b182fbf7116a3e21585b9a
MD5 30ffa9daf56a7b3e45e73b6c55f8da6e
BLAKE2b-256 08a9a46b539b4b7e3f157ffd9e4634f321975fb2526cf2ebb6d6f9128450b075

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