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

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded CPython 3.12musllinux: musl 1.1+ x86-64

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

Uploaded CPython 3.12musllinux: musl 1.1+ i686

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

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

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

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

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

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

Uploaded CPython 3.11musllinux: musl 1.1+ i686

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

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

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

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

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.3-cp310-cp310-musllinux_1_1_i686.whl (2.4 MB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

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

aioesphomeapi-18.0.3-cp39-cp39-musllinux_1_1_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9musllinux: musl 1.1+ x86-64

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

Uploaded CPython 3.9musllinux: musl 1.1+ i686

aioesphomeapi-18.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view details)

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

File details

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

File metadata

  • Download URL: aioesphomeapi-18.0.3.tar.gz
  • Upload date:
  • Size: 592.2 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.3.tar.gz
Algorithm Hash digest
SHA256 d3328cc2b3f99a1ced71362e990f6d08117816920a52faf458b76584fa7d29fc
MD5 f1d5efdd9b1e7f76bdac4a096aa446cf
BLAKE2b-256 5a9eebe8dabc1f2e2ae836b5b209d09d1eeae6851a4357feed9470fd87ef6d09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ff59632d4178c7f0c3ccf0261a0917268434533937713061b43faa776d8a4fa4
MD5 49e94dbf7aa38f69fa8d3f969a1d48ca
BLAKE2b-256 88c65d6e61c770e809eb64b4f9d27915793b70ac05eb61d3591d15504c8c5ce3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 4389ce2211e2ad18ad42f735c3e8f05f3aec142f5df0c9777ed2211c916dbb0f
MD5 e5d873c90253dd0cfd60139221c2f03f
BLAKE2b-256 fda3d01ec9077069450eab107e8bd437e404390cd5d5139e468f756827a3f8d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f1fe1dafe4b9a59a32666f8b92e50c5f5c020889391a9df329206ec08f431bbd
MD5 9e51d6ec8ce78b38c9cad9ae22ff1652
BLAKE2b-256 4f9fc247f678048eb043787752311defd9dd6971e9ff4e016fb3f7e4c3f18a1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 3f8ed811a0be60dcc2d2db34210e2205ee57b8555b7d3470bb35dda28d830a89
MD5 c3d3e98a14bc8804438fb6da03d564f8
BLAKE2b-256 922f2dcd414380827d91d93e65fa5d460a0ed2cd2493fce221fdd04fa07aac96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 02e6006cf657c6ded9c62327274949353b48928fb1ea36b86a9dbb0e6b249460
MD5 e1d8ec4593c13a4b0e90699e94fa5d47
BLAKE2b-256 b29396c7844a1fa7f4636557625f36527679622b0e764ee51984759cd8832835

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 c1e12e82243222c2b2e6f8c405e86a2d578808a6d747c98ec55da927e6336f78
MD5 caac88024deb1e25bf7a3beb43dfdec7
BLAKE2b-256 fc52b8a369fc8fb7ad9a02a95532185216d2594f80a628cc957b8d4ea2e443a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ff80f18f4a9f9ea26e9cd5dc687ed6df90cf58420baba00b1bad11847329f5a8
MD5 5daf6cf82e3d750e23de55760949929e
BLAKE2b-256 d0a0bf3dceff1b7063944a325ccbf627000ada71fcb114ce0d2d3b26300b4cba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 00601f4d46193b5ba1c8b1ee4113342e4ed2a5187e31cbe86a84c1454e4ca41f
MD5 158c4279f717ee6d94eedbd00a62dab4
BLAKE2b-256 9c30ad5d65f13cbbf274f07879b74fc4738e0ee26653bdea7a078f5e31111443

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d915baae1a4180a7485cb99309e947d462413698ee9c3452ec1c97e53842cadf
MD5 18aacee3b7a35b14268135658f6fe3a6
BLAKE2b-256 a9557e5f886eb0126eb02be43521074df5e92fcc5e5123c20cb3e1e3977f9b2e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 684077aec6939246f76cfdcb53cd67da1659f861707255d1fcab0a0ef1642478
MD5 3ba24ecb5c7188b22283bcded8f573d0
BLAKE2b-256 007e2e9241abbac70009f6512d812b3614ed865311adaaae824ff6950f200d3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5a9f547cd339f6cbc1d9f830caf3d2cb0b3ad48de3891a9dfd2df5e11b5ae9be
MD5 1bb601d45d32a84d60c84ae3ab2b6bd6
BLAKE2b-256 855eb0bc7343dfcddf4e1fb0e0445205a53e7f8bc12a73196b837d3529557807

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f138ad2a5ed4376488561fa9f723f47d8c0910fd69f3c77aa92aa3f459cfa7f5
MD5 ee1130bde3e2f1f022e19b78ca5494c4
BLAKE2b-256 47d6a8d4c566f51390fa0aa4008153935feab39c8887b55f10c0fb001dd903d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6cda11cb2c0b5beedb242224c9d606256ad857d9826855c32474786e7c47d7cc
MD5 e77bebdc06c242a58b6117627ba01d0f
BLAKE2b-256 44105c9a447cc1b21ad94bd0b1fb084d913fd26a9b9e19108bab4430b7d4c08b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 e92ad6e27cc35838b65ce97aafd0651be89525bf56b9411530b3f04afe4d1f04
MD5 33dabac53495141a898c512e0eb668b6
BLAKE2b-256 6b94bae774cc2acb1bfe9324e15e22f9e14c88e559bbbf6f163591d40b3dcc58

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d375cb754987c8b69a79d931e75bd55546a56bccf005cda70fd7e21158fd9d5c
MD5 4b23bb195d9117de2bb951b735aa66a0
BLAKE2b-256 c57a24340b392f84df22c4b088e37a7f65dd702f6ba010a0503a45f08ac79dd7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e60ae148c19a660005b1da8448d59d55673612ed1bfe852a407f63b22f3e1073
MD5 aeea401d90ccd6afd9790a189b63918d
BLAKE2b-256 a10d17d60c9978c45c1a1c2134f70e90fcd80e4ebe46ba890f24759751734d0f

See more details on using hashes here.

Supported by

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