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

Uploaded Source

Built Distributions

aioesphomeapi-18.0.4-cp312-cp312-musllinux_1_1_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.4-cp312-cp312-musllinux_1_1_i686.whl (2.6 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.4-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.6 MB view details)

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

aioesphomeapi-18.0.4-cp311-cp311-musllinux_1_1_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.4-cp311-cp311-musllinux_1_1_i686.whl (2.6 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.6 MB view details)

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

aioesphomeapi-18.0.4-cp310-cp310-musllinux_1_1_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.4-cp310-cp310-musllinux_1_1_i686.whl (2.4 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view details)

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

aioesphomeapi-18.0.4-cp39-cp39-musllinux_1_1_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

aioesphomeapi-18.0.4-cp39-cp39-musllinux_1_1_i686.whl (2.5 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.5 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.4.tar.gz.

File metadata

  • Download URL: aioesphomeapi-18.0.4.tar.gz
  • Upload date:
  • Size: 592.3 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.4.tar.gz
Algorithm Hash digest
SHA256 a67e3bb14f54feddbe0f3158dbe396b40b4b95307ad02e80fb021bb7bbb3c733
MD5 eec674e17d60b75eca5e7aefe9687552
BLAKE2b-256 d5abeb086f67f633089e46287f3c61cc8ad01363a8bd07676f98b1c7cfb03cea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f650d43f65699f9bbba2d81734961a581eaa0360f7dd52a872dd033606f8d067
MD5 2bdd2f87869dcb716986cfa401268951
BLAKE2b-256 5d3aba5bea585ee8abf0286d1cb760a6aeb61a5431e6f88ad1023dcd54ec5b6a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 8004e52cc93c51eb98bb901749819f34d58f9144303d97df57ce2f36f8f61d2d
MD5 8951b5b4f3ace498d7c6cfa6b5fd3237
BLAKE2b-256 5794ff9fc8aa4c32c123ffb5e014994b89adc1250197e006ef80d20a73d65fc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 de8564ba6dcfd5f28fd41b99347a06a4639bac157ad5cc5282cd70bd224ccde8
MD5 9fcb6298487128d50d52978d00e3dd0a
BLAKE2b-256 1183cf98aa0101e38cbea0048791b94c38e26f55f1bc047618b17ce94f4a5ca2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 483bc398b02edcd09f6043aca21c6fe44b323ff06596d2d887e2854aeb5cbe7d
MD5 a7dd4604d55b4cd4c4d5fd73219ec0cb
BLAKE2b-256 130839d50eba1ba776f84cb3728b4968ffc13dfa8ccc00a2447325db869e280b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 fe2ae584bcec42262a42f9c0f5f71ac573c22e7df5ec9467573186b47bcb2e05
MD5 ea4d3b504d274a4f2d8138a6b4d8ee61
BLAKE2b-256 647808302870f9249116cdd4783b6959496057997fca4ef44bc2ed677daa03b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 b0418d9a94ca084100644cb97fd284c805f00b2492b87e771d81c5093526e511
MD5 736d1c4df77778a3cbb0aa412a4b6594
BLAKE2b-256 6b5eb858eb67060cff8606246ea9407c336bffc7b1b5d4190a13c59be0bcd700

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 754122f3b5f884175e06b982b2bae11e24590c1ce67f5cf7ca7eecc97b6d92d0
MD5 1b7f047aea033c9ebb6e7026147f4e39
BLAKE2b-256 2097882739857370d1868137066a73e100bdd16acdf055740ed244da7c7e5993

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 633402d2d255bfa87d135c1ba7627e09cc1120cb7c28832c04b908e929cb957b
MD5 67f073bcb1fd1b4cc1d4b4b03d29bfd0
BLAKE2b-256 dd05bc3e623e451bbcbca50b2d816b848ad0f6ba38bdec0dd530a83fbcff7691

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ef5d814262f9b3c08faea7856e4df65a4e16783b9689b38cc7013fdd13635744
MD5 1da82f58c132df45b5025f8ced507f09
BLAKE2b-256 82047f7304ecd6d7bb4a613ebe0661d378cb3186c716ed36199e7c969a0cca54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 6e21fe13ce71b9048f75ba7262f7f1a7e90b2b44a9a4bfa9606230e95b241b9d
MD5 574e8e9eaf4a8391f10231958a5b6d6b
BLAKE2b-256 0e5877902ac1a1d73b3ddd248349db74225a9697e77b93dd1516cd96655bfd16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c4654dd4ea156d9f10b035daf6af7d27d7f873458a70d35f053820b6b6f17e57
MD5 6e9f83549f67cc66bf1ca7d31cfca2a0
BLAKE2b-256 14adf0cb03f86cad219c9cc65d57f645415cda78bb5ce67b7ee9ed040fbb09df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 607dde9ec00d2028b2cc8f5d7733e1964427065be33f4550c08b7e51a6c8e713
MD5 bb549a008ec191b425150e8675594f74
BLAKE2b-256 15a6a206de8e9bb349996089596e19658bf3bffceddd54f691ad972f4ac6c7f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e1db081db75c57b6fd7bdebba4a9de36ec4d4fb39eff6940021311157a79b107
MD5 93f9d61b14967e07a8755bb33c41e484
BLAKE2b-256 41dd40fa56d38395bf4eed06ac244366b97d1d2f54ba675c516f78acccf3766f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 3be6de5cb9901a5d40895af8f33ba2f8455fad1b6f6c26d2ccc4c81a59507971
MD5 6705b9bc5a0160b9af77780db2ad08d9
BLAKE2b-256 912ba58773e34880d869469590668e4f93df9586628152600ad7781782e95b20

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c1a4947adecd9125c06aa9d58fb01dfb81edb5f0f58ac98b71b4aa18a881acd0
MD5 a1209d57a2e2eadf504ba99d8673466f
BLAKE2b-256 33bd11d7643a18b9abf46e0ed29e9f91932e380a5b607257a964cb25cdbcc0bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 2e23e0f5d542561cce2845db1a0030f3ffce3c3c6da5ab9db980deab026eddee
MD5 b6977f7bfe4b48d0f5c0e2f59bb09d76
BLAKE2b-256 6019425846747abe82e50518336dc60ce1e095d4e9c7e99f72c30320236efcbd

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