get_device_history
Retrieve historical log or graph data for a smart home device, with options for sensor type (light, text, temp, percentage, counter) and time range (day, month, year).
Instructions
Get history log or graph for a device. sensor_type: 'light', 'text', 'temp', 'percentage', 'counter'. time_range (for graphs): 'day', 'month', 'year'.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| idx | No | ||
| name | No | ||
| sensor_type | No | light | |
| time_range | No | day |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:787-806 (handler)The 'get_device_history' tool handler function. It fetches history logs or graphs for a device by idx or name, supporting sensor types: 'light', 'text', 'temp', 'percentage', 'counter', and time_range: 'day', 'month', 'year'. Registered via @mcp.tool() decorator on line 787.
@mcp.tool() async def get_device_history(idx: int | None = None, name: str | None = None, sensor_type: str = "light", time_range: str = "day") -> str: """Get history log or graph for a device. sensor_type: 'light', 'text', 'temp', 'percentage', 'counter'. time_range (for graphs): 'day', 'month', 'year'.""" 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"}' url = f"{DOMOTICZ_API_URL}?type=command" if sensor_type == "light": url += f"¶m=getlightlog&idx={resolved_idx}" elif sensor_type == "text": url += f"¶m=gettextlog&idx={resolved_idx}" else: url += f"¶m=graph&sensor={sensor_type}&idx={resolved_idx}&range={time_range}" response = await _do_request(client, "GET", url) return response.text - src/domoticz_mcp/server.py:787-788 (registration)The tool is registered using the @mcp.tool() decorator on line 787, which is the standard FastMCP registration mechanism for tools.
@mcp.tool() async def get_device_history(idx: int | None = None, name: str | None = None, sensor_type: str = "light", time_range: str = "day") -> str: - src/domoticz_mcp/server.py:788-789 (schema)Input schema/parameters: idx (int, optional), name (str, optional), sensor_type (str, default 'light'), time_range (str, default 'day'). The docstring serves as the tool description.
async def get_device_history(idx: int | None = None, name: str | None = None, sensor_type: str = "light", time_range: str = "day") -> str: """Get history log or graph for a device. sensor_type: 'light', 'text', 'temp', 'percentage', 'counter'. time_range (for graphs): 'day', 'month', 'year'.""" - src/domoticz_mcp/server.py:373-375 (helper)Helper function _resolve_device_idx used by get_device_history to resolve device idx from name.
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")