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

Uploaded Source

Built Distributions

aioesphomeapi-26.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

aioesphomeapi-26.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

aioesphomeapi-26.0.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.3 MB view details)

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

aioesphomeapi-26.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

aioesphomeapi-26.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

aioesphomeapi-26.0.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.3 MB view details)

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

aioesphomeapi-26.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

aioesphomeapi-26.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

aioesphomeapi-26.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.3 MB view details)

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

File details

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

File metadata

  • Download URL: aioesphomeapi-26.0.0.tar.gz
  • Upload date:
  • Size: 105.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for aioesphomeapi-26.0.0.tar.gz
Algorithm Hash digest
SHA256 3987f8f82ddee5249ad303e1925349ff1fa0d11e253930c0b92798ac6af319b2
MD5 f79635da30bef770159e749a048abfd6
BLAKE2b-256 b0ff80028174f41ce0af5193c0ba521fe2685923a8096f35e37f91029288a20b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-26.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7640bf57bded3f033577432bb684a453aeda1c4d4c6d21c41302b7f46b5509c2
MD5 d9061cda03ae98aee6d36944b9dd757b
BLAKE2b-256 7c7729d83fa676202ce2884f78a4aefd1a9bc8e7272f902b382c1a0c8f3d3372

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-26.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7122ec6fd59418ccc504176a44a4f3087b09153f8ea456548d6d3640f49cb25e
MD5 d56ca258573c73af43f88f142ae26734
BLAKE2b-256 f963c890c95bfa45b18d78f7cdebcce05f2447819151b0afa9a8b241f94ca275

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-26.0.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4d7451c38ccf3baa3cdbbe01c0b10984b97a6ac53d984065be7c36a3be86a48b
MD5 835570eaa939c64b0013e5b080e2fc95
BLAKE2b-256 2e251619193c21413e30ac2f9bd3eef88c59f824cd3805b5b0d417b5bd1b55ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-26.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d785fdcde6326d3c98cadcc2974ad13294ae87159ee93371c126c44af700ee35
MD5 3c6cb3f39250a124837498f3eda31aaa
BLAKE2b-256 e45d62e11c89399ed06f73d450a56adf974d4b1966730edd680bfba322f7e264

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-26.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b93f72af1cf5ac1b32b8a903ef5b928da10bc38043d4235710f9d1f206118e6d
MD5 8d761a2a1fcdb0c66b2fa70c2e14eda8
BLAKE2b-256 2680ad630fddb1ef0e7984db4148b6152d15d531f4435bc46ef7f0775a78177f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-26.0.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 fec9d7b474c0237cf8ec894630b4c942f31523264f7f9eb2acf53b486612f38d
MD5 308f8c3e513daec6cea53651b11ccc00
BLAKE2b-256 2f6b17e76755b28883c3cd167ad88ac8ea21f4ef4c03c7791006aaa90c9ece39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-26.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 920a6664fa343310280d12603a80f635a5dab883d5d942d41f58a3e56e7caf3c
MD5 9058f94364822746bad877dfa6894579
BLAKE2b-256 16900b6c9d6e359066d2896782c69ef5321e1aca9bcf04afe8296627262f152d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-26.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f2c3155b7e8675f68f27295ed47dc576454f5fccef1d28215854d59bd5ea5bdf
MD5 4d6fd38793a8eb24335f4684f334188e
BLAKE2b-256 c43a134f3fffc18cca7d92f6e4a81d3dd61c8aa7913445b46ecbb0710bd16fb6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-26.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4535d5cdd04b9692ed3ac07557f2d03b90c0ee08db90a35d84da0dbdb7696261
MD5 70f1e09a11dad7ed7f209b6c7b6f2c82
BLAKE2b-256 5ba106a34f3f6e529dcd4403d3898b7588779fa1c4e2bd9c8ab2d52119c3deaf

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