Skip to main content

hassstuff

Home Assistant over REST and WebSocket: thin typed clients (somestuff.hassstuff.client) and a CLI (hass-api, or python -m somestuff.hassstuff). The WebSocket API covers what REST does not expose: entity/device/area registry, helpers, Lovelace dashboards, traces.

hass-api --help
hass-api <command> --help

Connection

Option Env Default
--url HASS_URL content of homeassistant_url.local.txt, otherwise http://homeassistant.local:8123
--token HASS_TOKEN –
--token-file HASS_TOKEN_FILE homeassistant_token.local.txt
--insecure – TLS is verified
--timeout – 30 seconds

Both *.local.txt files are searched in the current directory and every parent directory, each also under secrets.local/. --token wins over --token-file. Global options go before the command: hass-api --url https://… --token abc states.

Commands

Command API Purpose
info REST + WS Version, user, admin flag
states [PATTERN] [--domain D] [--json] REST States, pattern = substring or glob on ID/name
state ENTITY [--yaml] REST Full state object
call DOMAIN.SERVICE [k=v …] [--data JSON] REST Service call, --return-response for responses
template 'JINJA' REST Render a template server-side, - = stdin
history ENTITY … [--hours N] [--attributes] REST State history
logbook [ENTITY] [--hours N] REST Logbook including trigger (user, service, automation)
areas / devices [PATTERN] WS Areas, devices with area and model
entities [PATTERN] [--area A] [--platform P] WS Entity registry, area also inherited from the device
entity-update ENTITY [--name …] [--area …] … WS Name, icon, area, ID, enable/hide, labels
helper list|create|update|delete TYPE … WS input_*, counter, timer, schedule
automation list|get|put|delete REST UI automations, put shows a diff first
script list|get|put|delete REST UI scripts, as above
trace list [REF] / trace get REF [RUN_ID] REST + WS Run traces, without RUN_ID the latest run
dashboard list|get [URL_PATH]|save FILE [URL_PATH] WS Lovelace dashboards in storage mode
ws TYPE [k=v …] [--data JSON] WS Any WebSocket command

k=v values are parsed as JSON where possible (max=300, options='["a","b"]'), otherwise as text.

REF for automations/scripts: entity ID (automation.foo) or config ID. The config ID of an automation is its id attribute, not the part after automation.; automation list shows both.

Examples

hass-api entities --area Kitchen
hass-api logbook light.kitchen --hours 2          # who switched it?
hass-api trace get automation.morning_lights --yaml
hass-api automation get morning_lights --yaml > /tmp/a.yaml
hass-api automation put morning_lights /tmp/a.yaml --dry-run
hass-api helper create input_number name="Target" min=0 max=300 step=5 unit_of_measurement=°C
hass-api entity-update sensor.foo --area Kitchen --name "Kitchen temperature"
hass-api call logger.set_level homeassistant.components.mqtt=debug
hass-api dashboard get my-dashboard --yaml > /tmp/d.yaml
hass-api dashboard save /tmp/d.yaml my-dashboard --dry-run
hass-api ws config/label_registry/list

Library

from somestuff.hassstuff.client import HassConfig, HassRest, HassWebSocket, default_token_file, default_url, load_token

config = HassConfig(url=default_url(), token=load_token(None, default_token_file()))

with HassRest(config) as rest, HassWebSocket(config) as ws:
    print(rest.state("sun.sun").get("state"))
    for entry in ws.entity_registry():
        if entry.get("platform") == "mqtt":
            print(entry.get("entity_id"))

get, post and call return the full JsonValue union. The methods below check the shape at runtime and raise HassError (with the path or command in the message) if it does not match.

Method Returns Checks
HassRest.get_list(path, params) list[JsonObject] list, every element an object
HassRest.get_object(path, params) JsonObject object
HassRest.post_object(path, body, params) JsonObject object
HassRest.states() list[State] as get_list
HassRest.state(entity_id) State as get_object
HassWebSocket.call_list(msg_type, **payload) list[JsonObject] list, every element an object
HassWebSocket.call_object(msg_type, **payload) JsonObject object
HassWebSocket.entity_registry() list[EntityRegistryEntry] as call_list
HassWebSocket.device_registry() list[DeviceRegistryEntry] as call_list
HassWebSocket.area_registry() list[AreaRegistryEntry] as call_list
HassWebSocket.statistic_ids(statistic_type) list[StatisticMeta] as call_list

The typed methods narrow with cast after the shape check; fields are not validated. The TypedDicts live in somestuff.hassstuff.models and are re-exported from somestuff.hassstuff.client. All are total=False, so read fields with .get(). mypy rejects an unknown key in entry["…"]; entry.get("…") with an unknown key is typed object, which only fails once the value is used as a concrete type.

Type Source
Context context of a State
State REST /api/states
EntityRegistryEntry WS config/entity_registry/list
DeviceRegistryEntry WS config/device_registry/list
AreaRegistryEntry WS config/area_registry/list
StatisticMeta WS recorder/list_statistic_ids

Limits

  • put/save replace the whole object. First get, then edit, then put (without --dry-run).
  • delete asks for confirmation, --yes skips it.
  • Helpers created through config flows (template, utility meter, threshold, group …) do not go through helper, only through config_entries/flow (possible via ws, but multi-step).
  • YAML dashboards and hand-written automations in automations.yaml without id are not writable.

Metadata

Release files for somestuff-hassstuff 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for somestuff-hassstuff 0.2.0
File Size Uploaded Provenance Actions
somestuff_hassstuff-0.2.0.tar.gz 24.1 kB Without provenance Details for somestuff_hassstuff-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for somestuff-hassstuff 0.2.0
File Interpreter ABI Platform Actions
somestuff_hassstuff-0.2.0-py3-none-any.whl Python 3 none any Details for somestuff_hassstuff-0.2.0-py3-none-any.whl

Total release size: 46.8 kB

Release files / somestuff_hassstuff-0.2.0.tar.gz

Download URL somestuff_hassstuff-0.2.0.tar.gz
Size 24.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c0380b9162383665fd54c5198be3ea72a0838c8c11f0dc4aadee979a5b330818
BLAKE2b-256 checksum
How to use checksums
0924a806ad09261e7c2d1c4af47f0da03c551d44f0bed715bae52af6da8c51d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.18.2 {"ci":null,"cpu":"x86_64","distro":{"id":"resolute","libc":{"lib":"glibc","version":"2.43"},"name":"Ubuntu","version":"26.04"},"implementation":{"name":"CPython","version":"3.14.4"},"installer":{"name":"hatch","version":"1.18.2"},"openssl_version":"OpenSSL 3.5.5 27 Jan 2026","python":"3.14.4","system":{"name":"Linux","release":"7.3.5-custom"}} HTTPX2/2.16.0

Release files / somestuff_hassstuff-0.2.0-py3-none-any.whl

Download URL somestuff_hassstuff-0.2.0-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b2c3bf725941d491f39fd85e70dd03316538d1b5567dc4030a36ff77d307ca4
BLAKE2b-256 checksum
How to use checksums
ad088f08e1a752737506f2f14cefc2b87e44f17a02809a50447809d914d68f76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.18.2 {"ci":null,"cpu":"x86_64","distro":{"id":"resolute","libc":{"lib":"glibc","version":"2.43"},"name":"Ubuntu","version":"26.04"},"implementation":{"name":"CPython","version":"3.14.4"},"installer":{"name":"hatch","version":"1.18.2"},"openssl_version":"OpenSSL 3.5.5 27 Jan 2026","python":"3.14.4","system":{"name":"Linux","release":"7.3.5-custom"}} HTTPX2/2.16.0

Security for somestuff-hassstuff 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page