Asynchronous Home Assistant Supervisor Client

0.4.3 · active · verified Thu Apr 16

aiohasupervisor is an asynchronous Python client designed for interfacing with the Home Assistant Supervisor's REST API. It is currently at version 0.4.3 and is actively maintained, with a release cadence tied to the development and releases of Home Assistant itself, as it's primarily used within the Home Assistant ecosystem, particularly by its Supervisor integration and add-ons.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `aiohasupervisor` client and fetch basic supervisor information. It expects the `SUPERVISOR_TOKEN` environment variable to be set, which is automatically handled when running as a Home Assistant add-on. For external development, the `SUPERVISOR_API_URL` should also be set, and a token obtained from the `remote_api` add-on.

import asyncio
import os
from aiohasupervisor.client import Client

async def get_supervisor_info():
    # The SUPERVISOR_TOKEN environment variable is automatically set for Home Assistant add-ons.
    # For remote development/testing, use the remote_api add-on to get a token and set SUPERVISOR_API_URL.
    supervisor_token = os.environ.get('SUPERVISOR_TOKEN', 'YOUR_SUPERVISOR_TOKEN')
    supervisor_api_url = os.environ.get('SUPERVISOR_API_URL', 'http://supervisor/core') # Default for add-ons

    if supervisor_token == 'YOUR_SUPERVISOR_TOKEN':
        print("Warning: SUPERVISOR_TOKEN not set. This example may not work without a valid token.")
        print("Please refer to the aiohasupervisor GitHub for development setup with remote_api add-on.")
        return

    async with Client(supervisor_api_url, supervisor_token) as client:
        try:
            info = await client.info()
            print("Supervisor Info:", info)
        except Exception as e:
            print(f"Error fetching Supervisor info: {e}")

if __name__ == "__main__":
    asyncio.run(get_supervisor_info())

view raw JSON →