Skip to main content
Glama

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)

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