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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-18.1.0-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.1.0-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.1.0.tar.gz.

File metadata

  • Download URL: aioesphomeapi-18.1.0.tar.gz
  • Upload date:
  • Size: 74.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.1.0.tar.gz
Algorithm Hash digest
SHA256 57ddcd0963deb3e680055607702e4fd9d11bdec701ca482c9bd96630e547569c
MD5 1ac77655d231309a0f8ac3c84ecdc00d
BLAKE2b-256 e27d7bfef86b88bb58d7be66a681401a2e959de1adeede487405908727d641c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 58689c011ead0c92a08455233fed8501449c171458f3140346fb12aa96801474
MD5 ad4f5d0ceff601aafefe4886786747c4
BLAKE2b-256 618f7c1bbe8a49cfca214772a8f929e12bd08fc4f2e6f65feace6fd9477b20d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 e8fffa4cf9a40491b1dc5ea3d6d054c43c3536c9afcf402bf800d5f8498416ec
MD5 2a196438b1824cfb5137c2cc9d724d58
BLAKE2b-256 84d7ce20ab9f2867fa1782591cf1620eae7b622b5ab24921fa08b65cdaf4838a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ce1549fff1839048af529aab78d56f9c079ced914efd0c778d8a836ac65b6a10
MD5 5d9d9a3c0a9d4c941793aef0249d6db7
BLAKE2b-256 e05ba056b932df59b5421b31fb839160c816272092d1c02ea22918ea5b00b714

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 56ae4acfb795fa9a85f11523e8a47868b73486541af14fba27d136b14032c3d8
MD5 c1b84521a95802455e783504d248ac37
BLAKE2b-256 84608fb13dc7cb59d38d2608d88033f1d7c7ed46967050e09a24780eb78b9369

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 06b2a186de9291dd7270cdec5e0ea03be9f6f8b790c47c6a3fc547662bad505f
MD5 910c11118a845cf6f48f1d050ef29569
BLAKE2b-256 36a9c934bc174f7f69e37e62474ab8dda655dcb6fee5be78463aea5d99468a8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 be9661ff368e7c93f56bf3ce8c494b976c5e373e70b9da6feb3c863f0dac04c6
MD5 b881d17b43bd0b19c969d55cb3d53ec0
BLAKE2b-256 34475816064bdfb081ddeb5df015a84deae524d2a26c09e12b76fea07aad70b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d05f9d63a03a7821691fcbf6200d5198065185c55ae7c2813a99e754b9bbc06a
MD5 7315fa9ea065eccd13748bd61d3daeaa
BLAKE2b-256 340105253d574cfbf384c92975a3c9fa93e6b1911c92934c6813218180191dce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 2c5461a3e12ac2523914bc70d95f3e68c86a61d052a4bf786f71611fbb40822f
MD5 e8fd140b5aeb96fbb250b10dea3ff1cf
BLAKE2b-256 708a08b5809d5a77c73e981a65375161404bbdea7b8b0328b5f79d7f7bb2adcd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 8813a86c8172a8ce87aafecb243c5e00c9510c82a99224ed8ae607fdbb9c5c6a
MD5 d37de99d2424a6383683ba654a9ffc24
BLAKE2b-256 6c6be1368b245842def9ffa87b469bc43dfac51f716559541e691e547cc6393e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 393c12f6ee8443dde5dd61c16d2730ff15097c15a0d0e09e5a916ae643871d14
MD5 2a3f30484632014721c0dd02683d7d8d
BLAKE2b-256 21f6bb97d5416acccb0df386e7eb3479bb4c14952c1d68b37bdc794d0e82317a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c31854012b88406e94300670e1f171e1458c41618b38e7c2fc169191064c0ddb
MD5 f3dd1ca107d0b3a458387591926a7ddb
BLAKE2b-256 c1c2d855090ac024f559f39611da68282fe7e74966d2a22c4195c2cde845c4e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 35593e9083c9d1cdd35d5b1cb6749f512e11303b6ac3c4b904e2f3055cb926ca
MD5 425cf41c2123a41ab906a0ee08931ba1
BLAKE2b-256 00983d11ceb23fa7ee33f2746bd0c77833a8e748625c7afb5e2b8d82fedbaada

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 74b53f863f5365ae41fc24d99935f9ead66e20831470ee6ecbe62b7cd291eb54
MD5 145e9f1e92845637dcec0fabeb0fedc9
BLAKE2b-256 462e00ca8d9713117cae66a90625342f6f50e7b3e73a4e1b4ca911eaae0b2875

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 975c29ffde2b236b1f09797177dfc105558a5178ba5c9046085ba5456ffc32ff
MD5 1337d04970cca7f34fa4df6dc0d05a79
BLAKE2b-256 09c1b7723f41bb0024024833c0d794e0a8b2f9b38c5c6f81ff4534143e84259a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 72be0ab65b4a5d9a95d846a7b3c4c2d07a1b8f1438a22d769d3c29de885a0245
MD5 5861134392a5a6a3cc5157d59c77ecac
BLAKE2b-256 bf1c898c4bb12d6e3e079dcd609df14fc95e604f05c291b91db885c9e0af8067

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.1.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 8be67204a121eb9ba2b6bb64098db4c15cb27b94a4c1b648d18d82a4e6127ebf
MD5 4fbe925d3f5da9c8d57ebfc35f222204
BLAKE2b-256 3ad0d34664107ab9e6b31d4dc64610f50fd0c6612a2f7dc577e84c40e2e057c2

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