ha_get_state
Get the current state of a Home Assistant entity by supplying its entity ID. Enables real-time status retrieval for automation and monitoring.
Instructions
Get Home Assistant entity state by entity_id.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entity_id | Yes |
Implementation Reference
- src/index.ts:61-71 (handler)Handler function registered for the 'ha_get_state' tool. Calls ha.getState(input.entity_id) and returns the state as JSON text.
server.tool( 'ha_get_state', 'Get Home Assistant entity state by entity_id.', GetStateInput.shape, async (input) => { const state = await ha.getState(input.entity_id) return { content: [{ type: 'text', text: JSON.stringify(state, null, 2) }], } }, ) - src/tools.ts:3-5 (schema)Input schema for ha_get_state: takes a required entity_id string.
export const GetStateInput = z.object({ entity_id: z.string().min(1), }) - src/index.ts:61-71 (registration)Tool registration using server.tool() with name 'ha_get_state'.
server.tool( 'ha_get_state', 'Get Home Assistant entity state by entity_id.', GetStateInput.shape, async (input) => { const state = await ha.getState(input.entity_id) return { content: [{ type: 'text', text: JSON.stringify(state, null, 2) }], } }, ) - src/ha.ts:87-91 (helper)HomeAssistantClient.getState() - helper that looks up the entity by entity_id from cached entities.
async getState(entityId: string): Promise<HassEntity | null> { // Ensure we have a state snapshot. await this.ensureConnected() return this.entities[entityId] ?? null }