control_blinds
Manage blinds and covers in Domoticz with commands Open, Close, or Stop. Identify the device by its index or name.
Instructions
Control blinds or covers.
Args: command: Must be 'Open', 'Close', or 'Stop'. idx: Device index. name: Device name.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | ||
| idx | No | ||
| name | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:644-662 (handler)The main handler function for the 'control_blinds' tool. It accepts a 'command' (Open, Close, or Stop), resolves the device idx by idx or name, and calls the Domoticz switchlight API with the capitalized command.
@mcp.tool() async def control_blinds(command: str, idx: int | None = None, name: str | None = None) -> str: """Control blinds or covers. Args: command: Must be 'Open', 'Close', or 'Stop'. 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 command.capitalize() not in ['Open', 'Close', 'Stop']: return '{"status": "error", "message": "command must be \'Open\', \'Close\', or \'Stop\'"}' 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={command.capitalize()}") return response.text - src/domoticz_mcp/server.py:644-646 (schema)The @mcp.tool() decorator registers 'control_blinds' as an MCP tool. The function signature and docstring define the input schema: 'command' (str, required), 'idx' (int, optional), 'name' (str, optional).
@mcp.tool() async def control_blinds(command: str, idx: int | None = None, name: str | None = None) -> str: """Control blinds or covers. - src/domoticz_mcp/server.py:644-662 (registration)The @mcp.tool() decorator on line 644 registers this function as an MCP tool named 'control_blinds' with the FastMCP server instance.
@mcp.tool() async def control_blinds(command: str, idx: int | None = None, name: str | None = None) -> str: """Control blinds or covers. Args: command: Must be 'Open', 'Close', or 'Stop'. 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 command.capitalize() not in ['Open', 'Close', 'Stop']: return '{"status": "error", "message": "command must be \'Open\', \'Close\', or \'Stop\'"}' 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={command.capitalize()}") return response.text - tests/test_server.py:289-325 (helper)Test for the control_blinds tool. Imports control_blinds, mocks the device resolution and API call, then invokes await control_blinds('Open', 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") # set_temperature_setpoint # Thermostat is idx 45 in DEVICES_MOCK_RESPONSE respx.get(f"{DOMOTICZ_API_URL}?type=command¶m=setsetpoint&idx=45&setpoint=21.5").mock( return_value=Response(200, json={"status": "OK"}) ) await set_temperature_setpoint(21.5, name="Thermostat") # control_blinds # Let's say Kitchen Light is actually a blind for this test respx.get(f"{DOMOTICZ_API_URL}?type=command¶m=switchlight&idx=2&switchcmd=Open").mock( return_value=Response(200, json={"status": "OK"}) ) await control_blinds("Open", name="Kitchen Light")