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

Uploaded Source

Built Distributions

aioesphomeapi-18.0.9-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.0.9-cp312-cp312-musllinux_1_1_i686.whl (2.1 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.9-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.0.9-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.0.9-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.0.9-cp311-cp311-musllinux_1_1_i686.whl (2.1 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.9-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.0.9-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

aioesphomeapi-18.0.9-cp310-cp310-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.9-cp310-cp310-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.9-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.9 MB view details)

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

aioesphomeapi-18.0.9-cp39-cp39-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.9-cp39-cp39-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.9-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.9 MB view details)

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

File details

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

File metadata

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

File hashes

Hashes for aioesphomeapi-18.0.9.tar.gz
Algorithm Hash digest
SHA256 ebe306b193c995cf6cd99fd36d568fe8b64162b153c75d04f1fb414b67271acc
MD5 7c0086ab9f748d4d41b078e457f1c9f9
BLAKE2b-256 97c7708d0afc6192e2d935e38ba72ec2c006134bfc28be9c1491c8d837635183

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d452612275563292e75e824dc97bcfeafc4155abbac57ad50848de2ce1b2d10b
MD5 54d1bafd62b45873bd9d3c33f41ab85c
BLAKE2b-256 897a22b27f09f5146e9f09562664a27f680f0c578765bfda68fcade182b849ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 21ec0aa1ec18f3ade7b13bd1029b136fc52e33bcb68fdac865a923b684ec8bb5
MD5 1546f9f2d5f093833b0e3d1245d9cfe5
BLAKE2b-256 0a03c8dcfceee5ed510db100fb46dcc30d6ab05533f4355c11e8011ba5e9366f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9e8cd65d57be589e365d86cce6e14ae8320d16c9adae8706e247a789b924762f
MD5 a3aa9458a1f5010a6f70319bd2252f22
BLAKE2b-256 e2bdbe285e0e7c2f52b75f5e55093576859cd8fcb8641e5b7e419d7c651ebb1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 00b8192716074913fcfe6edd5cefec9c0eb79d5d1ced28d7662f23c9e70b864d
MD5 47d81b5641f9eb44f04784db61f47503
BLAKE2b-256 9cf861ea8a56a01087f4c55f6203636e8463b9487fe6fca4f914936cc23beae7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 23e92aa58bbce69e93d424a399a60ea820f4a11749422a07c961d338deb933ec
MD5 e9747eaf2e4bc069e0cb4a2710937398
BLAKE2b-256 f1c92a3bf4dabac4b2f0d29fa42dd273e01500ddc8d3dc56b67fa8457011cf79

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 4ec4c3d125931097d5a468c7eca906a70490a82d2ee9c4bcaf0f7c637eb5c9d0
MD5 3edf59404c9edb06bf002d8b1d985f7b
BLAKE2b-256 c53e898a5f4a6fcef69243e79a4edc92a2119a6deffd4d4de79e312cd6e886e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e007172a1609898ed99af14ea0c787db35f24fede690a54f8594981a30be4fe5
MD5 8c100dcc0a0b0b85976e5c299093e2a1
BLAKE2b-256 6b672e0dd55c4857c81b9d4b74d9f6652c8d8e6dd5db643491a3f3835d199349

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 492207d7bf20bbc1e6926c45a7c62fc03e1dced528538c703cd3d08f2f307343
MD5 c73a90828d33cde0aee407745cc17a7f
BLAKE2b-256 428b6f8484d0a0eed0e2051f9be35252c0a33af890919294269f2efb68556822

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.0.9-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3ca667e7600aa294dfdd915e855f982d208344d740bc9df127e178d8ec6625c1
MD5 dd5ef90b41ba4a83544b080df5372081
BLAKE2b-256 a0a12855c2326f22bd6ca988e205fabf314cf89c5ec01144f66c37be7dd79ec8

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.0.9-cp310-cp310-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 cc642d9cc083fa5a98b16d46bbe91a994f07924bd21b07ddf25bf723ed9df05d
MD5 d9427d50e0e8fb6150b0577d1b8eaf31
BLAKE2b-256 335a10277615d52b4a722cd419f41e85a872077f9b2d73f35f456a45f840bc2b

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.0.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9d56f04130eb4904863a318f7ceb15a3e2b14f129051ed291423b7256cc32814
MD5 4a07a4f7ee3121be04d9e557dfdadae3
BLAKE2b-256 e878b11805f0a4b76d66953a94ac67e0e6613cb8bd872c47ad5457c51e6ee43f

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.0.9-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 d04d05542e9d74676cefd4a53e6ae32c416891dd1ba3ed2dbd596ebef44d2bd3
MD5 d0aa841aeca4f62799383d156599551c
BLAKE2b-256 89e6b990bccc302fd341983d1c68bb7a97bf52099d620a9085c2f1e341a5348c

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.0.9-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 92d3ec8733e81ee05a01a154889bd0cee578555deeaf3d48ac77601316983a9c
MD5 4ec202729eb7d0875e02fc9b12bb9f23
BLAKE2b-256 4024cb06d1497cc72cbb7fa0ba2037a969e3ef338430abc5436857681061d68d

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.0.9-cp39-cp39-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 a37b2567ff652cfd8c3a65f194e2334e450fd312836d0735abf117a612f40a85
MD5 faeb71bcfc0544cb287696f3832f2619
BLAKE2b-256 e72fdfe56084746256eadce2c4485ed585edbb2e6b96225ae4a935ebd78dedcf

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.0.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 376abd09d710775dc38c0f9bc41dc12767aa7dd7c2dcb8f91f5d737701c7daef
MD5 5b5607ae29c1f20867cfd3c8eb18d0b1
BLAKE2b-256 95af4bc0eb516060e18bbe4e8aa354439b0b0910d50ea02b82ca692c0d9d488a

See more details on using hashes here.

File details

Details for the file aioesphomeapi-18.0.9-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for aioesphomeapi-18.0.9-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 dbb3543baa5b8db7ae73750fc301fa58e2950e06da2cf530d239cd5163110ddb
MD5 6741deeb21353937fc7146cfe9b20046
BLAKE2b-256 cfd5f7f9fd8ffd428eccaac9f235b58d011347c0ed8f447cff7ba90698c30160

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