list_entities
Retrieve all smart home devices and sensors from Home Assistant, with optional filtering by device type like lights or switches.
Instructions
List all Home Assistant entities (lights, switches, sensors, etc.)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| domain | No | Filter by domain (e.g., 'light', 'switch', 'sensor'). Optional. |
Implementation Reference
- src/index.ts:171-193 (handler)Handler for the 'list_entities' tool. Fetches all Home Assistant entities using haClient.getStates(), optionally filters by domain from input arguments, maps to a simplified object (entity_id, state, friendly_name), stringifies as JSON, and returns in the tool response content.case "list_entities": { const entities = await haClient.getStates(); const filtered = args?.domain ? entities.filter((e) => e.entity_id.startsWith(`${args.domain}.`)) : entities; return { content: [ { type: "text", text: JSON.stringify( filtered.map((e) => ({ entity_id: e.entity_id, state: e.state, friendly_name: e.attributes.friendly_name, })), null, 2 ), }, ], }; }
- src/index.ts:101-112 (registration)Registration of the 'list_entities' tool in the ListToolsRequestHandler response. Includes the tool name, description, and input schema for optional domain filter.name: "list_entities", description: "List all Home Assistant entities (lights, switches, sensors, etc.)", inputSchema: { type: "object", properties: { domain: { type: "string", description: "Filter by domain (e.g., 'light', 'switch', 'sensor'). Optional.", }, }, }, },
- src/index.ts:50-52 (helper)Helper method in HomeAssistantClient class that fetches the list of all entity states from the Home Assistant API endpoint '/api/states'.async getStates(): Promise<HAEntity[]> { return this.fetch("states"); }