Skip to main content
Glama
hpohlmann

Home Assistant MCP

by hpohlmann

control_device

Turn Home Assistant devices on or off by specifying entity IDs and desired states for remote control.

Instructions

Control a Home Assistant entity by turning it on or off.

Args:
    entity_id: The Home Assistant entity ID to control (format: domain.entity)
    state: The desired state ('on' or 'off')

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entity_idYes
stateYes

Implementation Reference

  • The async handler function implementing the control_device tool. It validates inputs, calls the Home Assistant API to turn entities on/off, and returns success/error messages.
    async def control_device(entity_id: str, state: str) -> str:
        """Control a Home Assistant entity by turning it on or off.
        
        Args:
            entity_id: The Home Assistant entity ID to control (format: domain.entity)
            state: The desired state ('on' or 'off')
        """
        # Basic validation
        if not entity_id or "." not in entity_id:
            return f"Invalid entity ID format: {entity_id}. Must be in format: domain.entity"
        
        state = state.lower()
        if state not in ["on", "off"]:
            return f"Invalid state: {state}. Must be 'on' or 'off'"
        
        # Check token
        if not HOME_ASSISTANT_TOKEN:
            return "Home Assistant token not configured. Set HOME_ASSISTANT_TOKEN environment variable."
        
        # Get domain from entity_id
        domain = entity_id.split(".")[0]
        service = "turn_on" if state == "on" else "turn_off"
        
        # Call the HA API
        result = await make_ha_request(domain, service, entity_id)
        
        if result["success"]:
            return f"Successfully turned {state} {entity_id}"
        else:
            return f"Failed to control {entity_id}: {result.get('error', 'Unknown error')}"
  • The registration of the control_device tool using the FastMCP tool decorator within the init_tools function.
    fastmcp_instance.tool()(control_device)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('turning it on or off') but lacks critical details: it doesn't mention permissions required, whether this is a destructive operation (e.g., if turning off a device has irreversible effects), rate limits, error handling, or what happens upon success/failure. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the first sentence states the core purpose, and the 'Args' section efficiently documents parameters without unnecessary details. Every sentence earns its place, making it easy to scan and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, mutation operation, no output schema), the description is partially complete. It covers the basic purpose and parameter semantics but lacks behavioral details (e.g., side effects, permissions) and usage guidelines. Without annotations or output schema, it leaves gaps that could hinder an agent's ability to use the tool effectively in varied contexts.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful semantics beyond the input schema, which has 0% description coverage. It explains that 'entity_id' is a Home Assistant entity ID with a specific format ('domain.entity') and that 'state' accepts 'on' or 'off' values. This clarifies the purpose and constraints of both parameters, compensating well for the schema's lack of descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Control a Home Assistant entity by turning it on or off.' This specifies the verb ('control'), resource ('Home Assistant entity'), and action ('turning it on or off'), making it easy to understand. However, it doesn't explicitly differentiate from sibling tools like 'set_device_color' (which might control color instead of on/off state), so it misses the highest score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'search_entities' (which might be for finding entities) or 'set_device_color' (which might control color settings), nor does it specify prerequisites, exclusions, or contextual cues for usage. This leaves the agent with minimal direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/hpohlmann/home-assistant-mcp'

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