https://github.com/grandmoff100/homeassistantapi
Python Wrapper for Homeassistant's REST API
https://github.com/grandmoff100/homeassistantapi
aiohttp api async hacktoberfest home-assistant home-automation python requests rest rest-api
Last synced: 21 days ago
JSON representation
Python Wrapper for Homeassistant's REST API
- Host: GitHub
- URL: https://github.com/grandmoff100/homeassistantapi
- Owner: GrandMoff100
- License: gpl-3.0
- Created: 2021-03-14T22:42:03.000Z (about 4 years ago)
- Default Branch: dev
- Last Pushed: 2025-03-30T20:32:48.000Z (about 1 month ago)
- Last Synced: 2025-04-13T05:06:32.772Z (21 days ago)
- Topics: aiohttp, api, async, hacktoberfest, home-assistant, home-automation, python, requests, rest, rest-api
- Language: Python
- Homepage: https://homeassistantapi.readthedocs.io
- Size: 2.25 MB
- Stars: 75
- Watchers: 1
- Forks: 21
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: docs/CONTRIBUTING.rst
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# HomeassistantAPI
[](https://codecov.io/gh/GrandMoff100/HomeAssistantAPI)
[](https://pypistats.org/packages/homeassistant-api)

[](https://homeassistantapi.readthedocs.io/en/latest/?badge=latest)
[](https://github.com/GrandMoff100/HomeassistantAPI/releases)## Python wrapper for Homeassistant's [Websocket API](https://developers.home-assistant.io/docs/api/websocket/) and [REST API](https://developers.home-assistant.io/docs/api/rest/)
> Note: As of [this comment](https://github.com/home-assistant/architecture/discussions/1074#discussioncomment-9196867) the REST API is not getting any new features or endpoints.
> However, it is not going to be deprecated according to [this comment](https://github.com/home-assistant/developers.home-assistant/pull/2150#pullrequestreview-2017433583)
> But it is recommended to use the Websocket API for new integrations.### REST API Examples
```py
from homeassistant_api import Clientwith Client(
'', # i.e. 'http://homeassistant.local:8123/api/'
''
) 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(...)`).```py
import asyncio
from homeassistant_api import Clientasync def main():
with Client(
'', # i.e. 'http://homeassistant.local:8123/api/'
'',
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
```py
from homeassistant_api import WebsocketClientwith WebsocketClient(
'', # i.e. 'ws://homeassistant.local:8123/api/websocket'
''
) 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](https://homeassistantapi.readthedocs.io)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](https://github.com/GrandMoff100/HomeAssistantAPI/discussions)?
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.