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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

aioesphomeapi-18.2.4-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.2.4-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.2.4-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.2.4-cp310-cp310-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-18.2.4-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.2.4-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.2.4-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.2.4-cp39-cp39-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

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

File metadata

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

File hashes

Hashes for aioesphomeapi-18.2.4.tar.gz
Algorithm Hash digest
SHA256 e5cb977bc68813dece9a7441ea1211b246d38ac53351d2d1becbb990c73cc62c
MD5 a3b23b2cf2263969891d9e3ee9a6ade0
BLAKE2b-256 2239e6bcfb547e3bd0253117eeeb7126c67e7e7f7062d5522e092430e6d04d11

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 904a3b46d9da1d9c16218c3e6e2b63eff09a8a73bf7814c5c003e583ac0ecd0d
MD5 35d17276a8aa9d86f29e98e2a226f3f0
BLAKE2b-256 08aff350e5185257b24d355f1852188fe15f1b277a25682793853d89452a3ff6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 59765d29e17860613bca21a8223a26211dea01389cd79b8d4d87cb327e61d091
MD5 44bbf6beb3a2472a5bf83c5ba989318e
BLAKE2b-256 aa28df049bcd85d64c197b1783d079d3b90746d14b4cfcd8c5a97eda5d2148f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6f38e3551f9d9ace79cb190084627bcc5927a3c08de1e1c811b571fb7b1695da
MD5 42c8dc0e93e603fbb5c1393072022983
BLAKE2b-256 5c82482db97810615a4ab672cb74235f346af9ea4c81a508a12bcd9b199f3641

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 33a5bf97f173bc3c223dab019e3eb4a456a3d78d0f370186dcabf2f58a3cee11
MD5 6b5443013877d0068df11238c7cb0ee4
BLAKE2b-256 abce61f402cad094d8953a1cd19082d0df5d3cf9cd108a0d3ab3116f6edb24e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 223f5cbacda5db571d5d697781001584d5d68d3df395451812e3efd43426ed3a
MD5 c2624cc2ae66de9ad33b0246e40df232
BLAKE2b-256 4b97d646b87bd1a7250987f24982ffdc6ea4b27b31dfdef4d9cbfa4f188e73f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 fb4059ea176317cf398426d32ae4940687bd13f3e5ee13987fce2166585a5dd5
MD5 f33b446ac70df2b17c4129636a5711ab
BLAKE2b-256 c4a8102f1625ce964f8494b498d9f5f67aeea398b507fe5b1c24337299786f02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fc12014c9abe375f8813a3b84e7566d79d3277632edb06ce7dae1c15a56d0b5d
MD5 4aa770daf65cd4dbf7ce331b73c6452c
BLAKE2b-256 e8480df3f909be6984d32b3fd174f9b67164ab4f1d321691ec2afcd1a31a03c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 8c19521395a711a660be8f8dcc8f1dad842475bde24d200db4bedd39fb01be75
MD5 197b864706b64fefdcf6a8144ac63e38
BLAKE2b-256 ab27aacb012bba0d2253c0dbdc61063b465c3970d1560848e6f784341d05cda9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4d9462a09d9ec906f369305907357d4c2094813921f9207d6599e3b8606e42a5
MD5 3c67a50ea6876902a800d09cc622ebb4
BLAKE2b-256 b1aded00ba33038ff2dabf611c4b2ccced2461fde92cf3c23dddbca77eec59ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 75cd7d9f9d329f429dbe7cea70a437e7a656d4cace3739713d9463c8aa9c513a
MD5 1cc0ca2207e1ad2ef42bc6f6c7d033c1
BLAKE2b-256 df269f51924ea55f6cb137cf5f26ad4395c1aeb0b080a50e3f467ed911420307

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 19bedc56a333ffd102841581e0b0f9ca6f3247de9e4897a725013c2186979a6f
MD5 f76e94b74459b6520018dff38dc849b5
BLAKE2b-256 8b1df02a5280a68cbb0ecfa3d16289e7ca50bc9864342b220dfa21250a6c8d60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 664dc052ef6450d07d4d5e368de9d96b88bd260a8032aa6b99799b8375a6ee54
MD5 fb6994077a16f6a6e77a23993557d3f6
BLAKE2b-256 c0fcbe5579dc640dea910beff1267df30a41f19441b8b8134617e05cb5a3fa5d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 5dadd52ed51291312389bd8b651e552b1b85ef2b6c7e8429a483ca047ca4a013
MD5 a789252498958f5fd554b737591a4da9
BLAKE2b-256 b7e933789ae5645b8e6a8f50008be389f7985a035223c9204ffed06ebd4b9853

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 85e62dc25fed1af24b023bc852799adcdb66ed53d44d695e83172fb81bc535c2
MD5 0150d02a583aa06c7e5fd09db3f01e23
BLAKE2b-256 fab6ced8f8054fe1fb12d3c911e2ad7f173e97b378fe628a8a155a3efb3c8780

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ca1c79efa59d96dae91a0777e966617d87ad5fb8bc6034d333f9beb35c682f97
MD5 4d1a6ca504c3028e347be776cfac43fc
BLAKE2b-256 dc5f0437307e08ee2f8565ed87af5ff17f38872ec888b6dd23010c4f43dbae26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 1185e509ba42dee211d95d38ff0595cee2287ed583f00012e2fded3880713dd0
MD5 80f8bd84e30ce4343463e9fe2a777b14
BLAKE2b-256 22bf230022e2505483ba52c10b34695f2dcf340f8f51036f79b2dbc2cafdae97

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