Skip to main content
Glama
adrighem

Domoticz MCP Server

by adrighem

get_device_history

Retrieve historical logs or graphs for a device by specifying sensor type (light, temp, etc.) 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

TableJSON Schema
NameRequiredDescriptionDefault
idxNo
nameNo
sensor_typeNolight
time_rangeNoday

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The `get_device_history` tool handler function. It retrieves history logs or graphs for a device by idx or name, supporting sensor types: 'light', 'text', 'temp', 'percentage', 'counter' and time ranges: 'day', 'month', 'year'. Uses Domoticz API endpoints getlightlog, gettextlog, or graph depending on sensor_type.
    @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
  • The schema/type annotations for the tool parameters: idx (optional int), name (optional str), sensor_type (str, default 'light'), time_range (str, default 'day'). Docstring documents allowed values.
    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'."""
  • The tool is registered via the @mcp.tool() decorator on the get_device_history function (line 793).
    @mcp.tool()
  • The `_resolve_device_idx` helper used by get_device_history to resolve a device idx from either an explicit idx or a device 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")
  • The `_do_request` helper used by get_device_history to perform HTTP requests with retry on 401 (token refresh).
    async def _do_request(client: httpx.AsyncClient, method: str, url: str, **kwargs) -> httpx.Response:
        """Perform a request with a single retry on 401 Unauthorized to handle expired tokens."""
        global _oauth_token_cache
        
        try:
            resp = await client.request(method, url, **kwargs)
            if resp.status_code == 401:
                # Token might be expired. Clear cache and retry once.
                _oauth_token_cache = None
                
                # Re-fetch token (this will trigger OAuth flow if needed)
                new_token = await _fetch_oauth_token(force_refresh=True)
                if new_token:
                    # Update headers for the retry
                    if "headers" not in kwargs:
                        kwargs["headers"] = {}
                    kwargs["headers"]["Authorization"] = f"Bearer {new_token}"
                    
                    # Retry the request
                    resp = await client.request(method, url, **kwargs)
            
            resp.raise_for_status()
            return resp
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It discloses that the output can be a log or graph based on parameters, but does not clarify read/write behavior, authentication needs, or other side effects. An output schema exists but the description does not add further context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, no extraneous information. The first sentence immediately states the purpose, and the second provides parameter details. Efficient and front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite having an output schema, the description fails to fully explain all four input parameters or provide usage context (e.g., how to choose between `idx` and `name`). Given the lack of annotation coverage, completeness is insufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0% description coverage. The description adds meaning for `sensor_type` and `time_range` by listing allowed values, but does not explain `idx` and `name` parameters. Partial compensation but incomplete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it retrieves a history log or graph for a device, which is a specific verb+resource. However, it does not explicitly distinguish from sibling tools like `get_log`, but the mention of 'for a device' provides some differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives such as `get_device` or `get_log`. There is no mention of prerequisites or exclusion criteria.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/adrighem/domoticz-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server