toggle_switch
Toggle a switch or light in Domoticz by specifying its IDX or name. Use IDX for precise control.
Instructions
Toggle a switch or light by IDX or Name. Prefer using IDX for precision.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| idx | No | ||
| name | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:568-578 (handler)The handler function for the toggle_switch MCP tool. It toggles a switch/light by idx or name by making a GET request to the Domoticz API with the 'Toggle' switch command.
@mcp.tool() async def toggle_switch(idx: int | None = None, name: str | None = None) -> str: """Toggle a switch or light by IDX or Name. Prefer using IDX for precision.""" if idx is None and name is None: return '{"status": "error", "message": "Must provide either idx or name"}' 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=Toggle") return response.text - src/domoticz_mcp/server.py:568-578 (registration)The @mcp.tool() decorator registers toggle_switch as an MCP tool on the FastMCP instance.
@mcp.tool() async def toggle_switch(idx: int | None = None, name: str | None = None) -> str: """Toggle a switch or light by IDX or Name. Prefer using IDX for precision.""" if idx is None and name is None: return '{"status": "error", "message": "Must provide either idx or name"}' 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=Toggle") return response.text - src/domoticz_mcp/server.py:568-578 (schema)Input schema: accepts optional idx (int) or name (str). Returns a JSON string response.
@mcp.tool() async def toggle_switch(idx: int | None = None, name: str | None = None) -> str: """Toggle a switch or light by IDX or Name. Prefer using IDX for precision.""" if idx is None and name is None: return '{"status": "error", "message": "Must provide either idx or name"}' 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=Toggle") return response.text