Skip to main content

Control Hubitat Maker API

Project description

hubitat_maker_api_client

This library facilitates access to Hubitat's Maker API. A key innovation is the HubitatCachingClient, which is capable of maintaining a cache of all your devices in a data store of your choice. This can allow you to query device state more efficiently than using the Maker API directly. HubitatCachingClient can be attached to a process that listens to Hubitat's /eventsocket to update the cached device states in real time.

Quick Start

Install

pip install hubitat-maker-api-client

This sample code demonstrates how to configure a HubitatCachingClient using your HOST, APP_ID, ACCESS_TOKEN and HUB_ID along with your custom implementation of DeviceCache.

from hubitat_maker_api_client import DeviceCache, HubitatAPIClient, HubitatCachingClient


class YourDeviceCache(DeviceCache):
   # Override methods for reading and writing
   # device state to your own datastore


_api_client = HubitatAPIClient(
    host=<HOST>,
    app_id=<APP_ID>,
    access_token=<ACCESS_TOKEN>,
    hub_id=<HUB_ID>,
)

client = HubitatCachingClient(
    api_client=_api_client,
    device_cache=YourDeviceCache(),
)


for switch in client.get_on_switches():
    client.turn_off_switch(switch)
    print(f'Turned off {switch}')

This sample code demonstrates how to update device state on your HubitatCachingClient by listening to Hubitat's /eventsocket.

import asyncio
import websockets
from hubitat_maker_api_client import HubitatEvent

async def listen(uri: str) -> None:
    async with websockets.connect(uri) as websocket:
        while True:
            message = await websocket.recv()
            event = HubitatEvent(json.loads(message))
            client.update_from_hubitat_event(event)

asyncio.get_event_loop().run_until_complete(listen('ws://<HOST_IP>/eventsocket'))

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

hubitat_maker_api_client-0.2.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hubitat_maker_api_client-0.2.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file hubitat_maker_api_client-0.2.0.tar.gz.

File metadata

  • Download URL: hubitat_maker_api_client-0.2.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.11.4 Linux/6.5.0-25-generic

File hashes

Hashes for hubitat_maker_api_client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a19f9e61ef14ae055cb612c26fc156c8789bdaf4206c608b66b4a9ac5a12db3a
MD5 e9a588c7a5f4d6e4f96e3631a91510a7
BLAKE2b-256 ead79068d783d77bb136aa9bc4e61c47d6fe3d075a8ace0b2134f7ea0ce6a720

See more details on using hashes here.

File details

Details for the file hubitat_maker_api_client-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hubitat_maker_api_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c284c0742872d58c99cd158650c712b6e47bd6b261807b35d5df6e9f6bd71220
MD5 dcd599b510ab2e855389d70d0281264f
BLAKE2b-256 51ff862512703ce70c0371c3a3574c4aaca8e645ab04203fcf73b8dba9e2d066

See more details on using hashes here.

Supported by

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