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

Uploaded Source

Built Distributions

aioesphomeapi-25.2.1-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.2.1-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.2.1-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.2.1-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.2.1-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.2.1-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.2.1-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.2.1-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.2.1-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.2.1.tar.gz.

File metadata

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

File hashes

Hashes for aioesphomeapi-25.2.1.tar.gz
Algorithm Hash digest
SHA256 e359f3c9ce2f2564a8efa65207caf8145d58be23ee089537814ad9231ab91ee6
MD5 c49dfcac84007dec9cc2983f2c9ea1f2
BLAKE2b-256 bf1c784773911922e7f72ac9cab4cac1ed17bf2e29934250156d99611a24f50a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5d64c24044b256939afc43420c5c0e9083868ce44c2582c4c4dda46ddf596cad
MD5 9da12c9dfdcdc6d305da8e95dc612aea
BLAKE2b-256 fd3cb6b59b8caa15eb963383835f125c48850eee7488a22ae29747af0440f67d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a12093dbf56a2c1f74475d4fabb93442c0cc507ef91f9fafd4c0f3be29a1ad97
MD5 63a93a565b6cd469770619fe73ddfb1b
BLAKE2b-256 8e0c12d11772a77033ae54f69fd9fffbe7db72f4089258c2e3f0980d81b9b7f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.2.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 591a03400371673c44281401ce6f803d39837c2dacb87e094a838927734cca53
MD5 65af4ea353cf071583e156370744d19a
BLAKE2b-256 9065e901f70638bd2197774a6dd8d1e4bf750cfdf85a000516c291b85345aa66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 db803a91ab7464e60eed384eeec44a888af18f80a0bd6fabcc0ba1950130288f
MD5 132f26e8929ba008e48a235301ded75f
BLAKE2b-256 4851ea92665900720c817a7b32cbba8dfff1799f141b159db324711a8279060b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e4435532139507a662faea9a6d7fcc3141b2365f584369ddff4af14bd3ee18e1
MD5 ce1685b1a64806700281b46f263c1ab9
BLAKE2b-256 29232e48d4343458a9a5219f4cfe66012be2743005f0edbce5160a24c5a63749

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.2.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4d7d594fc4ad3661c832827f4b9093ed79abe497d3b88ef37a3d7c2d74c7df90
MD5 1bbab8b8ec646937d19467e30207f037
BLAKE2b-256 bb407676ddff5d0843f8c9f5244736439f4c9e4a2870933df8fec4bbe7deb3ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 86fda8a00baa1bba2120e22ccb1f4c63f236793b9c91e58bb4668a74a4cbdd27
MD5 4a62137dff0c0d02a571832da028d366
BLAKE2b-256 6ebb4e5824975f9802eebb1ad97c918cff9f557871bc02c1d5a5ff6b8b6224a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fc629b32f7d8416bb03d50d6a4a8ea906cb89927f043e05aaabf0a6184a4a0f9
MD5 43a321e03cc81bcfef978957c31f8180
BLAKE2b-256 f02da0489cd539dd4b401bf7cadf7add4e83a116757b54accc67f287d1200e80

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.2.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b18331378c8206d467b8dd0411c2c49aba162879927d59dca0f02ea9977d9867
MD5 ad9a9915b5fb745aee29d22118158b7c
BLAKE2b-256 89f09083185a902c9be538678ab7b3af0c406d3af477804adab81e2a8f26f90e

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