Python Wrapper for Homeassistant's REST API
Project description
HomeassistantAPI
Python Wrapper for Homeassistant's REST API
Please ⭐️ the repo if you find this project useful or cool!
For contributing guidelines see towards the bottom.
from homeassistant_api import Client
client = Client(
'<API URL>',
'<Long Lived Access Token>'
)
client.get_domains().cover.open_garage(entity_id='cover.my_garage_door')
Installation
There are a variety of ways to install this wrapper.
Using pip
from PYPI
$ pip install homeassistant_api
Using Source from GitHub
$ git clone https://github.com/GrandMoff100/HomeassistantAPI
$ cd HomeassistantAPI
$ python setup.py install
Setup
Hardware
Before using this library, you need to have Homeassistant OS running on a device. Something like a Rasberry Pi or spare laptop.
Enable api
integration on Homeassistant
This library requires that you enable the api
integration on your Homeassistant if you are familiar with setting up integrations.
Access Token
Then once you have done that you need to head over to your profile and set up a "Long Lived Access Token" for you feed to the script. A good guide on how to do that is here
Exposing Homeassistant to the Web
You may want to setup a DNS server like DuckDNS (a good youtube tutorial on how to do that here, or port forwarding your homeassistant (if you are feeling adventurous) Both options will allow you to access your Homeassistant remotely. All you will have to change is telling your script where to find your api (a.k.a. the base api endpoint)
Usage
Once you have setup the api
integration and created a Long Lived Access Token, its time to feed these into the script.
See example.py
import os
from homeassistant_api import Client
# Tell the script where your homeassistant api server is, by typing it into the string in place of `<HOMEASSISTANT_API_ENDPOINT>`
url = '<HOMEASSISTANT_API_ENDPOINT>') # http://localhost:8123/api or https://myhomeassistant.duckdns.com:8123/api
# Copy and paste your long lived access token into the string in place of `<HOMEASSISTANT_TOKEN>`
token = '<HOMEASSISTANT_TOKEN>') # ey816najgfjassf...
client = Client(url, token)
servicedomains = client.get_services()
print(servicedomains)
# This assumes you have an actual light in your living room hooked up to homeassistant
servicedomains.light.services.turn_off.trigger(entity_id='light.living_room') # Sends a request to turn off the living room light
Contributing
We welcome contributions very warmly. If you have an idea or some code you want to add to the project please fork this repository, make your changes, and open a pull request. Most likely your changes will get merged if your code passes flake8 without any errors, and adds some functionality to the project. We'd love to incorporate your unique ideas and perspective!
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
Hashes for HomeAssistant API-2.0.0rc0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd73ba3cefe727ee8a080899c701c9d5cd2a449a3139c5a8d087a15bce08d562 |
|
MD5 | 9f4a21f85028bed2d27f356661e28179 |
|
BLAKE2b-256 | 1b5ca8a759ee41ff5b38532543481e79bed52dc588027c283f1c7f524170aa5e |
Hashes for HomeAssistant_API-2.0.0rc0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc1c449933657303a5acd76899f0800b114437ae2ba80b71ce86de20538fecc3 |
|
MD5 | b0cd6fc54d30ff0df03006d15d06593a |
|
BLAKE2b-256 | 647d717580b1b838b9eb9417290af3a37c45a0132a60e2c331c3d190722b6dd5 |