Skip to main content

Python API for interacting with ESPHome devices.

Project description

https://github.com/esphome/aioesphomeapi/workflows/CI/badge.svg https://img.shields.io/pypi/v/aioesphomeapi.svg https://codecov.io/gh/esphome/aioesphomeapi/branch/main/graph/badge.svg

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

A cli tool is also available for watching logs:

aioesphomeapi-logs --help

A cli tool is also available to discover devices:

aioesphomeapi-discover

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

Uploaded Source

Built Distributions

aioesphomeapi-25.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

aioesphomeapi-25.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

aioesphomeapi-25.1.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.2 MB view details)

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

aioesphomeapi-25.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

aioesphomeapi-25.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

aioesphomeapi-25.1.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.2 MB view details)

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

aioesphomeapi-25.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

aioesphomeapi-25.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

aioesphomeapi-25.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.2 MB view details)

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

File details

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

File metadata

  • Download URL: aioesphomeapi-25.1.0.tar.gz
  • Upload date:
  • Size: 101.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for aioesphomeapi-25.1.0.tar.gz
Algorithm Hash digest
SHA256 153219c68f7750ee40922412a9759b1873637fb5d6bce17f410c6db8701d53d6
MD5 ddd4b8ef164a749eda20cf69d00514c9
BLAKE2b-256 246e937a38bbda90864966d5a845b7439ed48d873cb331a80f4c0f3cf6d7301c

See more details on using hashes here.

File details

Details for the file aioesphomeapi-25.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-25.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6a0c3ea74b1ab0b85adced34993b5f2195edb0853fb83f65edab8db2a9a6036d
MD5 5f1870400816cfb48c6d8148698b1d10
BLAKE2b-256 0f70966335f9a76853411e4ba4e4f6dde1320c733c0245d1647838675f8424ec

See more details on using hashes here.

File details

Details for the file aioesphomeapi-25.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-25.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8a321eadc230245197697692bc0c68a9d3d8506738639a13c021261dcc0f42fd
MD5 2ffe2e723e55532530a35cb6556e1b1e
BLAKE2b-256 b6acd38e18fe8478529d2d7ed1ba60d85c9971e6de7a17b6ba366ad8b5a50fe1

See more details on using hashes here.

File details

Details for the file aioesphomeapi-25.1.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-25.1.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 af43bef65536b3be79b0f09b4808085120fbc4d4bec675e9dc13f355492ddb15
MD5 b9ba469c40effef9890fad6d99a3b45d
BLAKE2b-256 b2fe3f33cc2ae31d74df0e0b26885b3740dcca81d6cb1e25395051364939996c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9addad036e06d0e09c736847c0ac2dfdef08a442a7bea8e22fed49f4edabe928
MD5 5c22a146c696ca3a9aed53bd19013106
BLAKE2b-256 e364b2218a44b151d7b5c2586af5fb4761b4744e70827847eafb90369743d41e

See more details on using hashes here.

File details

Details for the file aioesphomeapi-25.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-25.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f939a6e8733e8b1e4fd8dc60dad28c9f4bac9de237733f494c0b08c5822cc109
MD5 4446917674e4bc595e4178da18ac1cca
BLAKE2b-256 761537e4c2692ab9bd3a20b7363c3ba9ea90764aabe84f54517d1ba20fdc9837

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.1.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e9d6743b9d096fb6b1b5f55875136a4c523fca60ff59cbc14894ad96efa3c147
MD5 d6dd3d9c7d186ac433c96cba88b6fe7a
BLAKE2b-256 545ab0d257353131426c448334a219eeba341d7df4645bbbaaac0f15026e79c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6754fce12d590012fe334c0327d24fc0726da1e64569a91794efa73ca7c582c1
MD5 5331209d4e8dca73766500ab0e5eb735
BLAKE2b-256 e845210467bed61134136d31b96b727f4e576d3dc9c8c8d0f1eb1f6af6bb9a16

See more details on using hashes here.

File details

Details for the file aioesphomeapi-25.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-25.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4da03e3bb1f0c212456bffbc4f114cac16488339fbe554e419dd5c5505097101
MD5 108cee5a4368906cea3dfa3c3683e3a0
BLAKE2b-256 05c8fce7a6f1aabc4f6253ce9fa2f0e90d185ce25298a99fbcdc9ca73162d005

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 eb59664e8c76952aceb79cb5a7790a50aaa21ee688a7b218657e0cad8ca707b0
MD5 a14c5ddabf61e28293901ddd97b4d4e3
BLAKE2b-256 d6ca800dff21363d58044ac58a95a13c7031be26e47eab51cfbee928f058befe

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