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

Uploaded Source

Built Distributions

aioesphomeapi-25.3.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.3.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.3.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.3.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.3.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.3.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.3.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.3.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.3.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.3.0.tar.gz.

File metadata

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

File hashes

Hashes for aioesphomeapi-25.3.0.tar.gz
Algorithm Hash digest
SHA256 4b42d4b16704bd33fd319eeb937cd96e82d27b40f2db1ee924b667be6cfc1591
MD5 e344103f34c80550f4512d852b17ac4a
BLAKE2b-256 76f54ae9e7e514f08e9ceead2e9e9eec044a02cb2660a087b99ad47ca841a394

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bb8962575bfe69a6ddde50d450348f41b7afc91c0c91202109768411ac6fcde7
MD5 2c656a248fad50402302d2f5cb8a207a
BLAKE2b-256 225dc6f309bcefd2aeeb708c4df1a988ab29e9a89fa1926fcce7f7275ba439a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b97da0ffc1352c3db99367fa34fb6423cf022dfa8a7068c206e480ce788c1899
MD5 e4622a1c896691166a8ef21677038a78
BLAKE2b-256 3330c9f46e16f94e7a9cef07ce8de58dab9d94bf6f09193efa442297e1d70833

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ae666adc7eb91b6c5d338ab8746fbbd9e781c7725f35b7597dcaefbf109aff2f
MD5 c47cb197311faa56f7ae21ce3cda9209
BLAKE2b-256 28f257af960b5e3df5bd1ecafa977120b96a619d33ec02184c2104a75549a818

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 01f251fe68149537a116343b4da798a2fb733e5a3bea486ede77cce8cc33d827
MD5 035013d55a92314d404bac740108f723
BLAKE2b-256 c733a246dd9d6a816b8a102613d65e45b7c7bafd0ccfa6c933aad57762ef2196

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a2dcbc31f919cfa2d1b7b50799672e78a2d486d9fffe9495aa56af87d43d5c16
MD5 e7bf23f8772669ef078718b94a49622c
BLAKE2b-256 b1d9ea9f174c373daf5fcdd5bd84a768a5a3bd614db66b608d2eec49251845f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 abb08f25029f3b963a9c7ad0b9309c0f3ab96481f595633fcdbfeb1d84bd34bc
MD5 0ac522a9f1e6bb4ab90bd73d869e9f54
BLAKE2b-256 4dde22e4ed0e913f05884b5008c7fb6ac82c109f26ed0e86e1735c97778d8c4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 305f167958bb44a4b64da6438bd4c3be485ea9fda2eab6c26aedd8ca93b1f4e4
MD5 0ae482b4f54638443980237c7197ca54
BLAKE2b-256 ef52e562f531b8ea62404e2ae698b06646e8f9fc0f7f92899a6b5e3d08e4cf80

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f1f5f48877c5dbf6b7ac7d6f9896921baf8260ea7f1312e15a2cf119f0407020
MD5 dc5176085131c4a8930ea8c685733fd3
BLAKE2b-256 b49fce380801128ba927a608518bdfdd54d4df32edfc701b11d852e196a3c95c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 7550cb0588af69a17585199bed56beb1e8ae977ab72058368e18cb1bfc36d4b4
MD5 4853baed45a13d483879599f2140b4ff
BLAKE2b-256 d9003f8aa55d6566bb2c665618894f0ae827906cdcc10a71a0ae9222eb1c3331

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