get_entity_state
Retrieve the current state and attributes of a Home Assistant entity, such as a light or sensor, to monitor device status and conditions.
Instructions
Get the current state and attributes of a specific entity
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entity_id | Yes | The entity ID (e.g., 'light.living_room') |
Implementation Reference
- src/index.ts:195-205 (handler)The handler function for the 'get_entity_state' tool. It retrieves the state of the specified Home Assistant entity using the haClient and returns it as a formatted JSON string in the tool response.case "get_entity_state": { const entity = await haClient.getState(args?.entity_id as string); return { content: [ { type: "text", text: JSON.stringify(entity, null, 2), }, ], }; }
- src/index.ts:113-126 (schema)Tool schema definition including name, description, and input schema for 'get_entity_state', registered in the list_tools response.{ name: "get_entity_state", description: "Get the current state and attributes of a specific entity", inputSchema: { type: "object", properties: { entity_id: { type: "string", description: "The entity ID (e.g., 'light.living_room')", }, }, required: ["entity_id"], }, },
- src/index.ts:54-56 (helper)Helper method in HomeAssistantClient class that performs the actual API call to retrieve the entity state from Home Assistant.async getState(entityId: string): Promise<HAEntity> { return this.fetch(`states/${entityId}`); }
- src/index.ts:15-21 (schema)TypeScript interface defining the structure of a Home Assistant entity state, used by the get_entity_state tool.interface HAEntity { entity_id: string; state: string; attributes: Record<string, any>; last_changed: string; last_updated: string; }