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.
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 you changes, and open a pull request. Most likely your changes wil get merged if your code passes flake8 without any errors, and adds some functionality to the project. We'd love to see your 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-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eba2dbdfba85ee58ac2b2a0abc6d23ba7e9b5b2853a814bf3be330cf7f76eca5 |
|
MD5 | 6903653971bdfb52600fa5bd53a53d02 |
|
BLAKE2b-256 | 102f3b67b03fbcfa02adaa101b1f4d17c712c1ae61a570ccdf2fa630c858998e |