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.
Here is a quick example.
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(...)
).
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!!
This project is under the GNU GPLv3 license, as defined by the Free Software Foundation.