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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

aioesphomeapi-18.2.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.2.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

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-18.2.0-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.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.0 MB view details)

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

aioesphomeapi-18.2.0-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.0-cp39-cp39-musllinux_1_1_i686.whl (2.0 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-18.2.0-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.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.0 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.0.tar.gz.

File metadata

  • Download URL: aioesphomeapi-18.2.0.tar.gz
  • Upload date:
  • Size: 74.9 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.0.tar.gz
Algorithm Hash digest
SHA256 281ff7d28acf1d473ace71e1dadb80ec52e3ecf8e149bbef1dea89e858e56c23
MD5 eb85a1b31e8395aafe2f703dc12146c3
BLAKE2b-256 e7d879b75c04858a361e3b07f81a72df533647bbc99c6121e82f3e0fdeb9595b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d17baed15bf587534793be8a9335c416722fddce4255345192129583e3175cb7
MD5 cd3a43dcb6899cf528efe76163f2f681
BLAKE2b-256 03a45aaaa74ceab6f400cce17e67b3e0b45c91988217f656e6d5a8f9a567bf93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 797739d16b31635c60c75afe5c7e8f7f16a2b379a71b10921401617b8406911d
MD5 70adcd2050f9426f544b05d451ee055e
BLAKE2b-256 69cc55c9ea4d08df0b7b06a174d8540fde0b6ecf3c437fca30005342331f1cdc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2c8517b97c7fe83133d29df90a2351db9bc1b88c35fc75d860206fe86c76ac49
MD5 4640b580eb4cb66a2b79238f6ebfff0e
BLAKE2b-256 e581b8d2290f28a87d432a90e04da5d924203c202b6d5eda066dfb687539baf6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f833cad929c62546d21881ecf7f1d8c7d06ccfe0446da40cad0b22c18030d512
MD5 1b88798146f0a8282bc0a8e892f25c28
BLAKE2b-256 9a21980529fe3bf9b4c2729e1280eb15dcc71978de33edde476f10b2b6f65008

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4c5d7ac35ccfecaa40bcb57de38af0f8ac8dbad6ff888ffe255f6a80a0414ae2
MD5 d69b4d8be63a1f851ede3de2c2176691
BLAKE2b-256 56ce200aca5d8d6d18f6e0e69e9b0c5c95ba6690e9b0f1fbf7b40b738acd2783

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 5ca258907b1e34db6da807605638ac9c950bd59c8266d80ae7f51d5997eeda08
MD5 b61516fdb370c21c738f46acffa07f90
BLAKE2b-256 a3c7e61a6eb925b3273b28ddcac215d20d79052a3f983fadfda9823d24f2a6e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a5c4a9a86a121333c3fec16c003f58a338bf0c842292732a8192436a6b2e2024
MD5 44c098d4b280240d2179b20364027f41
BLAKE2b-256 c8d2d52a2998edc1629a29f884536f7b85c2c780a0ed10aa8826219c47d13f5d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 79bd6067202bcb066a127b96fbc8a2cbfdeaa60f835f0181692f45d5186636a2
MD5 53b94ff39fc3345a11d34a3c781c206b
BLAKE2b-256 c1e284f3c8e53df8aa09ab11793112259c073fd6813eea67b9f4e73ac111a8b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 bcbfe8f3854a8f0b45dc8a35fac070abce334c2293176b17cad5594f9b91d180
MD5 b0b7deed71dd2fa6e47b2889d4794ac3
BLAKE2b-256 9cd0e340f3e67c151204b9fdf319f1acb7791f9b4ac9b2532fbffb440fed1ac2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 5db81758e6d5bc19e8c29185b968c35640fa04524290837c78e5e7f88b5617ec
MD5 ec45caf50e52f183a6a6362c61fc9fb9
BLAKE2b-256 919661accbc80bab44b202d43b10f9bf5dfaa48269e8db454dc325cd594f7130

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 78a3670771163cab54baba178e0d69c020efdf82d1a94914f5f8baa184112a2c
MD5 2dd178c8ace7a3b0b87f1aa6ba277e8b
BLAKE2b-256 d662235d9cc376bbc43a797e3b9c0e1890c447450834c0734f129eef3a572a18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 6811ca384853a1c283ddb99e7c92dffa1abdec34fe3ad21710a4b12af0ba1e43
MD5 73777ba329ded9537a09081ae63f2f57
BLAKE2b-256 53eb1ce22601b67f6f0fd13cf3c2a0f6c2739038643e14be4a0c0a5f90480360

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e2e7b1ee1ba44c158ddc2cc7fc2ff85a93e23f987fae25bbdced91672a196db8
MD5 ff2ed2d6b1c25923d8d93a217bd6a282
BLAKE2b-256 51fdc0edb02acacccc3960de3794b975948bcb519285037e79869a1ef7533df9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 0946191c0e6b44e27b790897ce6ed2b26d139a2afde1711bf2a4e922296a9877
MD5 697a97bbbce416b11bf03bc2f2c4010d
BLAKE2b-256 542cffc2996331deaecdd15cb5eab710f2ffe471b23165dc19ff5e8e867fe9c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 51518a929fa129af5eb9d5f61cd3bb3436b3c4213e7b4f2be79f63efb9688082
MD5 c65d5e4f2a792902af1d2bb9f3238a55
BLAKE2b-256 7cfe05e341e6fbc72e34942fcd5e1da09b0be8a020f48570b967ac31c199aae4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 bc483fd61cf98de488d13c0cdd4f7ea88f16368c5942bd9f55027ad49202e6b1
MD5 61b56b059655f3e0e7ad2b1e04ed3b31
BLAKE2b-256 bf8e4469fc49e5b5794d594be348358ca345e409dc556cfdfa32d7e516c801f9

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