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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

aioesphomeapi-18.2.3-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.3-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.2.3-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.3-cp39-cp39-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

aioesphomeapi-18.2.3-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.3-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.2.3.tar.gz.

File metadata

  • Download URL: aioesphomeapi-18.2.3.tar.gz
  • Upload date:
  • Size: 76.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.2.3.tar.gz
Algorithm Hash digest
SHA256 e6707fd43be4bc88e2b66c0600eec878f0d8faba1b7eae8895a61fe6d10c248e
MD5 9605718fe61092fa5952abd57f1e992a
BLAKE2b-256 093a60784334c339e1a9b5276eb4f324f8545ccc8892b025027afd067f58e5a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 13f534bd9cef96101ef78b40b35c475b3d054c62f4be3638c1f5d93a79f7f63c
MD5 1f9b8d0770501e3d83fd769f22bac3a0
BLAKE2b-256 ea00b15a06bd6d18598c6480d0aae8215ce6889b9fce0c2c78262c9b8ef27a90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 76448aa8a45ff019c50aa4286026fcd3daa461d37525dc6af77cd46fd0bb6234
MD5 04d7da8519a08a6261130cde71e2600c
BLAKE2b-256 d55d5dc11d665c3fd7102b388dda4a57eaeadcac573178216b4d3011a2fc296c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5e2fff77f2b34270426571fa6d6846eaa9854558716e6bde85d522d1cabc6d76
MD5 3e6d44fd6f42d57f2137e9f15b3914e6
BLAKE2b-256 dcdede2a86c7e41be4c21423a52c313d203a93d1710c914febe67e22c00f250b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e6cda81fdf9ad6d6d9ec2e1b8e0695183696010bfb77d6b98ae028f4dab14c8b
MD5 457c1707f1037bdf0753cc3c82e795e8
BLAKE2b-256 37dd26170f2267cc376a4cd323ea0d61a26607011f6ae0ac82e6bfcfff55ff5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c4b91d637ab779e76066fb148d8ed1cc6a506683896ab9931b6687b09c81353b
MD5 695f57598a316fc75849ee3745258822
BLAKE2b-256 c938e20bd15cb7c3fdbe74548710fe887ee0a570c7fcbed21976b8c2ac8331e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 63fe216dce21cc30e5e7e8b2c9e0b1ff3afd086122de64a89a1d0367324fe137
MD5 aea361c99a0c23890992b795162d9fa0
BLAKE2b-256 55a3424114a347c05a8b30dd1e21151fb799ffb310e5428231fa4913ab33c53e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 668fc613f7771cdc754f8dfe52963fc6024fbec4d5fbb59e9d4c0065edb3fbb5
MD5 1b745d31ef67b7d59250c0a9292ef5d5
BLAKE2b-256 980f31de0dc616fd63872744064d770e573fdb4cd4f90079a2e9bd040a51f87b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 dd36cc713f2eb76e2b3f395551c59a0e4f3ee70912a9c192be8035822e10f6c7
MD5 e47d0507cdf39713d22a11c62cc16874
BLAKE2b-256 a73d082c581f6049df94b0c1b7a24725bdb617b4be12576ec4f52f4baf904bb0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6447421ada03edde89f26913f6125315d7981a4140e8deb537e481715d959f66
MD5 0db70c37432de0559504d10b055daecc
BLAKE2b-256 517559aaa8cf55e394d1b50fdd40367143376839d9fcef8ba69ded4ccba26afe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 61bc18ed3373de23b4d8b6e9c13581e4ff8ab9ddcebb2e9e818a5c2d953cbb9a
MD5 ef04b9ec56e0ab21167b8587fd0927ed
BLAKE2b-256 12fdca6bc04df2e46cc52ed0d23304d25cb484e3bacc4ab800eda6c481893a1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ad39cc70f8820a604ab6f0511c40e996e8ffd5721a8d454e480ab77ca2ed9ba1
MD5 ae16b8fa4c1817c6e1a2f121e07ba249
BLAKE2b-256 db1d066ec1fae2d368616e1d2ed6870fb5ed3e711cf8cbdb24025ecc58119a2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 fba636a74ab2d9c820db9e50514c3b9415e9d22a5fbc59253b47bba785c8fb11
MD5 dee7f584b2b1c9a25e7214fa549640d1
BLAKE2b-256 e85648392f08480b33a963f86c057b81399745cfc07484f64f7693ed7b68bee4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4a9c55cb4760fab76bb6933623ba4a5dcb8023837e976624c8256d2db4fff2a0
MD5 a35c23411989a38349b750575f7abd5e
BLAKE2b-256 0fad64beb0191d205afbf8578e5db2d182bc4d33804357bd275fece8af745171

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 9601767028610135e2a2b564635d7c23c9ef39705c7d937df658c0f4a0761408
MD5 842e9a12238085652b3f93fd6348ab25
BLAKE2b-256 e3740be23821ab410daba6da0f42ebf9438bd8fc376be5e6694dcb74e721eadf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0d96da374697b2092d674db8753b508b81ad2084709b1042369278dd4b00d5b0
MD5 ff6a902371587fe1464e35e9aa99c448
BLAKE2b-256 f34e0fe480bad3792e1b8ae4407157f8cd7c40bf28963e83eb09fc992e294bcc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aioesphomeapi-18.2.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 7070a878148002d4d03eb83a1a50e2cdefd7d1aca355ba4d9d098bea6970ce5d
MD5 529548d2b6ecaa73474fc66f3a8dc0b8
BLAKE2b-256 1f2666ff5886d3726f6f88e93c1df164e8247f0c6d04398a8787f44a8c8be11c

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