dorkhub

HomeAssistantAPI

Python Wrapper for Homeassistant's REST API

HomeAssistant-API
Python10428 forksGPL-3.0updated 2 months ago
visit the demogit clone https://github.com/HomeAssistant-API/HomeAssistantAPI.gitHomeAssistant-API/HomeAssistantAPI

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:
    client.trigger_service('light', 'turn_on', entity_id="light.living_room")

All four client classes share the same method names. The async clients (AsyncClient, AsyncWebsocketClient) use async def methods that you await.

import asyncio
from homeassistant_api import AsyncClient

async def main():
    async with AsyncClient(
        '<REST API Server URL>', # i.e. 'http://homeassistant.local:8123/api/'
        '<Your Long Lived Access-Token>',
    ) as client:
        await client.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:
    ws_client.trigger_service('light', 'turn_on', entity_id="light.living_room")

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.

more like this

meine

meine 🌒 - A CLI file manager and system utility built with Textual. It combines intuitive command parsing with rich t…

Python50

taskbutler

Create and add progress bars, Office365 Files and Dropbox Paper papers by labels and link them to your Todoist tasks.

Python50

search

search projects, people, and tags