Python Wrapper for Homeassistant's REST API
Project description
HomeassistantAPI
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file homeassistant_api-5.0.2.post2.tar.gz.
File metadata
- Download URL: homeassistant_api-5.0.2.post2.tar.gz
- Upload date:
- Size: 35.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24ffbe43b626684cea07783b8d86fdecd37473bb17b7d45f763026a9af9a75fa
|
|
| MD5 |
dad9e974804d1d98ec14fb9f5ac2245b
|
|
| BLAKE2b-256 |
cc695bdae3b2719ce5947d8a405b1ad54a074488b2dd4c507a245b63f199148d
|
Provenance
The following attestation bundles were made for homeassistant_api-5.0.2.post2.tar.gz:
Publisher:
python-publish.yml on GrandMoff100/HomeAssistantAPI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
homeassistant_api-5.0.2.post2.tar.gz -
Subject digest:
24ffbe43b626684cea07783b8d86fdecd37473bb17b7d45f763026a9af9a75fa - Sigstore transparency entry: 779325650
- Sigstore integration time:
-
Permalink:
GrandMoff100/HomeAssistantAPI@d534286d9436683ad50b3dd00adfb2c0ed6e8dc7 -
Branch / Tag:
refs/tags/v5.0.2.post2 - Owner: https://github.com/GrandMoff100
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d534286d9436683ad50b3dd00adfb2c0ed6e8dc7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file homeassistant_api-5.0.2.post2-py3-none-any.whl.
File metadata
- Download URL: homeassistant_api-5.0.2.post2-py3-none-any.whl
- Upload date:
- Size: 45.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6707153b827de086fd684bda51a911ebb2ab7928a8d54299262dc8a1aaa5951
|
|
| MD5 |
6bdd25bb2ec70306132dc41726819024
|
|
| BLAKE2b-256 |
ee837f6a2718c02ac5c1a83209dc7ab85827b96c50add8fb4695b81bb7f82213
|
Provenance
The following attestation bundles were made for homeassistant_api-5.0.2.post2-py3-none-any.whl:
Publisher:
python-publish.yml on GrandMoff100/HomeAssistantAPI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
homeassistant_api-5.0.2.post2-py3-none-any.whl -
Subject digest:
f6707153b827de086fd684bda51a911ebb2ab7928a8d54299262dc8a1aaa5951 - Sigstore transparency entry: 779325651
- Sigstore integration time:
-
Permalink:
GrandMoff100/HomeAssistantAPI@d534286d9436683ad50b3dd00adfb2c0ed6e8dc7 -
Branch / Tag:
refs/tags/v5.0.2.post2 - Owner: https://github.com/GrandMoff100
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d534286d9436683ad50b3dd00adfb2c0ed6e8dc7 -
Trigger Event:
release
-
Statement type: