Skip to main content
Glama
adrighem

Domoticz MCP Server

by adrighem

set_dimmer_level

Set the brightness level of a dimmer switch. Adjust level from 0 (off) to 100 (full brightness) using device name or index.

Instructions

Set the brightness level of a dimmer switch.

Args: level: Integer from 0 to 100. Note: 0 is Off, 100 is Full Brightness. idx: Device index. name: Device name.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
levelYes
idxNo
nameNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'set_dimmer_level' tool. It is decorated with @mcp.tool(), accepts a 'level' (int 0-100), optional 'idx' or 'name', validates inputs, resolves the device ID, and sends a 'Set Level' command to the Domoticz API.
    @mcp.tool()
    async def set_dimmer_level(level: int, idx: int | None = None, name: str | None = None) -> str:
        """Set the brightness level of a dimmer switch.
        
        Args:
            level: Integer from 0 to 100. Note: 0 is Off, 100 is Full Brightness.
            idx: Device index.
            name: Device name.
        """
        if idx is None and name is None:
            return '{"status": "error", "message": "Must provide either idx or name"}'
        if not (0 <= level <= 100):
            return '{"status": "error", "message": "level must be between 0 and 100"}'
        async with create_client() as client:
            resolved_idx = await _resolve_device_idx(client, idx, name)
            if resolved_idx is None:
                return '{"status": "error", "message": "Device not found"}'
            response = await _do_request(client, "GET", f"{DOMOTICZ_API_URL}?type=command¶m=switchlight&idx={resolved_idx}&switchcmd=Set%20Level&level={level}")
            return response.text
  • The tool is registered via the @mcp.tool() decorator on line 600, which is the FastMCP instance created on line 70. This decorator registers the function as an MCP tool named 'set_dimmer_level' (derived from the async function name).
    @mcp.tool()
  • Input validation schema: 'level' is an int (0-100), 'idx' is optional int, 'name' is optional string. Lines 609-612 validate that at least idx or name is provided, and that level is in range 0-100.
    @mcp.tool()
    async def set_dimmer_level(level: int, idx: int | None = None, name: str | None = None) -> str:
        """Set the brightness level of a dimmer switch.
        
        Args:
            level: Integer from 0 to 100. Note: 0 is Off, 100 is Full Brightness.
            idx: Device index.
            name: Device name.
        """
        if idx is None and name is None:
            return '{"status": "error", "message": "Must provide either idx or name"}'
        if not (0 <= level <= 100):
            return '{"status": "error", "message": "level must be between 0 and 100"}'
  • The _resolve_device_idx helper resolves a device name or idx to a Domoticz device index, used by set_dimmer_level to find the target device.
    async def _resolve_device_idx(client: "httpx.AsyncClient", idx: Optional[int] = None, name: Optional[str] = None) -> Optional[int]:
        """Resolve a device to its idx."""
        return await _resolve_idx(client, idx, name, _device_cache, f"{DOMOTICZ_API_URL}?type=command¶m=getdevices&filter=all&used=true")
  • Test that validates the set_dimmer_level tool works correctly, mocking the Domoticz API and calling set_dimmer_level(50, name='Kitchen Light').
    @pytest.mark.asyncio
    @respx.mock
    async def test_device_control_tools():
        from domoticz_mcp.server import (
            set_switch_state, set_dimmer_level, set_temperature_setpoint, control_blinds
        )
        
        # Mock resolution for Kitchen Light (idx 2)
        respx.get(f"{DOMOTICZ_API_URL}?type=command¶m=getdevices&filter=all&used=true").mock(
            return_value=Response(200, json=DEVICES_MOCK_RESPONSE)
        )
        
        # set_switch_state
        respx.get(f"{DOMOTICZ_API_URL}?type=command¶m=switchlight&idx=2&switchcmd=On").mock(
            return_value=Response(200, json={"status": "OK"})
        )
        await set_switch_state("On", name="Kitchen Light")
        
        # set_dimmer_level
        respx.get(f"{DOMOTICZ_API_URL}?type=command¶m=switchlight&idx=2&switchcmd=Set%20Level&level=50").mock(
            return_value=Response(200, json={"status": "OK"})
        )
        await set_dimmer_level(50, name="Kitchen Light")
Behavior3/5

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

No annotations exist, so the description bears the burden. It provides a useful note about 0 being Off and 100 Full Brightness, but lacks details like whether changes are gradual or instantaneous, or if the device state changes.

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

Conciseness4/5

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

The description is short, but the Args list format adds some redundancy. It could be more concise by integrating parameter info into the main sentence.

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?

For a simple setter tool with an output schema (true), the description covers the core purpose and level parameter behavior. However, missing usage guidance slightly reduces completeness.

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

Parameters3/5

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

Schema description coverage is 0%. The description explains the level parameter (integer, range 0-100) but does not describe idx or name, leaving them unexplained despite being optional.

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 'Set the brightness level of a dimmer switch,' specifying the verb (set), resource (dimmer switch/brightness level). This distinguishes it from siblings like set_switch_state (on/off) and toggle_switch.

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?

No explicit guidance on when to use this tool versus alternatives like toggle_switch or set_color_brightness. Usage is implied but not stated as a recommendation.

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/adrighem/domoticz-mcp'

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