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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

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

File metadata

  • Download URL: aioesphomeapi-18.0.7.tar.gz
  • Upload date:
  • Size: 71.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.0.7.tar.gz
Algorithm Hash digest
SHA256 73ac1620e70da8b3d96b1dafa0b6e2dd3fb6dfdd09a44279261923841f49e72e
MD5 1d2c819937dc3f901ea431ec67fa7c18
BLAKE2b-256 288d62f89a8ca2db841fcc38475745fb7a8fd67a7ef53332e882cdfc1506cf4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 527a285d6d5cfec9ba08d95ca57ce1c14d2d7753d1b93115d0c3646dc6def38c
MD5 095b124be8543ac34f5f030a6cbcf3d5
BLAKE2b-256 f1ea862880cdc9759f70ab85458c833c53acc0636a18849211f537ed263f18e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 5137a85dc1befb4065fc016c55e9f541983418c19ee2adc5e86c4e38231e249b
MD5 b589a69a4dbc784d6e68e70eb8255f75
BLAKE2b-256 ee7a388744051867d8eb6153a0f03cb573c880721eb6855ce57a43bd68bf8481

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 efcfe193c36efbc1759be90dd4c606147b6986e5f0a8fd61d454f44e9f63e489
MD5 3e2026462374d4aa1f5e294a10439938
BLAKE2b-256 de54bb60b2eee11089888dbb3a39e5cc3f9c7d437270d690c057787dd27d9368

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 93e08f35a46f56854dd58b228f117cc5072ceb1c143c263190ac675821c55669
MD5 bb698011b4e28ae81354f734f3ef3f00
BLAKE2b-256 0589d957a52ba04369a10c180fe7bbc631672854aaa4b076b06ba8be0a76a73b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f0c17ab214e751a56866ec1361da18aadd993931a1bda4a0b12b3e9e3b024980
MD5 7c997668830a2577237aac1d674d5ca8
BLAKE2b-256 8103448e4b9ecde00ec7a64c1401653c35cd9f7180229b234b4ffb7604006c52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 8e10980ec0999da29cdaf74e9339ce429584f848fe8e79f308c0f2419496b154
MD5 90738b07ea1be09fbdb83addd832e747
BLAKE2b-256 f278f64d8e9da9a095361cd3ccb886af3598c10645273b59e5622169d0c6e653

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6f6b61626c183c76781016021828a305759887bd59191abd168aa332d52ed204
MD5 3fab405a88b279df98befffee69fbad6
BLAKE2b-256 340ffe014c51ef5db41ca6be13b3c4a9afa7e688b3037f577efb2e7d27c90398

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e9ec9d77d2999e585dfd198772af30e69557dc9b8559fcfac0a375925c430d4f
MD5 37ee165786bc1de93b8dae2a54cc96b7
BLAKE2b-256 24ec274efdf2e8c5978f61e77f20e4325f68542eecf79eca435fad4823a3d2ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 facb20e5a3f8026fe4b77c05bf58bd5427661a889d01ff0618809b024ca8a88a
MD5 e1c658f7df22e8c636e43668284630b8
BLAKE2b-256 bc24ca4006b999e38555f798fc694825c76bc4eb55d6bcb245beef3284bc2853

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 2bb44f056cb86b0bc819a1bd4b56014a97c2b78154a6ca517651907df77ade7e
MD5 f96ab68b6797688b6b2e650b6f5a446b
BLAKE2b-256 a42e73942c56710bf74542605dca79c140bd17584bde4eee95db2cf93be2cb4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0929cb747bf690b7d413940894c236edb48d2f035bc4b433bf8bc1fa07e6c99
MD5 7aeb8ffc1bef4e49f6263495ff3ddcdc
BLAKE2b-256 615389e6288317829e828d363793a7e96b35ca77eb2a02bf6acd6c84c9aded07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 d90dc2a63be1fdd780884d978faa59148db57adce0ecc166c98e2f0fbe58d394
MD5 f5abe150b8d4297edd190fdcaff68770
BLAKE2b-256 52fa01e124f987d6e1085e70c7405b4706fb9714eece290d39eba7e2ad64f606

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4f57dab12c49c466cae90e870dfa32932200ce66d25ae1cbdfbc7925409e6023
MD5 81b06a2a97d44f8ae82febd56acb4b75
BLAKE2b-256 51859619381b25c6d821aa4307c5919407865da90d60b0b8962386eae53735a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 2bf1a15cf40bb95ec5c4beb033e25a0043fc965e1974e0da3696e82348d926bf
MD5 cac49774612523c2f3bec4291040ed66
BLAKE2b-256 74e10dec07570ee97b3516d0492638013e7767ef947d367eaafbe863bf0e79ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d345c37f2a781f92ecd731cb7d36f0c3a290fc32487faef1e0c6004f7e488ffe
MD5 761523a1f7e672d4073349748fb1d895
BLAKE2b-256 c0c29d837f2eb2026b0c4c7511f8810d215d7cd5a04d84156ceaddc2c4e47e02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.7-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 cb51ce5f6a0e35aa77014ea91487431c057c5b0decfc0cc9ab777574c042746b
MD5 26477728c5a6b5086e221bd167afd6ac
BLAKE2b-256 63088a763d9a3fea5a0e3f7811d612cefa274ca2eb99e4a68d217b6d5feadcf8

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