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

Uploaded Source

Built Distributions

aioesphomeapi-18.0.1-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.1-cp312-cp312-musllinux_1_1_i686.whl (2.6 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.1-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.1-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.1-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.1-cp311-cp311-musllinux_1_1_i686.whl (2.6 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.1-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.1-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.1-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.1-cp310-cp310-musllinux_1_1_i686.whl (2.5 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.1-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.1-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.1-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.1-cp39-cp39-musllinux_1_1_i686.whl (2.5 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: aioesphomeapi-18.0.1.tar.gz
  • Upload date:
  • Size: 591.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.1.tar.gz
Algorithm Hash digest
SHA256 0b624dbf03fbff1dfcc672008b2b63f0530ecc2093f0bf69415397841ae63b2a
MD5 8b8c41048ab2b1e2665380d092ad17a3
BLAKE2b-256 24d602aa3be7a14f736736d59a10c861278f78ccef329a79e12d73f744b5af5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 68c92d6e38adcc97a1d31669de4116661541aca600dde0f186a157402f758568
MD5 088c10e9d2c037e09471505fea037e35
BLAKE2b-256 ffe39c5b123ef5676370e19f41383ab8e4436dcfdc8aa83e61a54bc3103c1b77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 0c3f7a2a59e3d7fcbea6a95adbcedbdb0118911bffbb32a09e46f1d736826460
MD5 ea5b645f16bfadf10f4a980438c8999b
BLAKE2b-256 e2de6dc87ac3412f9057ce2a053c7eaea73bc39391d0b4625ca32471e36326c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dd1cdc433fbc5d57e4f7a95a6dc6e9a689f3e404eabe421de35fc9eb7e451b96
MD5 ef25f05cb5603a2ed114df6566014fae
BLAKE2b-256 4790f4b23d4fb0241c6f64e01d9cfcf618920d38cd86d364ed09c91844e5958c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 c25eaa964c9008b739e788f40b2532e54e54af46c2d43498db4a175306519064
MD5 7991ebde50635d04155cedc3196ce7f9
BLAKE2b-256 cb6fca167cb1268e0d0419101e95862cfd4358549917afe59425753dd78ca8bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c3198b61237be4d3a617766533173966daeb892c2b81d01db7ded3ffb420d368
MD5 97ed25e2e459049469ee6a6e71f1b7de
BLAKE2b-256 2f6455cdbb6680be6fd7aaf7117ab3cb79a5249758ae44503544c429f3e201e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 561bff866666c9fcbe602513e5d184062c3f13ea8309ace45024e92bb640a20e
MD5 26daf17f9c81a68c2c7738a6fdacd38b
BLAKE2b-256 c6f2facd4b5b14716432f0abf4ee8e5d57b3c60748bcfddceb246b805701bc8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 295b683fefd2e035db971c1e575af6e68d44c6c2d550a912073ce062d64e1f20
MD5 797db5d42cb57f914b4ff50a4df4b239
BLAKE2b-256 f762e04aed70da1f441c5e0988a326553735596b08de535fa98c125b31e24832

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 6c494860d922be09443810a7e98f275ba5dfc55d6f5024cd44dcfc5a11c6b376
MD5 db3905b06a2486d159bbb08aac8fc300
BLAKE2b-256 03e39a810b70d0e5ccf9d72c65052a66a7b031a1840fe781b77a075f6ed72123

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c9dd85b3605808d38be5931c8201ec10c8c2325afd123cd09758ac5968a607dc
MD5 eeff8a0c29182d1b1c795a56ebe26a3b
BLAKE2b-256 c15d317673331f3a557edff3678f4f5f71ce9f45c1684851ce6b25169669a542

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 629fae7d654130f94e7223116c8dd18f1abbbeb36d28f70304ca3065fe5aa0a8
MD5 ce060f02a5c17ed3318889928df3b9c3
BLAKE2b-256 543be1e4fa3cb0d56b31e4ab55c6c5b9527be6fabfa902bfa3df0e33229af1c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 01683d84663dc13ac1c5e4a4ba584e8a38cfcf3c9467d3dd60ec514afb373b0d
MD5 1c527b2adae280659358ae75266ca062
BLAKE2b-256 7eaff4d9dea95a153a4143aae4e6b762eb7d426e27b3684cc5a25c7aff87907c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e309f66294eadd5d643b17df78f7df022561e236b17e946f8df535da89e796d9
MD5 0ff2e65510f4e8b8daada3f21bc5aaf2
BLAKE2b-256 c2e025f1aad4eb11e354512338c6886204cbfc15b42d3da21bc473d305159b7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 62c1cf545a1c350df4f3a544cf0b59f3dc173d24a941f55a137ccfaba3ec41f8
MD5 aa9246690839fe7cc2a6541c7ec45959
BLAKE2b-256 a43866738a1d6fa9578f42b41d872f89f84cb4a4a81bf10c6feab43dab921a8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 034b79195750dd76e104d81e0c735f37c3b84eebbf15b661ce58fb5819213091
MD5 92a6a005ad3525f0de714fef749effc2
BLAKE2b-256 204e78102e664be549b43d85e431928226257da67aa4ae7ba725effa07a5fde9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c33d29bb32c0c14e4a51853045daff003de89146dbc40d39860631b64a1482aa
MD5 6d241fa8fb66ef38dcb207757825bebe
BLAKE2b-256 b73ae195c0c3b103c5477a68399bd56c76bb6307b72f38a33b667a7a1a76de0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b4b5a9a3434adba52acde825eb29efac78bf406c0e1fd600b27f1e44d7442637
MD5 925c7d1409d8711a782b1648457e0bea
BLAKE2b-256 7d0fca53cc63fff25ff6b0510b1652f77bc5214c2528893566e1d8525138f16f

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