get_device
Retrieve the current status and details of a specific Domoticz device by IDX or name.
Instructions
Get a specific device state by IDX or Name from Domoticz.
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:562-572 (handler)The `get_device` tool handler function. It accepts optional `idx` or `name` parameters, resolves the device index using `_resolve_device_idx`, makes the API call to Domoticz, and returns the device state as JSON.
@mcp.tool() async def get_device(idx: int | None = None, name: str | None = None) -> str: """Get a specific device state by IDX or Name from Domoticz.""" 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=getdevices&rid={resolved_idx}") return response.text - src/domoticz_mcp/server.py:562-562 (registration)The `@mcp.tool()` decorator on line 562 registers `get_device` as an MCP tool.
@mcp.tool() - src/domoticz_mcp/server.py:562-563 (schema)The function signature defines the input schema: `idx` (optional int) and `name` (optional str). The docstring describes the purpose.
@mcp.tool() async def get_device(idx: int | None = None, name: str | None = None) -> str: - src/domoticz_mcp/server.py:373-376 (helper)The `_resolve_device_idx` helper is used by `get_device` to convert a device name to its idx, or pass through an existing idx.
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") - src/domoticz_mcp/server.py:354-370 (helper)The generic `_resolve_idx` helper that performs cached name-to-idx resolution with case-insensitive matching.
async def _resolve_idx( client: "httpx.AsyncClient", idx: Optional[int], name: Optional[str], cache: Dict[str, Any], api_url: str ) -> Optional[int]: """Resolve an entity to its idx by either using the provided idx or looking up by name.""" if idx is not None: return idx if not name: return None items = await _get_cached_data(client, cache, api_url) for item in items: if item.get("Name", "").lower() == name.lower(): return int(str(item.get("idx"))) return None