get_room_devices
Retrieve all smart home devices and their current states for a specific room by providing its ID 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:692-714 (handler)The main handler function for the 'get_room_devices' tool. It accepts either idx or room_name, resolves room_name to idx by looking up cached plans, then queries Domoticz API for devices in that plan (room). Results are simplified using _simplify_device helper.
@mcp.tool() 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:693-693 (schema)The schema/docstring for get_room_devices: takes optional idx (int) or room_name (str) parameters.
async def get_room_devices(idx: int | None = None, room_name: str | None = None) -> str: - src/domoticz_mcp/server.py:692-692 (registration)Registration via the @mcp.tool() decorator on line 692 marking get_room_devices as an MCP tool.
@mcp.tool() - src/domoticz_mcp/server.py:387-394 (helper)Helper function _simplify_device used by get_room_devices to reduce device dictionaries 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:89-89 (helper)Cache _plans_cache used by get_room_devices to store and retrieve room plans data.
_plans_cache = {"data": None, "timestamp": 0}