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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

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

File metadata

  • Download URL: aioesphomeapi-18.0.6.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.6.tar.gz
Algorithm Hash digest
SHA256 319cb7a8a1cb8526ffed337ee6fc37e8d3f7a974675ccf67fb3669829ebdc4db
MD5 bda29913867f63961d8e674607435b91
BLAKE2b-256 8d0eae60328808f77d4eb0272556948bf425ceb4d94479aa1c0108d6c2ab6fce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 9a6b3cfc9824829a95ea213e8ad5ed96455d22390e4157af7a627d26e5fd5391
MD5 9718381a5f7b06954da41a7e9e24bc16
BLAKE2b-256 2856331de0392c1ebb692951151fde938b76ab04af1e0175111db4fd7bdc5645

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 4fea527dc554836dbf7a2db60edfc6aa90e4c1840659ebf194da7ef9783764e3
MD5 4411c12246d41983477f38dd9c8d7697
BLAKE2b-256 8cc5fcf2d8c6ff13ac4a55265f4f7d8b32b0ca08567fba806a3eeb762f4f7483

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 787c6347a0e35ae86efde57b20f54cfe469ff2de15c3b0377889989694ca7f67
MD5 ea98113cc2861fb8c6832fe44eb1a5de
BLAKE2b-256 fbcabcd6de584a435fe91d79e856d6ce74638494363a1e4c5136f8f90f3e24a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 bc366245300ffedbe7adb8314cf6d01ec3293da733756ebeee8d21fcf32769dc
MD5 91a6f8f0ecb789881924e8b041685b11
BLAKE2b-256 e8a367180827954a7aba33c68bc68f7c08e4cfb187186624565465cad17e910b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 96025974f6bc27bb6186e835913ee1e2aeb0c74e0f29310365254926dc1c7e11
MD5 2b290ad7a3fb2eaad8b608bcc4338592
BLAKE2b-256 31e754f9ab3317c0dabbfd54b169bd5b3108a4c4cb9096cc002802852437e9cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 3289203d88d3bbacb0451fbaefad18c0d38d7027f5a5720eab648b645b440972
MD5 bfaff7b38e74049e7a93e91a00d0e088
BLAKE2b-256 b2cd7640c6b058283d2e2284b2572a3b0cdc18f1731efcdaa0af11fcd420bb37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a1cbcc5e67bce6b3f6951117b1a286625885c56b83c14e3a8d8928bd197215ce
MD5 a465f388238032da8b605b2b8604f94c
BLAKE2b-256 781d9581e6a981e582b15563595ddd093cd3c22c6278b529de9c0a492f91c2e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 6852e90965e416bc6dd47a2df19b5be6fb418dc605f6c20ceeff8822e82cbf77
MD5 4dd63f1363f7a4384e693f3563a3794f
BLAKE2b-256 7a2c80ee7506762297d124d16575724b00d1d530c605cf68010a5f194f4180f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 dceaa30b1de9446a744698d1f43f2e3c914df45707ced36cbf1a64a3bacfe299
MD5 50c648c3b4f3dd0b13fe5ee0b73f8d53
BLAKE2b-256 6a3229264785eb13b2ed7f2f4d7d5e41dadd6532cc8d44882c6a937e9e3d51b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 629715afe08f71b6714bdb1315085ec95ce5bb75dfdef08022e6100a943d1ee6
MD5 008d03cf3e95cca6848fda4c6f5823d6
BLAKE2b-256 d8bd45bd13a9de85ed2246ff8a030adb4938068b03dc37a5fe07e67058a3886a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 283804228782bb0cc6100523c2ddf223006e6336597e877c7794ed66573d2002
MD5 e00416542eae9e4318ce8622f62bcba2
BLAKE2b-256 294b5949b2621bf735afec4bc5cfdf703ad5e7b75b45bb5c09a609c0ba4bad8f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 eb64c35545fede38fb346fb3d590e1bf778bcc5dec92b2dd16a5e06cd92439fd
MD5 6ad1f5e13c408e47a20c6c32da99d2c5
BLAKE2b-256 16b63b628b6c63ca2d50d95f7d77f04cef8d86f41b46e3531b9ef36ca62ee75e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6beb29a1deff3002e8f9d7ac9d2eb1a53cba4fb11fa29399e759ce6f1fa8fcc5
MD5 556fe1ca61a15cabc86f3b658814c36e
BLAKE2b-256 3d5db9270a7e35574c357858774cf8e6e79c842c8fdedb1d405cf242a6b587d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 4904e6d09fb02c115b02cf23a7d40e467b2d59f0a89ec63e167d429270782a2b
MD5 4eeb734b23da755be868216699d58918
BLAKE2b-256 28a79ee826d0debb16a991adca7a051e492c6e6fb232f2b2cb8b634c4d1bbd8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fd24062dbdd8055ae4ea985e1b63d9feeac8e92f8ac81d28054334cad22d9181
MD5 56e650f2810028da43cc025ce91bd08c
BLAKE2b-256 197ef2a4225a9343874cc5d75b6f5129c8b7a007efc115ab42af155e74e4fec8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.6-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f457b3532342cd0021a78afe7e9a72d5574c91a1309402c828fbccfe8ca5ec06
MD5 67db7d031e722d29917dd4c77e116bd2
BLAKE2b-256 1e20693375a0bf797e2d61365328178fefda11eb2d5519aecdee4db547e467fd

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