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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.10-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.10-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.0 MB view details)

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

aioesphomeapi-18.0.10-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.10-cp39-cp39-musllinux_1_1_i686.whl (2.0 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.10-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.10-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.0 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.10.tar.gz.

File metadata

  • Download URL: aioesphomeapi-18.0.10.tar.gz
  • Upload date:
  • Size: 72.1 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.10.tar.gz
Algorithm Hash digest
SHA256 970ea1f5ea2d1da135273e7fcc10772294c755ffce5af0670d7f4fd0564c13c7
MD5 9c74029299431f2e129ae543510957ab
BLAKE2b-256 818583f2f8c03b48edcc161b010f667ccd56e86125a51b25553d6d2b9048ac90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d8b4ca0d610d0579bfb5fcdb0ab1955729b679dc3a790768bf195e243f7fbe7a
MD5 e1defcf51bce3deec3dfaabc1b535939
BLAKE2b-256 ddc8442ba79cd2d7e9de270873ff92e19553c8041cb176281e98d6eb9a35a78d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 538712720f92646f42a3d9790ad403aade5f15ebd7885f576707f69bc4d8092b
MD5 f366a838425353f104df36bc1a5ebd21
BLAKE2b-256 f716f74ed106bfb56b3cdd54f3a6aec1b1aee4f85e0d0a7cc2170a6af1ea4094

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 481e9d1f173bfe77bb79b50bfaa48a8a8e6998f0e625011890b6083afdab1ba1
MD5 3dd9d05c03f2fb95b8f633814b76318e
BLAKE2b-256 64b4d6ba4050845b53080c1f644d49f28e9b30ed09aa0b91f34c96b0a45450c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 5de254a7d9d95df6ce9a00bf8a9ef16b56c178dc5f6b15683786c0d40384851f
MD5 7d3bc5c316017845155bfe1851a7ab9f
BLAKE2b-256 c3044f30058d36dd099a90a81969bc24fb46bd77b8fd636985c423b776e3c7d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1cc07403210fb40fc64fd0e95d115cd35d4769e3cabb6cf07bc9d8f960d083a8
MD5 df2d85693ed88a683c840b2f5b2887e0
BLAKE2b-256 9f8482a6f19945f29e25bdecac3c629d263394493539df0e8969fc571ebea2fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 9ec9450c319b19c40ea5c1a070e171f88a174f7cbdc0bf95e400c02d664c1a40
MD5 0bfb7f9ed0ac97b4f2d086253a3924c8
BLAKE2b-256 e480023804fb5c210f7e5f5e7554a456c1351da54f3189563cc737d18e0e830e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f90a0f99bafcebe5cb9d83c5f37d1ed30d795b3e1525833272c9d3bd81f2f0d2
MD5 cf350239ef496155aa6468130806f5e6
BLAKE2b-256 2c3ad79f8dfbbdc56fd14521a60761791917d88b2c0349aa80c32c9f71c16222

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 685bfceab9f3e83c006fa12395850d7197e93bfc1609812a41e11346465838c0
MD5 2410be60ba00d6479849a59f8b49e169
BLAKE2b-256 fd57899ca6dc916732915f45d4a25fbcb82161cb8ffff74f1b2a5c59232cd641

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 314222a151345af0c9dfe290133aa8e46d0736691b523dc5b69234dca9b32c06
MD5 dc354fd8ac33ae28e63f98a8016616d9
BLAKE2b-256 64b1d7d2e5bdb0da48f8a23c6f211919ae3c81171d9103b6ab90feb17b8d278c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 a8aebc5c89901ba201e89c6308b83291bd13de1b101e69a3359ecbac33d914eb
MD5 625ebc539cc4dc4534e4a125498c087a
BLAKE2b-256 e196b91f03d91728969817c1177266bab7cadf939eb2e60d606f876b31dc4456

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4626a10a8eadf6c58d418a001a735c3a9e08d0c4a917b6d8708a3c225bdb236f
MD5 4d4c8685b1c5098381ae34e636801998
BLAKE2b-256 0952511d7ff011ad6baf036699bc512c26900c5799d521c166c0a8088cdb22a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 34d3da24fa8260ba8a3d32a76dfc66e8a2f3070770cafe5135e922a6bf742b1a
MD5 d5953aa48d87b7d296475f622d3e0c12
BLAKE2b-256 cd356a95ea4a78f72d339ce337ce3b0c838d65f78c12dd39a7550a0d39f6f212

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ef488fa8269862591b7e01afb86ae2f54694a78ece1da06d60c848724911a356
MD5 f988ad6f729a7dab6e7ec59c062d06c0
BLAKE2b-256 3ca7e34785911ff1c180a3bcd4b21d0420b51c679f204d67443ccfb5174e0810

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 7ece35df6427360ad50b49da70fb59031b310601983773334f33a22c57707300
MD5 43072feea82944861a97ed20c6f47561
BLAKE2b-256 1428788cab8bee5bc151e44f25d31ee263052253deb9464c23b74983f69ebbc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1ff53652d21abb9a725ab124ee4a63216076eb97a423e0efd7b739d85aaab22a
MD5 a6623e0a2b3c70daa0faa65e48799062
BLAKE2b-256 2efddcfe9f4b2e5be02756d6fcd09b342e66274ada4460a4877effd0692d2748

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.10-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 9562d411182a38fd86bdac4742b5af1f4b241a827d0373b65dd08bc3246f628c
MD5 475fbf5a7d731e4de4bb7f054952608c
BLAKE2b-256 dedb030685c1534feaeb60577f85df7ea40a5bd083c422c1c3e5623c02f3cc05

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