homeassistant

Data source reading entity states from the Home Assistant REST API.

Attributes

Classes

HomeAssistantSource

Reads the configured entities, one REST request each.

Functions

parse_catalog(text)

Catalog entries from the rendered template, sorted by name.

parse_state(state)

Convert a Home Assistant state string to int, float, str or None.

Module Contents

homeassistant.CATALOG_DOMAINS = ('sensor', 'binary_sensor', 'weather', 'climate', 'cover', 'lock', 'person', 'device_tracker',...
homeassistant.parse_catalog(text)

Catalog entries from the rendered template, sorted by name.

homeassistant.parse_state(state)

Convert a Home Assistant state string to int, float, str or None.

class homeassistant.HomeAssistantSource(http_get, base_url, token, entities, http_post=None)

Reads the configured entities, one REST request each.

http_get(url, headers) returns (status, parsed JSON or None) and raises OSError when the server cannot be reached; http_post(url, headers, payload) sends JSON and returns (status, text or None). entities maps reading keys to entity IDs, e.g. {“office_temperature”: “sensor.arbeitszimmer_temperatur”}.

read()

Read all configured entities.

With http_post this is one template request (much faster on the board), otherwise one GET per entity.

Returns:

A reading per configured key, in the format of datasource.

Raises:

OSError – If Home Assistant cannot be reached.

catalog()

List what can be shown on a tile.

Returns:

[{"id", "name", "unit", "style"}], see datasource.

Raises:

OSError – If Home Assistant cannot be reached.

alerts(ids)

Return the active alerts among ids, in one request.

Parameters:

ids – Entity IDs to check.

Returns:

Active alerts in the format of alerts.

Raises:

OSError – If Home Assistant cannot be reached.