Skip to main content
Glama
diverdown1964

Home Assistant MCP Server

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
NameRequiredDescriptionDefault
entity_idYesThe entity ID (e.g., 'light.living_room')

Implementation Reference

  • 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),
          },
        ],
      };
    }
  • 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"],
      },
    },
  • 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}`);
    }
  • 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;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/diverdown1964/HomeAssistant-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server