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

Uploaded Source

Built Distributions

aioesphomeapi-25.3.2-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-25.3.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

aioesphomeapi-25.3.2-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-25.3.2-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-25.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

aioesphomeapi-25.3.2-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-25.3.2-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-25.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

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

File metadata

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

File hashes

Hashes for aioesphomeapi-25.3.2.tar.gz
Algorithm Hash digest
SHA256 8d991b08d54cc09cfef44d06207fbf990dbcc3f8d2d2bb902e8fb008241f365b
MD5 ce2a0ffbaa2bfdff5c268c7891f2da3b
BLAKE2b-256 558a03bd868130293b0ffbc9fb6bd949da52486b1d1e1d4ccf7a605e86a33302

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b08677ae1fad52db0a98356fa16dafb6415a71e6aa00f7f8981fcd6a3d1306d
MD5 44a435dd55831e6f617ffa0532d2bd31
BLAKE2b-256 1b112a523c9dade6d30f9671314a5226ae26191feaa8660ebfb4bb90df79c695

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 db187a02c8dfd4530b5532c85aa03fe853e8d744fea39e700c68947df8d4d792
MD5 768f43b0f904ed0eccb5e6fac186a428
BLAKE2b-256 1f29a57962efadc5d3bbef01d21142ba226710d04defd05bd2912e22ca3ec93f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 39d58b2d2f5a488c4a9542c73e9addf5ba440d0191b8731f04d735576b3641ea
MD5 ede37f819ef2aeaa2b961c852ea10bdc
BLAKE2b-256 18fba32bb1366ac789d020afbc989b2b9f52cc73c77548ec839b2b9f5acab974

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a9750214dd7937785c3573ceb069f003eccfe84916fe400a42103edd82a70eb1
MD5 a17f7c570c197c7e81641e9e18642c7e
BLAKE2b-256 ba15f9cf914f5291e89189e4a00b4d9d322fffbcdc9b75f256df8a7fc68c40b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6c92f5cf348dcdb61a804b8d9ade203f37d81bb1dfc80253cdba86fd85f3adc3
MD5 5b617f0cc401a6d9556ea2db7411dc4c
BLAKE2b-256 59dbaeb451bfdb537ab4a50c0370e05dbb9691288ceabfcb651436aedc0ff30b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b316c2f09e041a41daf7bd1805efd963d42bdbc73088868d2c677ae3af16c4ec
MD5 05e60cfe3469d5e9ae8544a6a9cbfedd
BLAKE2b-256 4552ecd9d56eada48c2cbdcc4e14ddcbe8fdeadc736e4ac2e804881c35c50acc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9975f5cfbdde2c66b21ecbea765a24f461dac82a71fee48ebe4fc57b31c535f7
MD5 822f789fb505cea76241b8def407227d
BLAKE2b-256 3ce00b08fa1ad446d35a22d5bb05f869ac106ddea1b0bd91bb42bafe9f0ad3a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3d37ced54cb49080f49b4e7547ccb466a5022b7c4701350b028eef744c5e1ff2
MD5 37be43947cf87566410e9df2e3290eee
BLAKE2b-256 51a7dd7fbedfe611d89d9750a734425aceb99a68b935d6231adf2335a29eebaa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-25.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e8fe0d08e711a7f06168fca939408079e7d8adca6cfcdfeca40c07d918dac95e
MD5 31f8c7619bfa585320f52cb16e61d661
BLAKE2b-256 e35440bd2bb6dba291b713fa9bb6aabe172089a4a03d79eb887d77026eda9704

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