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

Uploaded Source

Built Distributions

aioesphomeapi-18.0.5-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.5-cp312-cp312-musllinux_1_1_i686.whl (2.6 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.5-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.5-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.5-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.5-cp311-cp311-musllinux_1_1_i686.whl (2.6 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.5-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.5-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.5-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.5-cp310-cp310-musllinux_1_1_i686.whl (2.5 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

aioesphomeapi-18.0.5-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.5-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.5-cp39-cp39-musllinux_1_1_i686.whl (2.5 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-18.0.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

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

File metadata

  • Download URL: aioesphomeapi-18.0.5.tar.gz
  • Upload date:
  • Size: 596.0 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.5.tar.gz
Algorithm Hash digest
SHA256 1147d080499b4bae00e824b8368f9e05041176fa8f9832f068c6624891912ddb
MD5 f776e98caad32f5a4d3e2f4779b1289a
BLAKE2b-256 67c64f6e8f4a374d58a3376272839eab57bbd08c9129b45e7e44494bb8ab56cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 7d9a8b92b26a1fd081925f093419152dd03b6734cb8be5da16845cc12d0ddb4d
MD5 bc702182ab8bba42e78ff048738beec8
BLAKE2b-256 bafc5ae046023ee12a719b138aa9977fbba4c6d083c7f5ebea8b1e1ff359ace1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 927138c68f9375b7e5f3b221e4577d99a726a95d854a2086b036afa825be77fa
MD5 73250c0205e58293cb1738abe2173c4b
BLAKE2b-256 df027d4e552d17c19a63489f0ef11d933f7bfe6154b34938b54067a6c0d01134

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2359236cbdf66b07f0ed90545926cf341572f143c88579f6fb2992e30622e7ea
MD5 779966bf29ddfebba48ef4c6a112e122
BLAKE2b-256 e548a6e6c829c9e37a507ce40e5a99f4bd85b3867a1f8bb8ed19532659895aa2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 1b8c9b7751a418bb812bbf9403f5fd3087a721052f5a26335e0fe57ec3af294c
MD5 271a20673530f3d258659bb64794097d
BLAKE2b-256 74fb18da19620feceb6d07961723c7f1695f0f6f8a00e9aec4a01fa1cf48659c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f058cb32cddbe66e62cfd2b82d98e4bce31843b0804c06534afb6b631d1db7c9
MD5 5f0a73870a7e1eec3010da4b03f8b2ba
BLAKE2b-256 0b52c6cd7af8115a4f4d6fa21508405acd78a4fc50e4ae04276a5ea0d22105eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 fe0b31044a0d3332d55a150a70a774dd40da931d863c6358467698983a42efda
MD5 d1b0aa70a57c7b5e356af78662339491
BLAKE2b-256 8fdc6d85255f7a6b21d93ae01dd2c9a82692dd7006864d2008d2f05c32e40304

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 97113bbbc8e660c96471888110543f755d630856a03a2dd391496b346e48e84c
MD5 a2505caf1e9fe76a386e4a037b457e84
BLAKE2b-256 a07b37352e87c56ec1b970d0992ccdb6c5e4feae493a5d5545c50346e26b4d33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 13d1a3a103509c52462d66510b5c0728bb05b0608f94edf9388311c2acd1cc29
MD5 c06455e9e69de56b08528df93a164e77
BLAKE2b-256 96d8a2eeff9f07bef883ef5fe56f229a2c220ba0f78de6cbcb216d4c4f147937

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 eef84bcdae7de2e188fd3c0d6890d22b505d2b5e940b575e31dd6ebccc03b903
MD5 709f7647322c2205e393f47986c2d4ee
BLAKE2b-256 f7658bd4f5a2ec450722235bd3810a56371539a2183a2f0dae7b65e3f56b807e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 438943b576d7b267728916e405fc11c32c18209adcb732b1d54a799516a90352
MD5 d6016c4bf4bd66080a00d073be470701
BLAKE2b-256 c4198a5e0287bef9b832d797299bbcc70aa86293aa3bed6e2fe5f3cb7d9c4e08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 50a33778190e7b6e09b109e42508fd8653ae3a2e4320eea9c7842ec2fdf5fb4e
MD5 310a675cb6d516642491a2998f40c20d
BLAKE2b-256 3b822af47e4c0aebb0227512723ff8fd3b1fbaa8155852268663ab1dd8f042db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 522c9399e50cf0a21f5692816f5032d3185bd748eec4b81582fdde94605c4cec
MD5 8c72df1dd0bd942a1d9f2693a4d9472c
BLAKE2b-256 1954db1279460b2fd4f510b780e0d4ad8885684f27eb59255c1aaa4f65e0c12e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 9631f2c1915b6b9e675d1af2ec999eced593351c86b8fd202759218d62a4183c
MD5 0af20c03e8cf2254f7ec42f695bd60c5
BLAKE2b-256 f32541e0c429ee4e4568e7c58fefd8d9b62f47c8b1d1df1d304c07eafac8000a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 92f04b0ab7a6d7dd4679f3d5d184a6775725e389933cf48219d852a487bda479
MD5 b42d4399c387a2ba2f8936fabf393fa2
BLAKE2b-256 45e14799647a700673df987bb2c9d5abdca1cf2a5442634e678a450b65e4e0e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 18f9c88e8cb66560ba590461053dc8f6ad3859bf3e69443240932fb4b77c2b43
MD5 4db0a74d6f62e4150d0c869e6ea1a003
BLAKE2b-256 ee00aa98c63050412ec49482d3588f7bbbd286d8c75fd4877bf4edc24670c5d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.0.5-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 c7ea3a4d5622d86b69a69572c14f2680afd4ea84ca3206633c005b86f5f51b9f
MD5 32a6cb60032dfefb4c0913827fc185b9
BLAKE2b-256 801c8f4b6e953967f1f112f30e2df288cd20a5495b8e2e91dc1880073afae00f

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