Skip to main content
Glama

entity_action

Control any Home Assistant entity by sending on, off, or toggle actions with optional parameters for brightness, temperature, and more.

Instructions

Perform an action on a Home Assistant entity (on, off, toggle)

Args: entity_id: The entity ID to control (e.g. 'light.living_room') action: The action to perform ('on', 'off', 'toggle') params: Optional dictionary of additional parameters for the service call

Returns: The response from Home Assistant

Examples: entity_id="light.living_room", action="on", params={"brightness": 255} entity_id="switch.garden_lights", action="off" entity_id="climate.living_room", action="on", params={"temperature": 22.5}

Domain-Specific Parameters: - Lights: brightness (0-255), color_temp, rgb_color, transition, effect - Covers: position (0-100), tilt_position - Climate: temperature, target_temp_high, target_temp_low, hvac_mode - Media players: source, volume_level (0-1)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entity_idYes
actionYes
paramsNo

Implementation Reference

  • The main handler function that performs actions on Home Assistant entities. Validates action (on/off/toggle), maps to service names (turn_on/turn_off/toggle), extracts domain from entity_id, and delegates to call_service.
    @mcp.tool()
    @async_handler("entity_action")
    async def entity_action(entity_id: str, action: str, params: Optional[Dict[str, Any]] = None) -> dict:
        """
        Perform an action on a Home Assistant entity (on, off, toggle)
        
        Args:
            entity_id: The entity ID to control (e.g. 'light.living_room')
            action: The action to perform ('on', 'off', 'toggle')
            params: Optional dictionary of additional parameters for the service call
        
        Returns:
            The response from Home Assistant
        
        Examples:
            entity_id="light.living_room", action="on", params={"brightness": 255}
            entity_id="switch.garden_lights", action="off"
            entity_id="climate.living_room", action="on", params={"temperature": 22.5}
        
        Domain-Specific Parameters:
            - Lights: brightness (0-255), color_temp, rgb_color, transition, effect
            - Covers: position (0-100), tilt_position
            - Climate: temperature, target_temp_high, target_temp_low, hvac_mode
            - Media players: source, volume_level (0-1)
        """
        if action not in ["on", "off", "toggle"]:
            return {"error": f"Invalid action: {action}. Valid actions are 'on', 'off', 'toggle'"}
        
        # Map action to service name
        service = action if action == "toggle" else f"turn_{action}"
        
        # Extract the domain from the entity_id
        domain = entity_id.split(".")[0]
        
        # Prepare service data
        data = {"entity_id": entity_id, **(params or {})}
        
        logger.info(f"Performing action '{action}' on entity: {entity_id} with params: {params}")
        return await call_service(domain, service, data)
  • app/server.py:104-104 (registration)
    The @mcp.tool() decorator registers this function as an MCP tool named 'entity_action'.
    @mcp.tool()
  • Type signature defines inputs: entity_id (str), action (str), optional params (dict), and returns a dict.
    async def entity_action(entity_id: str, action: str, params: Optional[Dict[str, Any]] = None) -> dict:
  • Helper function that makes the actual HTTP POST call to Home Assistant API to perform the service call. entity_action delegates to this function.
    async def call_service(domain: str, service: str, data: Optional[Dict[str, Any]] = None) -> List[Dict[str, Any]]:
        """Call a Home Assistant service.
    
        Returns:
            List of affected entity states (may be empty for services like reload).
        """
        if data is None:
            data = {}
        
        client = await get_client()
        response = await client.post(
            f"{HA_URL}/api/services/{domain}/{service}", 
            headers=get_ha_headers(),
            json=data
        )
        response.raise_for_status()
        
        # Invalidate cache after service calls as they might change entity states
        global _entities_timestamp
        _entities_timestamp = 0
        
        return response.json()
Behavior3/5

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

No annotations provided, so description carries full burden. Discloses optional params and domain-specific details, but does not mention side effects, permissions, or async behavior. Adequate for basic actions.

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?

Well-structured with clear sections, examples, and domain-specific info. Front-loaded purpose, no redundant sentences.

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

Completeness4/5

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

Covers main actions, examples, and domain-specific params. Could mention error handling or constraints, but overall complete for typical use.

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

Parameters5/5

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

Schema coverage is 0%, description compensates fully. Explains entity_id, action values, and provides extensive domain-specific parameter details (brightness, color_temp, etc.) for params.

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

Purpose5/5

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

Description clearly states verb 'Perform an action' and resource 'Home Assistant entity', with specific action values (on, off, toggle). Distinguishes from siblings like call_service_tool.

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

Usage Guidelines4/5

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

Provides examples and domain-specific parameters, giving strong implicit guidance. Does not explicitly state when not to use or compare to alternatives, but examples clarify typical usage.

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/voska/hass-mcp'

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