@orellbuehler/homeassistant-mcp 0.8.0 → 0.9.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.
- package/README.md +12 -2
- package/dist/tools/registry.js +46 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -170,7 +170,9 @@ not. Debug the result with the trace tools below.
|
|
|
170
170
|
| `list_registry_entities` | ALL registered entities, incl. disabled/unavailable (area, device, status). |
|
|
171
171
|
| `rename_entity` | Set an entity's registry `name` and/or `new_entity_id` (config edit, no device control). |
|
|
172
172
|
| `set_entity_enabled` | Enable/disable entities in the registry (batch, per-entity results). |
|
|
173
|
-
| `
|
|
173
|
+
| `remove_entity` | Delete an orphaned (restored/stateless) entity from the registry; refuses live entities. |
|
|
174
|
+
| `rename_device` | Set a device's `name_by_user` and/or `area_id` (config edit, no device control). |
|
|
175
|
+
| `list_devices` | Devices (id, name, name_by_user, manufacturer, model, area). |
|
|
174
176
|
| `list_areas` | Areas (area_id, name, floor). |
|
|
175
177
|
| `list_labels` | Labels (label_id, name, color, icon). |
|
|
176
178
|
|
|
@@ -179,7 +181,15 @@ not. Debug the result with the trace tools below.
|
|
|
179
181
|
`rename_entity` writes the registry via `config/entity_registry/update` (requires an admin token):
|
|
180
182
|
`name` overrides the friendly name (null reverts to the integration's `original_name`) and
|
|
181
183
|
`new_entity_id` renames the entity_id within the same domain.
|
|
182
|
-
`
|
|
184
|
+
`remove_entity` deletes a leftover registry entry via `config/entity_registry/remove` (admin-only,
|
|
185
|
+
not undoable). It first checks the live states and refuses any entity that still has a state not
|
|
186
|
+
marked `restored` — i.e. one a loaded integration still provides — so it only cleans up orphans such
|
|
187
|
+
as a deleted template entity. A disabled entity has no state and is therefore removable too.
|
|
188
|
+
`rename_device` writes the device registry via `config/device_registry/update` (admin-only):
|
|
189
|
+
`name_by_user` overrides the device name (null reverts to the integration's name) and `area_id`
|
|
190
|
+
moves the device to another area. Entities that take their name from the device (`has_entity_name`)
|
|
191
|
+
follow the device name, so rename the device to fix their friendly names.
|
|
192
|
+
`set_entity_enabled` uses `config/entity_registry/update` as well (also admin-only) to set `disabled_by` to `null`
|
|
183
193
|
(enable) or `"user"` (disable) for a batch of entity_ids; one failure does not abort the rest, and
|
|
184
194
|
each entity comes back with its own `ok`/`error` and resulting `disabled_by`. Enabling is not
|
|
185
195
|
instant — HA loads the entity after its config entry reloads (`reload_delay`, usually 30 seconds) or
|
package/dist/tools/registry.js
CHANGED
|
@@ -114,12 +114,57 @@ export function registerRegistryTools(server, ws) {
|
|
|
114
114
|
return err(e);
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
|
-
server.tool("
|
|
117
|
+
server.tool("remove_entity", "Remove an orphaned entity from the entity registry via the WebSocket API (config/entity_registry/remove). Only for leftover entries no integration provides any more — e.g. a deleted template entity or a stale device entity shown as restored/unavailable. Refuses to remove an entity that is still provided by a loaded integration (it has a live state that is not marked 'restored'); remove or reconfigure that integration instead. This deletes registry config only — it does not control any device — and cannot be undone.", {
|
|
118
|
+
entity_id: z.string().describe("entity_id to remove, e.g. 'light.licht_keller_wc'"),
|
|
119
|
+
}, async ({ entity_id }) => {
|
|
120
|
+
try {
|
|
121
|
+
const states = (await ws.command("get_states"));
|
|
122
|
+
const state = states.find((s) => s.entity_id === entity_id);
|
|
123
|
+
if (state && state.attributes?.restored !== true) {
|
|
124
|
+
throw new Error(`${entity_id} is still provided by a loaded integration (state '${state.state}'), so it is not orphaned and was not removed. Remove it from its integration or config first.`);
|
|
125
|
+
}
|
|
126
|
+
await ws.command("config/entity_registry/remove", { entity_id });
|
|
127
|
+
return ok({ removed: entity_id });
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
return err(e);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
server.tool("rename_device", "Rename a device in the device registry via the WebSocket API (config/device_registry/update). Set 'name_by_user' to override the device name (pass null to revert to the integration's name) and/or 'area_id' to move it to another area (pass null to clear the area). At least one of name_by_user or area_id is required. Entities with has_entity_name derive their friendly names from the device name, so this is how to fix their display names. This edits registry config only — it does not control any device. Returns the updated device entry.", {
|
|
134
|
+
device_id: z.string().describe("Device registry id, as returned by list_devices"),
|
|
135
|
+
name_by_user: z
|
|
136
|
+
.string()
|
|
137
|
+
.nullable()
|
|
138
|
+
.optional()
|
|
139
|
+
.describe("New user-facing device name; null reverts to the integration's name"),
|
|
140
|
+
area_id: z
|
|
141
|
+
.string()
|
|
142
|
+
.nullable()
|
|
143
|
+
.optional()
|
|
144
|
+
.describe("Area to assign, as returned by list_areas; null clears the area"),
|
|
145
|
+
}, async ({ device_id, name_by_user, area_id }) => {
|
|
146
|
+
try {
|
|
147
|
+
if (name_by_user === undefined && area_id === undefined) {
|
|
148
|
+
throw new Error("Provide at least one of 'name_by_user' or 'area_id' to update the device");
|
|
149
|
+
}
|
|
150
|
+
const payload = { device_id };
|
|
151
|
+
if (name_by_user !== undefined)
|
|
152
|
+
payload.name_by_user = name_by_user;
|
|
153
|
+
if (area_id !== undefined)
|
|
154
|
+
payload.area_id = area_id;
|
|
155
|
+
return ok(await ws.command("config/device_registry/update", payload));
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
return err(e);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
server.tool("list_devices", "List devices from the device registry via the WebSocket API (id, name, name_by_user, manufacturer, model, area_id). 'name' is the effective name (name_by_user if set, else the integration's name); 'name_by_user' is the user override or null. Useful for grouping entities by physical device when writing automations.", {}, async () => {
|
|
118
162
|
try {
|
|
119
163
|
const list = (await ws.command("config/device_registry/list"));
|
|
120
164
|
const devices = list.map((d) => ({
|
|
121
165
|
id: d.id,
|
|
122
166
|
name: d.name_by_user ?? d.name ?? null,
|
|
167
|
+
name_by_user: d.name_by_user ?? null,
|
|
123
168
|
manufacturer: d.manufacturer ?? null,
|
|
124
169
|
model: d.model ?? null,
|
|
125
170
|
area_id: d.area_id ?? null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orellbuehler/homeassistant-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Model Context Protocol server for Home Assistant: introspect entities, services, events, registries, render templates and validate configuration to help AI agents author HA configs and automations.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|