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

Uploaded Source

Built Distributions

aioesphomeapi-27.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-27.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-27.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-27.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-27.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-27.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-27.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-27.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-27.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-27.0.0.tar.gz.

File metadata

  • Download URL: aioesphomeapi-27.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-27.0.0.tar.gz
Algorithm Hash digest
SHA256 940e55f91b54fbfa1aa9cc0add9cd4fc27a92b4188ae9a39c8738ccfd4b591c1
MD5 524c988348b4449d1f0a9c70a5aac763
BLAKE2b-256 ecb8e163036d8b5e982d0b1e0bbc8d683fe0d1f1d82d9de1c4299f15b6c2da3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-27.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 305a90ab8006808c64663f871beddc5b01831c8041985ff9a3a4ff8e38e580dd
MD5 dfafcdc6dd96aac904c87ae6113b0625
BLAKE2b-256 b9361265f9bdbe2f3cdb8f936ff307e9185494a8a3be19e01f01c66b4e15c45c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-27.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b125ba66ff348cf20b2bd41022c0e777850f44cb3e9505661dc55ebb6227faf6
MD5 1445db0842291161ffbe99d956f685da
BLAKE2b-256 24fbad39441f4f9c2b3b4986131c4fd4c8f2f44fc4089f861686980605908eda

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-27.0.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f9b7b59b97342fd3968a00aeef09d1a4afc239e06f736c1278561624f3b50510
MD5 9ae72f140739c72ca991369d9a960ce3
BLAKE2b-256 28251bba3beb3693ef83ea7b107356baa112770ae7eb5a24616a8758da12885e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-27.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 340622559c4e3a99b5ed5b95b613bb95ff247908ae825cd9731826c9030dcbbf
MD5 800ebef151094f3f8f6c9d834d8fcdc1
BLAKE2b-256 5bf5c93ef42e13319961356400967b9bcc7614fec364ac99176303f11802ec85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-27.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cd00ec050960d7f5c06fcbd52999559f8f24355d7853048eced524069553cf3b
MD5 315ecea5860c34a4dac3907d3562b646
BLAKE2b-256 9964664b60057415b1e190ccf681b1634158857010334351d58275c2a9c7c8b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-27.0.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 fd8524c4fc0a3dcb5c1cfb24219400be7e964eb1fc8d2e94aab5f7a05506e55f
MD5 241fc126f7b7aa1eb1b222bf8c84f6cc
BLAKE2b-256 f4773243b8809c76fdc9ed8fc767a96b930dbc6c59be36676c9f310f84b60d9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-27.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f216b149faf96fb690034b81bf227fb0a624860f1813d928a6769530a799ffe9
MD5 4a3fbca06f2c519b1e90651aa9aa0e9c
BLAKE2b-256 729ace80cb44cb4aa389eab275c5221d6d050ddcaa4d25269a91d7b96f196b4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-27.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3e55e01c1cbd01cc1f2b6a9fa61ecd2e14326da81ba2bbaa6a7f551f199e0077
MD5 b1af8f45aaba6b4f7ba95a0eb3a2770a
BLAKE2b-256 64cc5371bae64bb05d968e1035a979f842efcc601f128fc59a2205765f773967

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-27.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 1e7cf16d1c8c682637b7b6c33dc6228f89687c0ee7681f8c49f753888a92e766
MD5 71ffe8ba27c17a42c07bc3176cf5ff45
BLAKE2b-256 34c70ee0584b55d4cb1af9a158e4a405d2e46a798520834527997d785266395d

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