Skip to main content

Python Wrapper for Homeassistant's REST API

Project description

HomeassistantAPI

Code Coverage PyPI - Downloads GitHub commits since latest release (by date including pre-releases) Read the Docs (version) GitHub release (latest by date)

Python wrapper for Homeassistant's Websocket API and REST API

Note: As of this comment the REST API is not getting any new features or endpoints. However, it is not going to be deprecated according to this comment But it is recommended to use the Websocket API for new integrations.

REST API Examples

from homeassistant_api import Client

with Client(
    '<API Server URL>', # i.e. 'http://homeassistant.local:8123/api/'
    '<Your Long Lived Access-Token>'
) as client:
    light = client.trigger_service('light', 'turn_on', entity_id="light.living_room")

All the methods also support async/await! Just prefix the method with async_ and pass the use_async=True argument to the Client constructor. Then you can use the methods as coroutines (i.e. await light.async_turn_on(...)).

import asyncio
from homeassistant_api import Client

async def main():
    with Client(
        '<REST API Server URL>', # i.e. 'http://homeassistant.local:8123/api/'
        '<Your Long Lived Access-Token>',
        use_async=True
    ) as client:
    light = await client.async_trigger_service('light', 'turn_on', entity_id="light.living_room")

asyncio.run(main())

Websocket API Example

from homeassistant_api import WebsocketClient

with WebsocketClient(
    '<WS API Server URL>', # i.e. 'ws://homeassistant.local:8123/api/websocket'
    '<Your Long Lived Access-Token>'
) as ws_client:
    light = ws_client.trigger_service('light', 'turn_on', entity_id="light.living_room")

Note: The Websocket API is not yet supported in async/await mode.

Documentation

All documentation, API reference, contribution guidelines and pretty much everything else you'd want to know is on our readthedocs site here

If there is something missing, open an issue and let us know! Thanks!

Go make some cool stuff! Maybe come back and tell us about it in a discussion? We'd love to hear about how you use our library!!

License

This project is under the GNU GPLv3 license, as defined by the Free Software Foundation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

homeassistant_api-5.0.3.tar.gz (35.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

homeassistant_api-5.0.3-py3-none-any.whl (45.5 kB view details)

Uploaded Python 3

File details

Details for the file homeassistant_api-5.0.3.tar.gz.

File metadata

  • Download URL: homeassistant_api-5.0.3.tar.gz
  • Upload date:
  • Size: 35.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for homeassistant_api-5.0.3.tar.gz
Algorithm Hash digest
SHA256 47f4ba45a997cd52e43b38c56191504ea79b8456b4f2177a15190ab1eead3214
MD5 fc0b4c55c6b8a5a207ea140ce3fcd946
BLAKE2b-256 31da037a3d2a88d51370bc9a14a5c394bed06128420de267d0ff5fb9aa8f43c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for homeassistant_api-5.0.3.tar.gz:

Publisher: python-publish.yml on GrandMoff100/HomeAssistantAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file homeassistant_api-5.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for homeassistant_api-5.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b8c76accd0c149992dfff5b86d91900daeae73f9e7ea51ad1ebabdcb6385f7ff
MD5 f2abd9bb47d551d037a2ecc9e658a54f
BLAKE2b-256 b74162732cdbba46abb81e61374481cc11ee72ad03f07d3c261fd95e610d8caf

See more details on using hashes here.

Provenance

The following attestation bundles were made for homeassistant_api-5.0.3-py3-none-any.whl:

Publisher: python-publish.yml on GrandMoff100/HomeAssistantAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page