Skip to main content
Glama
hekmon8

Home Assistant MCP Server

by hekmon8

toggle_entity

Switch Home Assistant devices on or off by specifying the entity ID and desired state to control smart home automation.

Instructions

Toggle a Home Assistant entity on/off

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entity_idYesThe entity ID to toggle (e.g., switch.bedroom)
stateYesThe desired state (on/off)

Implementation Reference

  • The main handler function that implements the toggle_entity tool logic by validating inputs and calling the Home Assistant API to turn the entity on or off.
    private async toggleEntity(args: any) {
      if (!args.entity_id || !args.state) {
        throw new McpError(ErrorCode.InvalidParams, 'entity_id and state are required');
      }
    
      const response = await this.haClient.post('/api/services/homeassistant/turn_' + args.state, {
        entity_id: args.entity_id,
      });
    
      return {
        content: [
          {
            type: 'text',
            text: `Successfully turned ${args.state} ${args.entity_id}`,
          },
        ],
      };
    }
  • Input schema defining the parameters for the toggle_entity tool: entity_id (required string) and state (required string enum ['on','off']).
    inputSchema: {
      type: 'object',
      properties: {
        entity_id: {
          type: 'string',
          description: 'The entity ID to toggle (e.g., switch.bedroom)',
        },
        state: {
          type: 'string',
          description: 'The desired state (on/off)',
          enum: ['on', 'off'],
        },
      },
      required: ['entity_id', 'state'],
    },
  • src/index.ts:70-88 (registration)
    Registration of the toggle_entity tool in the ListTools response, including name, description, and input schema.
    {
      name: 'toggle_entity',
      description: 'Toggle a Home Assistant entity on/off',
      inputSchema: {
        type: 'object',
        properties: {
          entity_id: {
            type: 'string',
            description: 'The entity ID to toggle (e.g., switch.bedroom)',
          },
          state: {
            type: 'string',
            description: 'The desired state (on/off)',
            enum: ['on', 'off'],
          },
        },
        required: ['entity_id', 'state'],
      },
    },
  • Switch case in the CallToolRequest handler that dispatches toggle_entity requests to the toggleEntity method.
    case 'toggle_entity':
      return await this.toggleEntity(request.params.arguments);

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

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/hekmon8/Homeassistant-server-mcp'

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