@orellbuehler/homeassistant-mcp 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +142 -39
  2. package/bin/homeassistant-mcp.js +51 -0
  3. package/binaries/darwin-arm64/homeassistant-mcp +0 -0
  4. package/binaries/darwin-x64/homeassistant-mcp +0 -0
  5. package/binaries/linux-arm64/homeassistant-mcp +0 -0
  6. package/binaries/linux-x64/homeassistant-mcp +0 -0
  7. package/binaries/win32-x64/homeassistant-mcp.exe +0 -0
  8. package/package.json +5 -38
  9. package/dist/config.js +0 -26
  10. package/dist/hass/format.js +0 -38
  11. package/dist/hass/rest.js +0 -50
  12. package/dist/hass/ws.js +0 -80
  13. package/dist/index.js +0 -17
  14. package/dist/server.js +0 -9
  15. package/dist/tools/auth.js +0 -191
  16. package/dist/tools/automations.js +0 -62
  17. package/dist/tools/backup.js +0 -375
  18. package/dist/tools/control.js +0 -133
  19. package/dist/tools/dashboards.js +0 -206
  20. package/dist/tools/diagnostics.js +0 -537
  21. package/dist/tools/energy.js +0 -235
  22. package/dist/tools/entities.js +0 -57
  23. package/dist/tools/hacs.js +0 -52
  24. package/dist/tools/helpers.js +0 -98
  25. package/dist/tools/history.js +0 -57
  26. package/dist/tools/integrations.js +0 -538
  27. package/dist/tools/lists.js +0 -216
  28. package/dist/tools/organization.js +0 -548
  29. package/dist/tools/raw.js +0 -41
  30. package/dist/tools/registry.js +0 -195
  31. package/dist/tools/reload.js +0 -40
  32. package/dist/tools/resources.js +0 -56
  33. package/dist/tools/scripts.js +0 -206
  34. package/dist/tools/services.js +0 -33
  35. package/dist/tools/statistics.js +0 -363
  36. package/dist/tools/system.js +0 -57
  37. package/dist/tools/templates.js +0 -21
  38. package/dist/tools/trace.js +0 -74
  39. package/dist/tools/zha.js +0 -121
  40. package/dist/toolsets.js +0 -356
@@ -1,548 +0,0 @@
1
- import { z } from "zod";
2
- import { ok, err } from "../hass/format.js";
3
- const ASSISTANTS = ["conversation", "cloud.alexa", "cloud.google_assistant"];
4
- const ITEM_TYPES = [
5
- "area",
6
- "automation",
7
- "automation_blueprint",
8
- "config_entry",
9
- "device",
10
- "entity",
11
- "floor",
12
- "group",
13
- "integration",
14
- "label",
15
- "person",
16
- "scene",
17
- "script",
18
- "script_blueprint",
19
- ];
20
- const ENTITY_ID_PARTS = ["area", "device", "entity", "floor", "parent_device"];
21
- function defined(fields) {
22
- return Object.fromEntries(Object.entries(fields).filter(([, v]) => v !== undefined));
23
- }
24
- function buildUpdate(ids, fields) {
25
- const changes = defined(fields);
26
- if (Object.keys(changes).length === 0) {
27
- const names = Object.keys(fields)
28
- .map((k) => `'${k}'`)
29
- .join(", ");
30
- throw new Error(`Provide at least one of ${names} to update`);
31
- }
32
- return { ...ids, ...changes };
33
- }
34
- export function registerOrganizationTools(server, ws) {
35
- server.tool("create_area", "Create an area (room or location) in the area registry via the WebSocket API (config/area_registry/create) and return the new entry; the area_id is generated from the name. The name must not already be in use. Optionally place it on a floor (floor_id from list_floors), add voice aliases, an icon, labels (label_ids from list_labels — unknown ids are silently dropped, so check the returned 'labels'), a picture, and humidity/temperature sensor entity_ids (each must be an existing sensor entity with the humidity / temperature device class, otherwise HA rejects the call). This edits registry config only — it does not control any device.", {
36
- name: z.string().describe("Area name, e.g. 'Kitchen'"),
37
- floor_id: z
38
- .string()
39
- .optional()
40
- .describe("Floor to put the area on, as returned by list_floors"),
41
- aliases: z
42
- .array(z.string())
43
- .optional()
44
- .describe("Alternative names for the area (used by voice assistants)"),
45
- icon: z.string().optional().describe("Icon, e.g. 'mdi:silverware-fork-knife'"),
46
- labels: z.array(z.string()).optional().describe("label_id(s) to attach, from list_labels"),
47
- picture: z.string().optional().describe("Picture path or URL for the area"),
48
- humidity_entity_id: z
49
- .string()
50
- .optional()
51
- .describe("Humidity sensor shown for the area, e.g. 'sensor.kitchen_humidity'"),
52
- temperature_entity_id: z
53
- .string()
54
- .optional()
55
- .describe("Temperature sensor shown for the area, e.g. 'sensor.kitchen_temperature'"),
56
- }, async ({ name, floor_id, aliases, icon, labels, picture, humidity_entity_id, temperature_entity_id, }) => {
57
- try {
58
- const payload = {
59
- name,
60
- ...defined({
61
- floor_id,
62
- aliases,
63
- icon,
64
- labels,
65
- picture,
66
- humidity_entity_id,
67
- temperature_entity_id,
68
- }),
69
- };
70
- return ok(await ws.command("config/area_registry/create", payload));
71
- }
72
- catch (e) {
73
- return err(e);
74
- }
75
- });
76
- server.tool("update_area", "Update an area in the area registry via the WebSocket API (config/area_registry/update). Only the fields you pass are changed; pass null to clear floor_id, icon, picture, humidity_entity_id or temperature_entity_id. 'aliases' and 'labels' replace the whole list (unknown label_ids are silently dropped). At least one field besides area_id is required. This is how to rename an area or move it to another floor. This edits registry config only — it does not control any device. Returns the updated area entry.", {
77
- area_id: z.string().describe("Area to update, as returned by list_areas"),
78
- name: z.string().optional().describe("New area name"),
79
- floor_id: z
80
- .string()
81
- .nullable()
82
- .optional()
83
- .describe("Floor to move the area to, from list_floors; null removes it from its floor"),
84
- aliases: z.array(z.string()).optional().describe("Replacement list of alternative names"),
85
- icon: z.string().nullable().optional().describe("Icon, e.g. 'mdi:sofa'; null clears it"),
86
- labels: z
87
- .array(z.string())
88
- .optional()
89
- .describe("Replacement list of label_id(s), from list_labels"),
90
- picture: z.string().nullable().optional().describe("Picture path or URL; null clears it"),
91
- humidity_entity_id: z
92
- .string()
93
- .nullable()
94
- .optional()
95
- .describe("Humidity sensor entity_id; null clears it"),
96
- temperature_entity_id: z
97
- .string()
98
- .nullable()
99
- .optional()
100
- .describe("Temperature sensor entity_id; null clears it"),
101
- }, async ({ area_id, name, floor_id, aliases, icon, labels, picture, humidity_entity_id, temperature_entity_id, }) => {
102
- try {
103
- const payload = buildUpdate({ area_id }, {
104
- name,
105
- floor_id,
106
- aliases,
107
- icon,
108
- labels,
109
- picture,
110
- humidity_entity_id,
111
- temperature_entity_id,
112
- });
113
- return ok(await ws.command("config/area_registry/update", payload));
114
- }
115
- catch (e) {
116
- return err(e);
117
- }
118
- });
119
- server.tool("delete_area", "Delete an area from the area registry via the WebSocket API (config/area_registry/delete). Devices and entities assigned to the area lose their area assignment (area_id becomes null); they are not deleted. Cannot be undone. Use search_related with item_type 'area' first to see which devices, entities, automations and scripts reference it. This edits registry config only — it does not control any device.", {
120
- area_id: z.string().describe("Area to delete, as returned by list_areas"),
121
- }, async ({ area_id }) => {
122
- try {
123
- await ws.command("config/area_registry/delete", { area_id });
124
- return ok({ deleted: area_id });
125
- }
126
- catch (e) {
127
- return err(e);
128
- }
129
- });
130
- server.tool("reorder_areas", "Set the display order of areas in the area registry via the WebSocket API (config/area_registry/reorder). 'area_ids' must contain EVERY existing area_id exactly once, in the desired order — Home Assistant rejects partial lists, duplicates and unknown ids. Read the current ids with list_areas first. This edits registry config only.", {
131
- area_ids: z.array(z.string()).describe("All area_ids, in the new order"),
132
- }, async ({ area_ids }) => {
133
- try {
134
- await ws.command("config/area_registry/reorder", { area_ids });
135
- return ok({ reordered: true, area_ids });
136
- }
137
- catch (e) {
138
- return err(e);
139
- }
140
- });
141
- server.tool("list_floors", "List floors from the floor registry via the WebSocket API (config/floor_registry/list): floor_id, name, level, icon, aliases, created_at, modified_at. Areas are assigned to a floor through their floor_id (see list_areas, create_area, update_area).", {}, async () => {
142
- try {
143
- return ok(await ws.command("config/floor_registry/list"));
144
- }
145
- catch (e) {
146
- return err(e);
147
- }
148
- });
149
- server.tool("create_floor", "Create a floor in the floor registry via the WebSocket API (config/floor_registry/create) and return the new entry; the floor_id is generated from the name and the name must not already be in use. 'level' is an integer used to order floors (e.g. 0 for the ground floor, -1 for a basement). Assign areas to it afterwards with update_area. This edits registry config only.", {
150
- name: z.string().describe("Floor name, e.g. 'Ground floor'"),
151
- level: z.number().int().optional().describe("Floor level number, e.g. 0 or -1"),
152
- icon: z.string().optional().describe("Icon, e.g. 'mdi:home-floor-0'"),
153
- aliases: z
154
- .array(z.string())
155
- .optional()
156
- .describe("Alternative names for the floor (used by voice assistants)"),
157
- }, async ({ name, level, icon, aliases }) => {
158
- try {
159
- const payload = { name, ...defined({ level, icon, aliases }) };
160
- return ok(await ws.command("config/floor_registry/create", payload));
161
- }
162
- catch (e) {
163
- return err(e);
164
- }
165
- });
166
- server.tool("update_floor", "Update a floor in the floor registry via the WebSocket API (config/floor_registry/update). Only the fields you pass are changed; pass null to clear level or icon. 'aliases' replaces the whole list. At least one field besides floor_id is required. This edits registry config only. Returns the updated floor entry.", {
167
- floor_id: z.string().describe("Floor to update, as returned by list_floors"),
168
- name: z.string().optional().describe("New floor name"),
169
- level: z.number().int().nullable().optional().describe("Floor level number; null clears it"),
170
- icon: z.string().nullable().optional().describe("Icon; null clears it"),
171
- aliases: z.array(z.string()).optional().describe("Replacement list of alternative names"),
172
- }, async ({ floor_id, name, level, icon, aliases }) => {
173
- try {
174
- const payload = buildUpdate({ floor_id }, { name, level, icon, aliases });
175
- return ok(await ws.command("config/floor_registry/update", payload));
176
- }
177
- catch (e) {
178
- return err(e);
179
- }
180
- });
181
- server.tool("delete_floor", "Delete a floor from the floor registry via the WebSocket API (config/floor_registry/delete). Areas on the floor are kept but lose their floor_id (set to null). Cannot be undone. Use search_related with item_type 'floor' first to see what references it. This edits registry config only.", {
182
- floor_id: z.string().describe("Floor to delete, as returned by list_floors"),
183
- }, async ({ floor_id }) => {
184
- try {
185
- await ws.command("config/floor_registry/delete", { floor_id });
186
- return ok({ deleted: floor_id });
187
- }
188
- catch (e) {
189
- return err(e);
190
- }
191
- });
192
- server.tool("reorder_floors", "Set the display order of floors in the floor registry via the WebSocket API (config/floor_registry/reorder). 'floor_ids' must contain EVERY existing floor_id exactly once, in the desired order — Home Assistant rejects partial lists, duplicates and unknown ids. Read the current ids with list_floors first. This edits registry config only.", {
193
- floor_ids: z.array(z.string()).describe("All floor_ids, in the new order"),
194
- }, async ({ floor_ids }) => {
195
- try {
196
- await ws.command("config/floor_registry/reorder", { floor_ids });
197
- return ok({ reordered: true, floor_ids });
198
- }
199
- catch (e) {
200
- return err(e);
201
- }
202
- });
203
- server.tool("create_label", "Create a label in the label registry via the WebSocket API (config/label_registry/create) and return the new entry; the label_id is generated from the name and the name must not already be in use. 'color' is either a '#RRGGBB' hex string or a theme color name (primary, accent, disabled, red, pink, purple, deep-purple, indigo, blue, light-blue, cyan, teal, green, light-green, lime, yellow, amber, orange, deep-orange, brown, light-grey, grey, dark-grey, blue-grey, black, white). 'icon' must be in 'prefix:name' form. Attach labels to things with update_registry_entity, update_device or update_area (labels). This edits registry config only.", {
204
- name: z.string().describe("Label name, e.g. 'Battery powered'"),
205
- color: z
206
- .string()
207
- .optional()
208
- .describe("'#RRGGBB' hex color or a theme color name such as 'red' or 'light-blue'"),
209
- icon: z.string().optional().describe("Icon in 'prefix:name' form, e.g. 'mdi:battery'"),
210
- description: z.string().optional().describe("Free-text description"),
211
- }, async ({ name, color, icon, description }) => {
212
- try {
213
- const payload = { name, ...defined({ color, icon, description }) };
214
- return ok(await ws.command("config/label_registry/create", payload));
215
- }
216
- catch (e) {
217
- return err(e);
218
- }
219
- });
220
- server.tool("update_label", "Update a label in the label registry via the WebSocket API (config/label_registry/update). Only the fields you pass are changed; pass null to clear color, icon or description. 'color' is a '#RRGGBB' hex string or a theme color name (see create_label); 'icon' must be in 'prefix:name' form. At least one field besides label_id is required. This edits registry config only. Returns the updated label entry.", {
221
- label_id: z.string().describe("Label to update, as returned by list_labels"),
222
- name: z.string().optional().describe("New label name"),
223
- color: z
224
- .string()
225
- .nullable()
226
- .optional()
227
- .describe("'#RRGGBB' hex color or theme color name; null clears it"),
228
- icon: z.string().nullable().optional().describe("Icon in 'prefix:name' form; null clears it"),
229
- description: z.string().nullable().optional().describe("Description; null clears it"),
230
- }, async ({ label_id, name, color, icon, description }) => {
231
- try {
232
- const payload = buildUpdate({ label_id }, { name, color, icon, description });
233
- return ok(await ws.command("config/label_registry/update", payload));
234
- }
235
- catch (e) {
236
- return err(e);
237
- }
238
- });
239
- server.tool("delete_label", "Delete a label from the label registry via the WebSocket API (config/label_registry/delete). The label is also removed from every area, device and entity that carries it. Cannot be undone. Use search_related with item_type 'label' first to see what uses it. This edits registry config only.", {
240
- label_id: z.string().describe("Label to delete, as returned by list_labels"),
241
- }, async ({ label_id }) => {
242
- try {
243
- await ws.command("config/label_registry/delete", { label_id });
244
- return ok({ deleted: label_id });
245
- }
246
- catch (e) {
247
- return err(e);
248
- }
249
- });
250
- server.tool("list_categories", "List categories for one scope from the category registry via the WebSocket API (config/category_registry/list): category_id, name, icon, created_at, modified_at. Categories group items such as automations or scripts; each category belongs to a 'scope' (a free-form namespace, e.g. 'automation') and an entity joins a category through the 'categories' map on its registry entry (scope -> category_id, see update_registry_entity). An unknown scope returns an empty list.", {
251
- scope: z.string().describe("Category scope, e.g. 'automation'"),
252
- }, async ({ scope }) => {
253
- try {
254
- return ok(await ws.command("config/category_registry/list", { scope }));
255
- }
256
- catch (e) {
257
- return err(e);
258
- }
259
- });
260
- server.tool("create_category", "Create a category in the category registry via the WebSocket API (config/category_registry/create) and return the new entry; the category_id is generated. The name must be unique within the scope. Put an entity into it with update_registry_entity (categories: { <scope>: <category_id> }). This edits registry config only.", {
261
- scope: z.string().describe("Category scope, e.g. 'automation'"),
262
- name: z.string().describe("Category name, e.g. 'Lighting'"),
263
- icon: z.string().optional().describe("Icon in 'prefix:name' form, e.g. 'mdi:lightbulb'"),
264
- }, async ({ scope, name, icon }) => {
265
- try {
266
- const payload = { scope, name, ...defined({ icon }) };
267
- return ok(await ws.command("config/category_registry/create", payload));
268
- }
269
- catch (e) {
270
- return err(e);
271
- }
272
- });
273
- server.tool("update_category", "Update a category in the category registry via the WebSocket API (config/category_registry/update). Only the fields you pass are changed; pass null for icon to clear it. A new name must be unique within the scope. At least one of name or icon is required. This edits registry config only. Returns the updated category entry.", {
274
- scope: z.string().describe("Category scope the category belongs to"),
275
- category_id: z.string().describe("Category to update, as returned by list_categories"),
276
- name: z.string().optional().describe("New category name"),
277
- icon: z.string().nullable().optional().describe("Icon in 'prefix:name' form; null clears it"),
278
- }, async ({ scope, category_id, name, icon }) => {
279
- try {
280
- const payload = buildUpdate({ scope, category_id }, { name, icon });
281
- return ok(await ws.command("config/category_registry/update", payload));
282
- }
283
- catch (e) {
284
- return err(e);
285
- }
286
- });
287
- server.tool("delete_category", "Delete a category from the category registry via the WebSocket API (config/category_registry/delete). Entities that were in this category in that scope are removed from it. Cannot be undone. This edits registry config only.", {
288
- scope: z.string().describe("Category scope the category belongs to"),
289
- category_id: z.string().describe("Category to delete, as returned by list_categories"),
290
- }, async ({ scope, category_id }) => {
291
- try {
292
- await ws.command("config/category_registry/delete", { scope, category_id });
293
- return ok({ deleted: category_id, scope });
294
- }
295
- catch (e) {
296
- return err(e);
297
- }
298
- });
299
- server.tool("get_registry_entity", "Get the full entity registry entry for one entity via the WebSocket API (config/entity_registry/get). Unlike list_registry_entities (a summary), this returns every field: area_id, categories, config_entry_id, device_id, disabled_by, hidden_by, entity_category, icon, labels, name, original_name, platform, unique_id, aliases, capabilities, device_class, original_device_class, original_icon, options (per-domain settings, including voice-assistant exposure) and timestamps. Works for disabled entities. Fails with 'Entity not found' for entities that are not in the registry (e.g. YAML entities without a unique_id).", {
300
- entity_id: z.string().describe("entity_id to look up, e.g. 'light.kitchen'"),
301
- }, async ({ entity_id }) => {
302
- try {
303
- return ok(await ws.command("config/entity_registry/get", { entity_id }));
304
- }
305
- catch (e) {
306
- return err(e);
307
- }
308
- });
309
- server.tool("get_registry_entities", "Get the full entity registry entries for several entities in one call via the WebSocket API (config/entity_registry/get_entries). Returns an object keyed by entity_id; the value is the full entry (same fields as get_registry_entity) or null for an entity that is not in the registry.", {
310
- entity_ids: z
311
- .array(z.string())
312
- .min(1)
313
- .describe("entity_id(s) to look up, e.g. ['light.kitchen', 'sensor.temp']"),
314
- }, async ({ entity_ids }) => {
315
- try {
316
- return ok(await ws.command("config/entity_registry/get_entries", { entity_ids }));
317
- }
318
- catch (e) {
319
- return err(e);
320
- }
321
- });
322
- server.tool("update_registry_entity", "Update entity registry settings other than name, entity_id and enabled state via the WebSocket API (config/entity_registry/update); use rename_entity for name/new_entity_id and set_entity_enabled for disabled_by. Only the fields you pass are changed; pass null to clear area_id, device_class or icon, or to un-hide with hidden_by. 'area_id' overrides the device's area for this entity. 'labels' and 'aliases' replace the whole list (unknown label_ids are silently dropped; a null alias stands for the entity's own full name). 'categories' maps a scope to a category_id (null removes the entity from that scope's category); scopes you do not list are left untouched. 'hidden_by' only accepts 'user' (hide) or null (unhide). 'options_domain' + 'options' replace one domain's registry options (e.g. 'sensor' with { display_precision: 1 }); options null removes that domain's options, and both must be given together. At least one field besides entity_id is required. This edits registry config only — it does not control any device. Returns { entity_entry }.", {
323
- entity_id: z.string().describe("entity_id to update, e.g. 'sensor.kitchen_temperature'"),
324
- area_id: z
325
- .string()
326
- .nullable()
327
- .optional()
328
- .describe("Area override from list_areas; null falls back to the device's area"),
329
- labels: z
330
- .array(z.string())
331
- .optional()
332
- .describe("Replacement list of label_id(s), from list_labels"),
333
- icon: z
334
- .string()
335
- .nullable()
336
- .optional()
337
- .describe("Icon override, e.g. 'mdi:flash'; null clears it"),
338
- hidden_by: z
339
- .enum(["user"])
340
- .nullable()
341
- .optional()
342
- .describe("'user' hides the entity from default views; null unhides it"),
343
- device_class: z
344
- .string()
345
- .nullable()
346
- .optional()
347
- .describe("Device class override, e.g. 'humidity'; null reverts to the original"),
348
- aliases: z
349
- .array(z.string().nullable())
350
- .optional()
351
- .describe("Replacement list of aliases for voice assistants; null entries mean the entity's full name"),
352
- categories: z
353
- .record(z.string().nullable())
354
- .optional()
355
- .describe("Scope -> category_id, e.g. { automation: 'lighting' }; null removes the category for that scope"),
356
- options_domain: z
357
- .string()
358
- .optional()
359
- .describe("Options domain to replace, e.g. 'sensor'; requires 'options'"),
360
- options: z
361
- .record(z.unknown())
362
- .nullable()
363
- .optional()
364
- .describe("Options object for options_domain; null removes that domain's options"),
365
- }, async ({ entity_id, area_id, labels, icon, hidden_by, device_class, aliases, categories, options_domain, options, }) => {
366
- try {
367
- if ((options_domain === undefined) !== (options === undefined)) {
368
- throw new Error("'options_domain' and 'options' must be provided together (options null removes that domain's options)");
369
- }
370
- const payload = buildUpdate({ entity_id }, {
371
- area_id,
372
- labels,
373
- icon,
374
- hidden_by,
375
- device_class,
376
- aliases,
377
- categories,
378
- options_domain,
379
- options,
380
- });
381
- return ok(await ws.command("config/entity_registry/update", payload));
382
- }
383
- catch (e) {
384
- return err(e);
385
- }
386
- });
387
- server.tool("get_automatic_entity_ids", "Show the entity_id Home Assistant would generate for each given entity from its current device, area and entity names (config/entity_registry/get_automatic_entity_ids). Returns an object entity_id -> proposed entity_id (equal to the current one if it is already automatic), or null for an entity that is not in the registry. Use it to find entity_ids that were customized and reset them with rename_entity (new_entity_id). Read-only: nothing is renamed.", {
388
- entity_ids: z
389
- .array(z.string())
390
- .min(1)
391
- .describe("entity_id(s) to check, e.g. ['light.kitchen_light_2']"),
392
- }, async ({ entity_ids }) => {
393
- try {
394
- return ok(await ws.command("config/entity_registry/get_automatic_entity_ids", { entity_ids }));
395
- }
396
- catch (e) {
397
- return err(e);
398
- }
399
- });
400
- server.tool("get_entity_registry_settings", "Get the global entity registry settings via the WebSocket API (config/entity_registry/settings/get). Returns { entity_id_parts }: the name parts (area, floor, parent_device, device, entity) Home Assistant uses when it generates entity_ids, or null for the default (area, parent_device, device, entity).", {}, async () => {
401
- try {
402
- return ok(await ws.command("config/entity_registry/settings/get"));
403
- }
404
- catch (e) {
405
- return err(e);
406
- }
407
- });
408
- server.tool("update_entity_registry_settings", "Change the global entity registry settings via the WebSocket API (config/entity_registry/settings/update). 'entity_id_parts' selects which name parts Home Assistant uses when it generates entity_ids: a list of unique values from area, floor, parent_device, device, entity that must include both 'entity' and 'device'; null resets to the default (area, parent_device, device, entity). This only affects ids generated afterwards (new entities, get_automatic_entity_ids); existing entities are not renamed. This edits registry config only. Returns the resulting { entity_id_parts }.", {
409
- entity_id_parts: z
410
- .array(z.enum(ENTITY_ID_PARTS))
411
- .nullable()
412
- .optional()
413
- .describe("Name parts for generated entity_ids; null resets to the default"),
414
- }, async ({ entity_id_parts }) => {
415
- try {
416
- const payload = buildUpdate({}, { entity_id_parts });
417
- return ok(await ws.command("config/entity_registry/settings/update", payload));
418
- }
419
- catch (e) {
420
- return err(e);
421
- }
422
- });
423
- server.tool("update_device", "Update device registry settings other than name and area via the WebSocket API (config/device_registry/update); use rename_device for name_by_user and area_id. Only the fields you pass are changed. 'labels' replaces the whole list (unknown label_ids are silently dropped). 'disabled_by' only accepts 'user' (disable) or null (re-enable): disabling a device also disables its entities, and re-enabling is silently ignored while the owning config entry is disabled, so check 'disabled_by' in the result. At least one of labels or disabled_by is required. Composite device ids (see list_composite_splits) cannot be updated. This edits registry config only — it does not control any device. Returns the updated device entry.", {
424
- device_id: z.string().describe("Device registry id, as returned by list_devices"),
425
- labels: z
426
- .array(z.string())
427
- .optional()
428
- .describe("Replacement list of label_id(s), from list_labels"),
429
- disabled_by: z
430
- .enum(["user"])
431
- .nullable()
432
- .optional()
433
- .describe("'user' disables the device; null re-enables it"),
434
- }, async ({ device_id, labels, disabled_by }) => {
435
- try {
436
- const payload = buildUpdate({ device_id }, { labels, disabled_by });
437
- return ok(await ws.command("config/device_registry/update", payload));
438
- }
439
- catch (e) {
440
- return err(e);
441
- }
442
- });
443
- server.tool("remove_device", "Remove a device from the device registry via the WebSocket API (config/device_registry/remove). Home Assistant asks the owning integration to approve the removal and fails if the integration does not support it or rejects it. On success the device and its entities are deleted from the registries. Some integrations also unpair the physical device when asked to remove it (the Matter integration removes the node from its Matter network), and an integration may rediscover and re-add the device later. Cannot be undone. Composite device ids cannot be removed. Prefer update_device (disabled_by 'user') when you only want a device to stop appearing.", {
444
- device_id: z.string().describe("Device registry id, as returned by list_devices"),
445
- }, async ({ device_id }) => {
446
- try {
447
- await ws.command("config/device_registry/remove", { device_id });
448
- return ok({ removed: device_id });
449
- }
450
- catch (e) {
451
- return err(e);
452
- }
453
- });
454
- server.tool("list_composite_splits", "List pre-migration composite devices that Home Assistant split into one device per config entry (config/device_registry/list_composite_splits). Returns an object keyed by the old composite device id with { split_ids, primary_id }: the ids of the devices that replaced it and which of them belongs to the composite's former primary config entry (null if none). Automations and scripts that still reference an old composite id resolve to these devices. An empty object means no splits.", {}, async () => {
455
- try {
456
- return ok(await ws.command("config/device_registry/list_composite_splits"));
457
- }
458
- catch (e) {
459
- return err(e);
460
- }
461
- });
462
- server.tool("list_linked_devices", "List devices linked to a given device via the WebSocket API (config/device_registry/list_linked_devices). Linked devices share at least one connection or identifier with it but belong to other config entries (e.g. one physical device registered by two integrations). Returns { linked_devices: [device_id, ...] }; a child device always has none. Fails if the device does not exist.", {
463
- device_id: z.string().describe("Device registry id, as returned by list_devices"),
464
- }, async ({ device_id }) => {
465
- try {
466
- return ok(await ws.command("config/device_registry/list_linked_devices", { device_id }));
467
- }
468
- catch (e) {
469
- return err(e);
470
- }
471
- });
472
- server.tool("search_related", "Find everything related to an item via the WebSocket API (search/related): the entities, devices, areas, floors, labels, config entries, integrations, automations, scripts, scenes, groups, persons and blueprints connected to it. Use it to see what depends on an entity, device, area, floor or label before renaming, moving or deleting it, or what an automation or script touches. Returns an object keyed by item type with a list of ids per type (types with no results are omitted, and the requested item itself is left out). 'item_id' depends on item_type: area_id, floor_id, label_id, device_id, config entry id, integration domain (e.g. 'hue'), entity_id for entity/automation/script/scene/group/person (e.g. 'automation.morning_lights'), or the blueprint path for automation_blueprint/script_blueprint (e.g. 'homeassistant/motion_light.yaml'). Related automations and scripts are returned as entity_ids.", {
473
- item_type: z.enum(ITEM_TYPES).describe("Kind of item to search from"),
474
- item_id: z.string().describe("Identifier of the item, in the form item_type requires"),
475
- include_disabled_entities: z
476
- .boolean()
477
- .optional()
478
- .describe("Also include disabled entities of related devices and areas (default false)"),
479
- }, async ({ item_type, item_id, include_disabled_entities }) => {
480
- try {
481
- const payload = {
482
- item_type,
483
- item_id,
484
- ...defined({ include_disabled_entities }),
485
- };
486
- return ok(await ws.command("search/related", payload));
487
- }
488
- catch (e) {
489
- return err(e);
490
- }
491
- });
492
- server.tool("list_exposed_entities", "List entities exposed to voice assistants via the WebSocket API (homeassistant/expose_entity/list; needs an admin token). Returns { exposed_entities: { entity_id: { <assistant>: true } } } where the assistants are 'conversation' (Assist), 'cloud.alexa' and 'cloud.google_assistant'. Only entities with a stored 'exposed' setting are listed; an entity that was never evaluated follows the expose-new-entities default (see get_expose_new_entities) and may not appear yet.", {}, async () => {
493
- try {
494
- return ok(await ws.command("homeassistant/expose_entity/list"));
495
- }
496
- catch (e) {
497
- return err(e);
498
- }
499
- });
500
- server.tool("set_entity_exposure", "Expose entities to, or hide them from, voice assistants via the WebSocket API (homeassistant/expose_entity; needs an admin token). 'assistants' picks the targets: 'conversation' (Assist), 'cloud.alexa', 'cloud.google_assistant'. should_expose true exposes every listed entity to every listed assistant, false stops exposing them. This changes which entities those assistants can see and control by voice; it does not control any device itself. Returns { changed_entity_ids }: the entities whose exposure actually changed.", {
501
- assistants: z
502
- .array(z.enum(ASSISTANTS))
503
- .min(1)
504
- .describe("Assistant(s) to change: 'conversation', 'cloud.alexa', 'cloud.google_assistant'"),
505
- entity_ids: z
506
- .array(z.string())
507
- .min(1)
508
- .describe("entity_id(s) to expose or hide, e.g. ['light.kitchen']"),
509
- should_expose: z.boolean().describe("true to expose, false to stop exposing"),
510
- }, async ({ assistants, entity_ids, should_expose }) => {
511
- try {
512
- return ok(await ws.command("homeassistant/expose_entity", {
513
- assistants,
514
- entity_ids,
515
- should_expose,
516
- }));
517
- }
518
- catch (e) {
519
- return err(e);
520
- }
521
- });
522
- server.tool("get_expose_new_entities", "Check whether newly added entities are automatically exposed to a voice assistant via the WebSocket API (homeassistant/expose_new_entities/get; needs an admin token). Returns { expose_new }. The default is true for 'conversation' (Assist) and false for 'cloud.alexa' and 'cloud.google_assistant'; even when true, only entities in Home Assistant's default-exposed domains and device classes qualify.", {
523
- assistant: z
524
- .enum(ASSISTANTS)
525
- .describe("'conversation', 'cloud.alexa' or 'cloud.google_assistant'"),
526
- }, async ({ assistant }) => {
527
- try {
528
- return ok(await ws.command("homeassistant/expose_new_entities/get", { assistant }));
529
- }
530
- catch (e) {
531
- return err(e);
532
- }
533
- });
534
- server.tool("set_expose_new_entities", "Set whether newly added entities are automatically exposed to a voice assistant via the WebSocket API (homeassistant/expose_new_entities/set; needs an admin token). Affects only entities added or first evaluated afterwards; existing exposure settings are unchanged (use set_entity_exposure for those).", {
535
- assistant: z
536
- .enum(ASSISTANTS)
537
- .describe("'conversation', 'cloud.alexa' or 'cloud.google_assistant'"),
538
- expose_new: z.boolean().describe("true to expose new entities automatically"),
539
- }, async ({ assistant, expose_new }) => {
540
- try {
541
- await ws.command("homeassistant/expose_new_entities/set", { assistant, expose_new });
542
- return ok({ assistant, expose_new });
543
- }
544
- catch (e) {
545
- return err(e);
546
- }
547
- });
548
- }
package/dist/tools/raw.js DELETED
@@ -1,41 +0,0 @@
1
- import { z } from "zod";
2
- import { ok, err } from "../hass/format.js";
3
- export function registerRawTools(server, client, ws) {
4
- server.tool("ws_command", "Send any single WebSocket API command to Home Assistant and return its result — an escape hatch for commands without a dedicated tool, including those of custom integrations (e.g. 'zwave_js/network_status', 'matter/commission'). Unrestricted: it can change or delete anything the token is allowed to, so prefer a dedicated tool when one exists. Only request/response commands work; subscription commands that deliver data through later events return just their acknowledgement.", {
5
- type: z.string().describe("Command type, e.g. 'config/floor_registry/list'"),
6
- payload: z
7
- .record(z.unknown())
8
- .optional()
9
- .describe("Command parameters, without 'id' and 'type'"),
10
- }, async ({ type, payload }) => {
11
- try {
12
- return ok(await ws.command(type, payload ?? {}));
13
- }
14
- catch (e) {
15
- return err(e);
16
- }
17
- });
18
- server.tool("rest_request", "Send any request to the Home Assistant REST API and return the response (JSON, or text for non-JSON responses) — an escape hatch for routes without a dedicated tool. The path must start with '/api/'. Unrestricted: POST and DELETE can change anything the token is allowed to, so prefer a dedicated tool when one exists.", {
19
- method: z
20
- .enum(["GET", "POST", "PUT", "DELETE"])
21
- .optional()
22
- .describe("HTTP method (default GET)"),
23
- path: z
24
- .string()
25
- .describe("Path including any query string, e.g. '/api/calendars' or '/api/states/sun.sun'"),
26
- body: z.unknown().optional().describe("JSON body for POST/PUT"),
27
- }, async ({ method, path, body }) => {
28
- try {
29
- if (!path.startsWith("/api/") || path.split(/[/?#]/).includes("..")) {
30
- throw new Error(`path must start with '/api/' and must not contain '..' (got '${path}')`);
31
- }
32
- const options = { method: method ?? "GET" };
33
- if (body !== undefined)
34
- options.body = JSON.stringify(body);
35
- return ok(await client.fetch(path, options));
36
- }
37
- catch (e) {
38
- return err(e);
39
- }
40
- });
41
- }