Skip to main content
Glama
hpohlmann

Home Assistant MCP

by hpohlmann

set_device_color

Control light colors in Home Assistant by specifying RGB values and optional brightness for precise lighting adjustments.

Instructions

Set the color and optionally brightness of a light entity.

Args:
    entity_id: The Home Assistant entity ID to control (format: light.entity)
    red: Red component (0-255)
    green: Green component (0-255)
    blue: Blue component (0-255)
    brightness: Optional brightness level (0-255)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entity_idYes
redYes
greenYes
blueYes
brightnessNo

Implementation Reference

  • The handler function that validates inputs and calls the Home Assistant API to set RGB color and optional brightness on a light entity.
    async def set_device_color(entity_id: str, red: int, green: int, blue: int, brightness: int = None) -> str:
        """Set the color and optionally brightness of a light entity.
        
        Args:
            entity_id: The Home Assistant entity ID to control (format: light.entity)
            red: Red component (0-255)
            green: Green component (0-255)
            blue: Blue component (0-255)
            brightness: Optional brightness level (0-255)
        """
        # Basic validation
        if not entity_id or not entity_id.startswith("light."):
            return f"Invalid entity ID format: {entity_id}. Must be a light entity (format: light.entity)"
        
        # Validate RGB values
        for color, name in [(red, "Red"), (green, "Green"), (blue, "Blue")]:
            if not 0 <= color <= 255:
                return f"Invalid {name} value: {color}. Must be between 0 and 255"
        
        # Validate brightness if provided
        if brightness is not None and not 0 <= brightness <= 255:
            return f"Invalid brightness value: {brightness}. Must be between 0 and 255"
        
        # Check token
        if not HOME_ASSISTANT_TOKEN:
            return "Home Assistant token not configured. Set HOME_ASSISTANT_TOKEN environment variable."
        
        # Call the HA API
        result = await set_light_color(entity_id, [red, green, blue], brightness)
        
        if result["success"]:
            color_msg = f"color to RGB({red},{green},{blue})"
            brightness_msg = f" and brightness to {brightness}" if brightness is not None else ""
            return f"Successfully set {entity_id} {color_msg}{brightness_msg}"
        else:
            return f"Failed to set color for {entity_id}: {result.get('error', 'Unknown error')}"
  • Registers the set_device_color tool (and others) with the FastMCP instance.
    def init_tools(fastmcp_instance: FastMCP):
        """Initialize the tools with a FastMCP instance."""
        global mcp
        mcp = fastmcp_instance
        
        # Register tools with the FastMCP instance
        fastmcp_instance.tool()(control_device)
        fastmcp_instance.tool()(search_entities)
        fastmcp_instance.tool()(set_device_color)  # Register set_device_color like other tools
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states this is a write operation ('Set') but doesn't mention permissions, side effects, error conditions, or response format. While it specifies the action, it lacks critical behavioral details like whether this requires authentication, what happens on invalid inputs, or if changes are reversible.

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 front-loaded with the core purpose in the first sentence, followed by a structured parameter list. Every sentence earns its place by clarifying parameter details without redundancy. It's appropriately sized for a tool with multiple parameters.

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 no annotations and no output schema, the description covers the action and parameters well but lacks behavioral context (e.g., error handling, permissions) and return values. For a write operation with 5 parameters, this is minimally adequate but leaves gaps in understanding full tool behavior.

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 description coverage is 0%, so the description must fully compensate. It provides clear semantics for all 5 parameters: entity_id format ('light.entity'), RGB component ranges (0-255), and brightness as optional with range. This adds essential meaning beyond the bare schema, which only shows types and titles without context.

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?

The description clearly states the specific action ('Set the color and optionally brightness') and target resource ('a light entity'), distinguishing it from sibling tools like 'control_device' (more generic) and 'search_entities' (read-only). The verb 'set' is precise and indicates a write operation.

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

Usage Guidelines3/5

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

The description implies usage for controlling light color/brightness but doesn't explicitly state when to use this tool versus 'control_device' (which might handle other device types or operations) or 'search_entities' (for discovery). No explicit alternatives, prerequisites, or exclusions are provided, leaving usage context somewhat ambiguous.

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