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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.12-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.12-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.0.12-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.12-cp39-cp39-musllinux_1_1_i686.whl (2.0 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.12-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.12-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.0.12.tar.gz.

File metadata

  • Download URL: aioesphomeapi-18.0.12.tar.gz
  • Upload date:
  • Size: 73.2 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.12.tar.gz
Algorithm Hash digest
SHA256 ad9618e702069961858630d585377665738b9e204695477045bbf5ece7da5a2e
MD5 a27b7b8e67143a18bf4a9faa86260ce2
BLAKE2b-256 7cf6c8b02c6e18545fe9e11aa22eaa2e2edd8075748b88cfa058ae61fbc115e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 b2a15cfaa78a5fd4b636ee2f60add6aaea2e789733f1f87620d7ca9485f9e0de
MD5 f4b1f0dc9a2d55cee7b10b4c280ef892
BLAKE2b-256 c0ee38f6920aaaf0af5681ecdbaf1831e93749baa88d5bdfd2ebdbe9f233e72d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 b7041b83ea4a9d32dda9668fdc9c14055118e25ccb484c06fa7f0ee7bc5185c6
MD5 a008c6db29a2e5767aaaa69c628bbea2
BLAKE2b-256 236e987b69e46abc6fe594444d46210bee0097920551988d027685304f531bd9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 87d974d1ebdba4e9398a4a0c0e292f787a167c3de649d2924c589644189fb1e5
MD5 f7c795c5aef74b0313378cdf02240192
BLAKE2b-256 fb8d347f7ffe68f3b7961fb7016d6d4e9af77eea37876d621c2b4bc0cb2ee1d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 0faacf925bad08e54a1d39d1dead2e2794461b0d49a3611d130cde05edaa6be0
MD5 a8b2ddcdf758b6f104fb7a670ce894a6
BLAKE2b-256 8f237dd56e8d2ca0ae50357d331f5a79cf5db70143fb65b7ebf073c4bcfbb719

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 07238394c7e12055e89a0de58e5d9fa50d8b859732e8f8b7e95f2fe09d720273
MD5 903e5992d4dcfd949a6e64294de3eaad
BLAKE2b-256 0009ab7955197c916c191c1e4461e6bf5c33c386455d02f321e0786723ffcb91

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 2fec8f789819a4eaf56cead80cb9a1a51e9bdc82a5a3b1f62c32bd5c31357c85
MD5 9dbda614ab55670fd963ba776116d68f
BLAKE2b-256 f3e8139267a3e0b1776f7560f9acf1aa321150b1da3c53aaea8f6e14b1eba769

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8bc6056ec66856e6c7d4e4937fd0e74de7214e7a419e82427686897d6a47408e
MD5 8f262e5fc74fbf0a66b94a20a16523ba
BLAKE2b-256 5e003ae72a742a6d98ef6772e4fc2aa65aabc9284572c27489b0e61711644f99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 25b9d741ae0e39444fe0fe24249e631689ca2b250e4c011d23efacb7fced99ce
MD5 f330c4b384f712adb24c75f6c2e0cd3b
BLAKE2b-256 0228b78725f384c9275dc289898b4f157b6a8b2b7f20a31bf090a6aabc78ce63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 059fb304d3506bd62d40ef76c30dd52e484c31cae72fffee71632d2e221dea67
MD5 b0fa853ea6fb95c976dc44a3eca21324
BLAKE2b-256 52013f78a4353203c3b7c4d7a4d4518cf4fb9caca09dae855f7175ca14ac912b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 182eb3636e876eeedff39cc225754584bac83724b924824c28c5d4bda03b0539
MD5 a233646e91d5efa44379eba5da51af89
BLAKE2b-256 118acc369ce048001bf6d4d21622d35801e7dd7a8e224db1be8bd07d547cdbe1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ec1464c3f30dfe38ae5f0f6e3cb3597580ed0260f7b54edf1c6fcdc4888e288
MD5 15abe54815d3d20b9c8fb0e805529763
BLAKE2b-256 8f7f2f6f7dd24e1f5acc6733df20f8782925f14cb7701672bd1a59fbab9f2776

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 bee7712420205ddfb35510350b26a0d2dac232672c91c7fde0585391c737463d
MD5 db882409f0efb79e9340de42dc387c51
BLAKE2b-256 055b513428f55d2987eb3650c7fee07ed390cceee812bae9a325e19209a3dbf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 a16d5d02dfc2e31f878b5421257474ab422a65cdc3141fe33b17c9c0b45e3599
MD5 d011ac41e69276722c222b8d34465853
BLAKE2b-256 9558b5957c4c2ea5fec26848abcd73e735e6fa01320e06d8aa00619e0a4748f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 1c1a97489d7e97fdc14f7d110174a532037aa035452390e11ccb251f4449e4dc
MD5 4302c0aac79c0037d2068bf9130baddd
BLAKE2b-256 cde1ec273e8448cd425cdb708cdc2987c8b1a1a5702d94e7da428454464e58fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 19894219271b3ba11707c63246b2e272da261d37661d631609f14440ebed9ec2
MD5 2b142bb5b903df630da18d16e99077a2
BLAKE2b-256 10538bed0915e314b45ade1fb3e6007b06aa7080ead3fef219aff8eb58b0d5be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.12-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 48aaccb53e19ffdaff5a3fb94852a1ca5c453e22028a99f0e026cb685ec4eea2
MD5 deaf36e44f3d38cf268758c64c0692ca
BLAKE2b-256 bb4443c63616fb6095d535a6b875ef3d9ffba5567f27a1812431ddd5e1ce807c

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