Skip to main content
Glama

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

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