Entity discovery

From markusleben/ha-nova · View interactive version

Entity discovery is an AI agent skill from the GitHub repository markusleben/ha-nova. Use when searching or resolving Home Assistant entities by name, room, or domain through HA NOVA Relay, and live state snapshots across a domain — what is open, on, running, locked, who is home, averages and totals right now.

How to use this skill

Skill file

HA NOVA Entity Discovery

Scope

Use for:

Read-only behavior.

Bootstrap (once per session)

Read and follow ../ha-nova/session-bootstrap.md.

Relay Contract

Use file-based relay requests by default:

Flow

Step 1: Resolve a name — `ha-nova find`

ha-nova find "<the user's phrase>" [--domain <d>] [--area <area_id>] [--state <s>] [--limit 20]
ha-nova find --domain <d> [--area <area_id>] [--state <s>]

Every word of the phrase must match the entity_id, name, or area,

case- and accent-insensitive; aliases are read automatically when names miss.

The result carries total (exact), returned, and matches[] with each

match basis (by: name, alias, or state for unregistered).

Step 1b: Bulk inventory — raw relay

find matches phrases; prefix, label, and domain-count inventories use the

relay. For bulk selectors, follow ../ha-nova/bulk-patterns.md.

For domain counts or domain shortlists:

Entity registry uses compact abbreviated keys: ei=entity_id, en=name, ai=area_id.

Create <payload-file> with {"type":"config/entity_registry/list_for_display"}, then run:

ha-nova relay ws --data-file <payload-file> --jq-file <filter-file>

Write <filter-file> by copying the canonical ../ha-nova/discovery-filter.jq

and replacing KEYWORD with the pattern; if the canonical file is unavailable

(flat-copy installs), recreate it with exactly:

[.data.entities[] | select((.ei + " " + (.en // "")) | test("KEYWORD";"i")) | {entity_id: .ei, name: .en, area_id: .ai}]
| {total: length, shown: (.[0:20] | length), omitted: ([length - 20, 0] | max), truncated: (length > 20), matches: .[0:20]}

It returns {total, shown, omitted, truncated, matches} — the 20-row cap

applies to matches only; the counts are exact. This generic filter is for free-text search, not explicit prefix matching;

an explicit prefix selector matches the suffix and display name with startswith(...).

Fail closed on truncation: while truncated is true the result proves neither absence nor uniqueness — narrow until truncated is false before concluding either.

Never dump entire domains without a user-intent keyword, and never show an unfiltered full-registry dump.

When the task is multi-target inventory:

Step 2: Get state or config — `ha-nova get`

ha-nova get <entity_id>              # state and attributes
ha-nova get <entity_id> --config     # automation/script/scene config, resolved by unique_id, never the slug
ha-nova get <entity_id> --related    # search/related for the entity
ha-nova history <entity_id> [--since 24h] [--logbook]   # recent changes, summarized

Step 3: Find automations related to a device or area

Automations rarely have reliable direct area_id data in the compact registry. When user asks "automations for X in room Y":

  1. Resolve room name to area_id:

ha-nova relay ws --data-file <payload-file> then filter by name with --jq

  1. Query the area directly:

{"type":"search/related","item_type":"area","item_id":"<area_id>"}

  1. Treat the response as a keyed object, not an array:
  1. If automation/script keys are absent and only area entities are present, use search/related on those entities to derive the automation/script shortlist:

```text

ha-nova relay ws --data-file <payload-file>

```

Step 4: Return shortlist

Device-sibling capability discovery

A capability-oriented request (restart, identify, calibrate, reset, siren, ...) on a resolved entity or device, where the capability is not on the resolved entity itself, is answered by the device's OTHER entities — not by "the entity cannot do that":

  1. Resolve the physical device: for an entity target, read its registry row (WS config/entity_registry/get) and take its device_id; a target already resolved AS a device (a device-registry row or config-entry device) supplies its device_id directly — no entity row is required to proceed.
  2. List ALL registry entities of that device from the FULL registry (config/entity_registry/list, filter by device_id) — list_for_display omits disabled entities, and the registry row's disabled_by decides enabled/disabled status. NEVER validate a disabled candidate through /api/states: it has no state there, and its absence proves nothing about the capability. The 20-row display envelope does NOT apply: capping could hide the one capability past the cap.
  3. Select by domain, device_class, translation_key, and entity_id semantics on the SAME device. An entity on another device never qualifies merely because its name matches.
  4. Prefer an enabled exact match. Multiple plausible candidates → ONE bounded clarification listing each candidate by name, device, and whether it is disabled (entity ID only on a name clash).
  5. Report a disabled candidate as available-but-disabled WITH its disabled_by source and offer the matching enable flow via ha-nova:organize (a "device"-disabled sibling needs its parent DEVICE re-enabled, not the entity alone; "integration" (off by default) enables like "user"; "config_entry" follows its integration (ha-nova:integration-setup)). Never enable anything automatically, and never press or execute from discovery — hand off to the owning skill.

This contract is generic — never hard-coded to a brand, to cameras, or to restart buttons.

State Snapshot Queries

"is everything closed?", "who is home?", "what is running right now?" — these ask

about STATE across many entities, not about finding one. They are reads and

belong here; ha-nova:health answers what is broken, not what is on.

An average, total, or highest value right now: computed-answers.md (one template render, read-only).

By domain and state: ha-nova find --domain light --state on (rows carry the current

state); a second find with --state unavailable (and

unknown) fills the third bucket. A

device_class filter needs one raw read, ha-nova relay core --method GET --path /api/states --out <result-file>,

filtered by domain, device_class, and state:

[.data.body[]
 | select(.attributes.device_class == "window" and .state == "on")
 | {e: .entity_id, n: .attributes.friendly_name}]

Three answers, not two: yes / no / could not tell. An entity that is

unknown or unavailable, and one that is readable but does not report the

thing being asked, both go in the third bucket and get named. "Everything is

closed" with three sensors offline is false reassurance — "none open, 3 could

not be read" is the honest form.

Count group helpers separately: a Light Group is a real light.* entity

beside its members, so it double-counts. find marks one group: true; raw reads

show an attributes.entity_id array.

(switch_as_x mirrors double-count too and carry no such marker; say so if

the count looks high.)

window/door/garage_door/opening (the generic contact class) in state

on, AND cover.* in open/opening/closing (mid-close is still open)

with the COVER classes, which are named differently: garage — not the

binary sensor's garage_door — plus door, window, gate. A motorized

window is a cover, not a binary_sensor, so checking one family answers the

question wrong. A cover in those states whose device_class is absent or

outside that list is not evidence of closed: report it as "N open, class

unknown". Do NOT do the same for unclassed binary sensors — one is

indistinguishable from a motion sensor and would manufacture false alarms.

unknown/unavailable is away, including a named zone like work: those

are zone names, not errors. unknown means no tracker had usable data —

third bucket, because "nobody is home" from a dropped phone is how an alarm

gets armed on someone. (This skill owns person STATE reads; ha-nova:admin

owns creating and editing them.)

unavailable/unknown, AND binary_sensor with device_class: lock in

state on, which reports on for UNLOCKED — the reverse of every other

class here. Name the state each one is in rather than flattening them to

"unlocked": jammed and mid-travel are not secured, and they are what a user

needs to hear.

(a Harmony-style remote in on means an AV activity is live);

media_player in anything but off/standby/unavailable/unknown

(paused and idle are not off; standby IS — Home Assistant core deprecates

it as meaning off-or-idle, and users call that TV off);

binary_sensor with device_class running or moving in on;

script in on and automation with attributes.current > 0 — both are

actually executing, and the RUNNING list counts them, so leaving them out

here would let "is everything off?" say yes to something "what is running?"

names in the same breath;

climate/water_heater/humidifier in any state but

off/unavailable/unknown — an unreachable one is not off, it goes in

the third bucket;

vacuum and lawn_mower in cleaning/mowing/returning/paused/error

— error means stranded mid-floor, not put away, and it is readable so the

unavailable rule never catches it; valve in open/opening/closing;

cover only in opening/closing — a cover left open is answered by the

open-windows question above, not by this one, because it consumes nothing.

keep that invariant when either list changes. Same lights, switches, fans,

sirens and binary_sensor running, plus device_class: moving; but

media_player only in playing/buffering; vacuum/lawn_mower only in

cleaning/mowing/returning (report error as stuck, not as running);

valve in open/opening/closing; cover in opening/closing only —

a motor turning is running, a cover left open is not.

(heating, cooling, drying, fan, preheating, defrosting).

PRESENT and not off/idle.

mode (eco, performance, heat_pump, ...), which reports enablement and

never activity. It can never be proven running: enabled goes in the third

bucket, never in "nothing is running".

thermostats never publish one, and "nothing is running" while the heat pump

runs is the failure this whole section exists to prevent.

is "47 things are running". Its real running signal is

attributes.current > 0. script in on does mean running.

Answer count-first ("2 windows open: kitchen, bathroom"), then the names, in the List

Frame. This is a summary, not the banned domain dump. A follow-up "and which are

closed?" is a fresh read, not a cached list.

Matching Rules

If ambiguity remains: present top candidates (max 10) and state the match basis for each (name, alias, area; the id only if it alone matched) — the user must see WHY a candidate matched; then ask one selection question.

Output Format

Apply ../ha-nova/output-rules.md: plain words, HA names verbatim; unless asked or names clash, no ids, "entity", modes, Relay/HA URLs, snapshots, raw JSON.

Render the Step 4 shortlist as the List Frame (output-cards.md). Never dump raw states.

Safety

Guardrails

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.