Python Wrapper for Homeassistant's REST API
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
Before using this library, you need to have Homeassistant OS running on a device. Something like a Rasberry Pi or spare laptop.
This library requires that you enable the api
integration on your Homeassistant if you are familiar with setting up integrations.
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
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)
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