Skip to main content

Python API for interacting with ESPHome devices.

Project description

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

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

Uploaded Source

Built Distributions

aioesphomeapi-18.3.0-cp312-cp312-musllinux_1_1_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.3.0-cp312-cp312-musllinux_1_1_i686.whl (2.1 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

aioesphomeapi-18.3.0-cp312-cp312-musllinux_1_1_aarch64.whl (2.2 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ ARM64

aioesphomeapi-18.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

aioesphomeapi-18.3.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.1 MB view details)

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

aioesphomeapi-18.3.0-cp311-cp311-musllinux_1_1_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.3.0-cp311-cp311-musllinux_1_1_i686.whl (2.1 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

aioesphomeapi-18.3.0-cp311-cp311-musllinux_1_1_aarch64.whl (2.2 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

aioesphomeapi-18.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

aioesphomeapi-18.3.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.1 MB view details)

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

File details

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

File metadata

  • Download URL: aioesphomeapi-18.3.0.tar.gz
  • Upload date:
  • Size: 77.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for aioesphomeapi-18.3.0.tar.gz
Algorithm Hash digest
SHA256 c15d21381e76aecc4f290b883a5ab1722a4e92d0e3c2709987841cfd8babba40
MD5 6b03c1be9efdba9375ba006e70b60eee
BLAKE2b-256 0056dafc945169f80e4756f1e6b773e12f5416c4293170f6a129d533aef7754b

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.3.0-cp312-cp312-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.3.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d30968904da92f1b84a26e3421409965da5bbb31d542f0073661a7a1948acb01
MD5 398bdf122af5a89e04537ece57e00044
BLAKE2b-256 73e673e5c1d5b5dc3b58428c6dcbfa83f2d1b0813ee771c2d13dd04591ef0125

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.3.0-cp312-cp312-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.3.0-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 ba224af65274cff3d55e02d416e724bd65104474a16205c9353a00d27446b438
MD5 2a25652367de30eaaf7a55d4a687a0ee
BLAKE2b-256 d26a1767f6591ffd74792f7c3e13152cd54033cc0415f290aa6ad99b1f365ae2

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.3.0-cp312-cp312-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.3.0-cp312-cp312-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 c2af650c3669761d5ad41a4f56b4967f21d21dfcb177b84d673defe2d33807e7
MD5 75f1bd8484801412401313cc50a2896d
BLAKE2b-256 d4337eeab7d388f8ac7e6ebcdb37623c7916dac69ed27c7c8a2c189fe485006c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8026de36a4094dd7b2634e111c8a525e3119517b2b504fa020ce384d51301364
MD5 427e2bc603ca79fd4d569d4dd252668d
BLAKE2b-256 1837cc4e9301c6976a4e4c9b2b422fc2c2a9c8406d94e74fb7e48577bb991be4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6591702a8df00886a2e0a0df5b2bf6db9636ea867247a102f2c9b0a9769a18f4
MD5 fe94a7fe023027c6018788fac32ffa8f
BLAKE2b-256 563afe21daae70f06441899cb859bcbb9de553284c1d4ce69a6d82727121eed5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.3.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 3e566ab3a6dd53c050f29ea73f88b68a8e5541e69101b3e810d20f3d3709e769
MD5 e822b1d91411d3ce5733292c4b7c967c
BLAKE2b-256 1d91faa40f5e7da31aca77dba3fd179676657c1f53644f45cc9f0aaf08fb9ea7

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.3.0-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.3.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 08194235a5e73a864c909ca4dabb6418234ca83b5eee471aabc4589c29c1eb0b
MD5 3f67bb88af5e12247ef2bb1ce3d182c5
BLAKE2b-256 5a11bec8f522d3052a43220c50a453b0319e9fb1829df17f96b3aec1cec5052e

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.3.0-cp311-cp311-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.3.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 35b83305b6394657fb39eb2c16f9339046fdb35d8f1c335797f19aa24458ff54
MD5 8451ce4f7cc7fb5b5b2b5c502fd0a091
BLAKE2b-256 9a7ec20caf56237d13aa19e289451f46d8946c3de9685bb8accd4d56824d8c08

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.3.0-cp311-cp311-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.3.0-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 a8759749d414a219f856caae3b60bd86d6f84ab624aa108ca84899f279a99bef
MD5 f676dfd3b3f38d263d3c600524409ac8
BLAKE2b-256 94bf393412ff957f7170b4f8baec67473094bb5d0db6a94eec05f52fd9bd68d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 80459a78118ccf42ebaa8541d6a0f0dfade6e1f02ecf69dad1f8ea15e39da901
MD5 0e27f6154d87565b701c3df21c8628ae
BLAKE2b-256 d880feb926073602ca6044496946a6c35e10dfec08e46926b4020f9e01d71ca3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4f9522f07f33edaf48dc796cf27703d96709766f43e91bb739f006375433cdb2
MD5 7c4515779a5fed6c2d382c22ea87fe55
BLAKE2b-256 9452dc2ec065a8b82004612829c3f455197eea1498b71b5a2f6c1eebb681da98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.3.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 444832f60c2b0af560e579ca83985f1e9e85e333165e489d0a544de3e8b59852
MD5 e969b23f24885f7dad38e48cc76af4db
BLAKE2b-256 fb62df859f1accf461ecd82e408c7ca59f477fcc148118bb815e98ec372ff65c

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