Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

HomeAssistant API-0.1.1.post2.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distribution

HomeAssistant_API-0.1.1.post2-py3-none-any.whl (12.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page