How do jobs flow from hAPI to Home Assistant on the home network, and results back? Choose the mechanism (RabbitMQ, MQTT broker, HTTP job polling, direct call over the private link, etc.), where the broker (if any) runs, delivery/acknowledgement semantics, and how HA authenticates. Note: if the home network is joined to the cluster privately, the NAT-traversal reason for HA polling weakens.
Part of #44
## Question
How do jobs flow from hAPI to Home Assistant on the home network, and results back? Choose the mechanism (RabbitMQ, MQTT broker, HTTP job polling, direct call over the private link, etc.), where the broker (if any) runs, delivery/acknowledgement semantics, and how HA authenticates. Note: if the home network is joined to the cluster privately, the NAT-traversal reason for HA polling weakens.
Constraint from How is hAPI reachable on the network? (ADR-0002): the home network is behind CGNAT, so traffic only ever starts from home. hAPI can't call HA's REST/WebSocket API, and the bridge must be one HA connects out to: polling, or MQTT to a public broker. A public broker is allowed if it's TLS-only with per-Principal auth. Note that HA can present a client cert only over MQTT.
Constraint from [How is hAPI reachable on the network?](https://git.bobbypalko.com/bobby/hapi/issues/45) ([ADR-0002](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0002-network-exposure.md)): the home network is behind CGNAT, so **traffic only ever starts from home**. hAPI can't call HA's REST/WebSocket API, and the bridge must be one HA connects out to: polling, or MQTT to a public broker. A public broker is allowed if it's TLS-only with per-Principal auth. Note that HA can present a client cert only over MQTT.
Note from How do Principals authenticate, and what may each do? (ADR-0005): HA authenticates as a Bot with an opaque Token. It gets Household access through Household grants and Personal access through per-domain Bindings. Scopes are <domain>:read|write plus health. This ticket decides whether consuming the job queue needs its own Scope (for example jobs) or falls under smart_home:*.
Note from [How do Principals authenticate, and what may each do?](https://git.bobbypalko.com/bobby/hapi/issues/54) (ADR-0005): HA authenticates as a Bot with an opaque Token. It gets Household access through Household grants and Personal access through per-domain Bindings. Scopes are `<domain>:read|write` plus `health`. This ticket decides whether consuming the job queue needs its own Scope (for example `jobs`) or falls under `smart_home:*`.
bobby
self-assigned this 2026-11-24 11:10:17 -05:00
HA polls hAPI for Jobs that name allowlisted HA scripts. Full record: ADR-0006. New glossary term: Job.
Transport: HA's built-in rest sensor polls GET /v1/smart_home/jobs/next every 15–30 s. An automation runs the Job and then rest_commands POST /v1/smart_home/jobs/{id}/result, followed by update_entity so a backlog drains quickly. There's no broker, no new public surface, and no custom integration. MQTT (Mosquitto) is the upgrade path if real-time Jobs ever matter. Jobs tolerate about 30 s of latency; real-time control stays in HA's own app.
Job: Household data, created by domain code, Persons, or Bots. A Job names an HA script (hapi_[a-z0-9_]+) plus variables (≤16 KB), and HA only runs script.hapi_*. hAPI keeps no script catalogue.
Timing:not_before is optional. expires_at defaults to 1 h after not_before (or after creation).
Delivery: at-least-once, FIFO, with a 2-minute lease and 3 attempts before the Job becomes failed (no_result). States are pending → succeeded | failed | expired | cancelled. Scripts must be idempotent.
Result:{status, error?, response?}. The first result wins, and a later one gets 409. Any Household member, or any Bot with smart_home:write, can cancel a pending Job. Finished Jobs are kept for 90 days and purged by hapi jobs purge until scheduling exists.
Auth: the home-assistant Bot holds a Household grant of smart_home:write. There's no jobs Scope. Its Token lives in HA's secrets.yaml.
HA side: a reference package lives at integrations/home-assistant/hapi_jobs.yaml and is copied in by hand. The hapi_* scripts live in a separate HA config repo.
This bridge carries only Jobs and results. HA → hAPI data goes to ordinary domain endpoints.
Handed off: HA's last-poll timestamp, to be turned into a stall alert, goes to How are health, logs, and metrics exposed and collected?. "Notify when a Job fails or expires" goes to the Notifications fog.
## Resolution
**HA polls hAPI for Jobs that name allowlisted HA scripts.** Full record: [ADR-0006](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0006-home-assistant-job-polling.md). New glossary term: **Job**.
- **Transport:** HA's built-in `rest` sensor polls `GET /v1/smart_home/jobs/next` every 15–30 s. An automation runs the Job and then `rest_command`s `POST /v1/smart_home/jobs/{id}/result`, followed by `update_entity` so a backlog drains quickly. There's no broker, no new public surface, and no custom integration. MQTT (Mosquitto) is the upgrade path if real-time Jobs ever matter. Jobs tolerate about 30 s of latency; real-time control stays in HA's own app.
- **Job:** Household data, created by domain code, Persons, or Bots. A Job names an HA script (`hapi_[a-z0-9_]+`) plus variables (≤16 KB), and HA only runs `script.hapi_*`. hAPI keeps no script catalogue.
- **Timing:** `not_before` is optional. `expires_at` defaults to 1 h after `not_before` (or after creation).
- **Delivery:** at-least-once, FIFO, with a 2-minute lease and 3 attempts before the Job becomes `failed` (`no_result`). States are `pending → succeeded | failed | expired | cancelled`. Scripts must be idempotent.
- **Result:** `{status, error?, response?}`. The first result wins, and a later one gets `409`. Any Household member, or any Bot with `smart_home:write`, can cancel a pending Job. Finished Jobs are kept for 90 days and purged by `hapi jobs purge` until scheduling exists.
- **Auth:** the `home-assistant` Bot holds a Household grant of `smart_home:write`. There's no `jobs` Scope. Its Token lives in HA's `secrets.yaml`.
- **HA side:** a reference package lives at `integrations/home-assistant/hapi_jobs.yaml` and is copied in by hand. The `hapi_*` scripts live in a separate HA config repo.
- **This bridge carries only Jobs and results.** HA → hAPI data goes to ordinary domain endpoints.
- **Handed off:** HA's last-poll timestamp, to be turned into a stall alert, goes to *How are health, logs, and metrics exposed and collected?*. "Notify when a Job fails or expires" goes to the Notifications fog.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Part of #44
Question
How do jobs flow from hAPI to Home Assistant on the home network, and results back? Choose the mechanism (RabbitMQ, MQTT broker, HTTP job polling, direct call over the private link, etc.), where the broker (if any) runs, delivery/acknowledgement semantics, and how HA authenticates. Note: if the home network is joined to the cluster privately, the NAT-traversal reason for HA polling weakens.
Constraint from How is hAPI reachable on the network? (ADR-0002): the home network is behind CGNAT, so traffic only ever starts from home. hAPI can't call HA's REST/WebSocket API, and the bridge must be one HA connects out to: polling, or MQTT to a public broker. A public broker is allowed if it's TLS-only with per-Principal auth. Note that HA can present a client cert only over MQTT.
Note from How do Principals authenticate, and what may each do? (ADR-0005): HA authenticates as a Bot with an opaque Token. It gets Household access through Household grants and Personal access through per-domain Bindings. Scopes are
<domain>:read|writeplushealth. This ticket decides whether consuming the job queue needs its own Scope (for examplejobs) or falls undersmart_home:*.Resolution
HA polls hAPI for Jobs that name allowlisted HA scripts. Full record: ADR-0006. New glossary term: Job.
restsensor pollsGET /v1/smart_home/jobs/nextevery 15–30 s. An automation runs the Job and thenrest_commandsPOST /v1/smart_home/jobs/{id}/result, followed byupdate_entityso a backlog drains quickly. There's no broker, no new public surface, and no custom integration. MQTT (Mosquitto) is the upgrade path if real-time Jobs ever matter. Jobs tolerate about 30 s of latency; real-time control stays in HA's own app.hapi_[a-z0-9_]+) plus variables (≤16 KB), and HA only runsscript.hapi_*. hAPI keeps no script catalogue.not_beforeis optional.expires_atdefaults to 1 h afternot_before(or after creation).failed(no_result). States arepending → succeeded | failed | expired | cancelled. Scripts must be idempotent.{status, error?, response?}. The first result wins, and a later one gets409. Any Household member, or any Bot withsmart_home:write, can cancel a pending Job. Finished Jobs are kept for 90 days and purged byhapi jobs purgeuntil scheduling exists.home-assistantBot holds a Household grant ofsmart_home:write. There's nojobsScope. Its Token lives in HA'ssecrets.yaml.integrations/home-assistant/hapi_jobs.yamland is copied in by hand. Thehapi_*scripts live in a separate HA config repo.