get_scenes
Retrieve all scenes and groups configured in your Domoticz home automation system.
Instructions
Get all scenes and groups from Domoticz.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:664-669 (handler)The main handler function for the 'get_scenes' tool. Uses the DomoticzClient to call the Domoticz API with param=getscenes, caches the result via _get_cached_data, and returns the scenes as JSON.
@mcp.tool() async def get_scenes() -> str: """Get all scenes and groups from Domoticz.""" async with create_client() as client: scenes = await _get_cached_data(client, _scene_cache, f"{DOMOTICZ_API_URL}?type=command¶m=getscenes") return json.dumps({"status": "OK", "result": scenes}) - src/domoticz_mcp/server.py:664-666 (registration)Registration: The @mcp.tool() decorator registers 'get_scenes' as a tool in the FastMCP server instance.
@mcp.tool() async def get_scenes() -> str: """Get all scenes and groups from Domoticz.""" - src/domoticz_mcp/server.py:346-352 (helper)Helper function used by get_scenes to fetch and cache data from the Domoticz API, with a 5-minute TTL.
async def _get_cached_data(client: "httpx.AsyncClient", cache_obj: Dict[str, Any], api_url: str, key_path: str = "result") -> List[Dict[str, Any]]: now = time.time() if cache_obj["data"] is None or (now - cache_obj["timestamp"]) > CACHE_TTL: response = await _do_request(client, "GET", api_url) cache_obj["data"] = response.json().get(key_path, []) cache_obj["timestamp"] = now return cache_obj["data"] - src/domoticz_mcp/server.py:87-89 (helper)Global cache object for scenes, used by get_scenes to avoid repeated API calls.
_scene_cache = {"data": None, "timestamp": 0} _user_variable_cache = {"data": None, "timestamp": 0} _plans_cache = {"data": None, "timestamp": 0} - src/domoticz_mcp/server.py:378-380 (helper)Helper to resolve a scene by name or idx, used by other scene-related tools (e.g., switch_scene, get_scene_devices). Uses the same _scene_cache.
async def _resolve_scene_idx(client: "httpx.AsyncClient", idx: Optional[int] = None, name: Optional[str] = None) -> Optional[int]: """Resolve a scene to its idx.""" return await _resolve_idx(client, idx, name, _scene_cache, f"{DOMOTICZ_API_URL}?type=command¶m=getscenes")