get_room_devices
Retrieves all devices and their current states for a specific room using either the room index or name.
Instructions
Get all devices and their current states in a specific room. Provide either idx or room_name.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| idx | No | ||
| room_name | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:687-708 (handler)The actual handler function for the get_room_devices tool. It accepts an idx or room_name, resolves the room name to an idx via the plans cache if needed, then fetches devices for that room plan, simplifies the device data, and returns JSON.
async def get_room_devices(idx: int | None = None, room_name: str | None = None) -> str: """Get all devices and their current states in a specific room. Provide either idx or room_name.""" if idx is None and room_name is None: return '{"status": "error", "message": "Must provide either idx or room_name"}' async with create_client() as client: if idx is None: plans = await _get_cached_data(client, _plans_cache, f"{DOMOTICZ_API_URL}?type=command¶m=getplans&order=name&used=true") for plan in plans: if plan.get("Name", "").lower() == str(room_name).lower(): idx = plan.get("idx") break if idx is None: return f'{{"status": "error", "message": "Room \'{room_name}\' not found"}}' # Using plan=idx returns the full status of all devices in the room, rather than just their IDs response = await _do_request(client, "GET", f"{DOMOTICZ_API_URL}?type=command¶m=getdevices&plan={idx}") data = response.json() if "result" in data: data["result"] = [_simplify_device(d) for d in data["result"]] return json.dumps(data) - src/domoticz_mcp/server.py:686-686 (registration)The @mcp.tool() decorator registers get_room_devices as an MCP tool on the FastMCP server instance.
@mcp.tool() - src/domoticz_mcp/server.py:387-394 (helper)The _simplify_device helper function used within get_room_devices to reduce device data to essential fields.
def _simplify_device(dev: Dict[str, Any]) -> Dict[str, Any]: """Reduce device dictionary to essential fields to save context space.""" keys_to_keep = [ "idx", "Name", "Type", "SubType", "Data", "Status", "BatteryLevel", "Favorite", "HardwareName", "LastUpdate", "TypeImg", "Usage", "CounterToday", "Temp", "Humidity" ] return {k: dev[k] for k in keys_to_keep if k in dev} - src/domoticz_mcp/server.py:687-688 (schema)The function signature defines the input schema: idx (optional int) and room_name (optional str). Output is a JSON string.
async def get_room_devices(idx: int | None = None, room_name: str | None = None) -> str: """Get all devices and their current states in a specific room. Provide either idx or room_name."""