Skip to main content
Glama
adrighem

Domoticz MCP Server

by adrighem

analyze_energy_usage

Analyze all energy-reporting devices and summarize their energy usage for today.

Instructions

Analyze all energy-reporting devices and summarize their 'Today' usage.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler for analyze_energy_usage. Fetches all devices from Domoticz, filters for those with 'Usage' or 'CounterToday' fields (energy-reporting devices), and returns a JSON summary of current usage and today's total.
    @mcp.tool()
    async def analyze_energy_usage() -> str:
        """Analyze all energy-reporting devices and summarize their 'Today' usage."""
        async with create_client() as client:
            devices = await _get_cached_data(client, _device_cache, f"{DOMOTICZ_API_URL}?type=command¶m=getdevices&filter=all&used=true")
            results = []
            
            # Look for devices with 'Usage' or 'Counter' related fields
            for dev in devices:
                usage = dev.get("Usage")
                counter_today = dev.get("CounterToday")
                
                if usage is not None or counter_today is not None:
                    results.append({
                        "idx": dev.get("idx"),
                        "Name": dev.get("Name"),
                        "CurrentUsage": usage,
                        "TodayTotal": counter_today,
                        "Type": dev.get("Type"),
                        "SubType": dev.get("SubType")
                    })
            
            return json.dumps({"status": "OK", "result": results})
  • The tool is registered with the MCP framework via the @mcp.tool() decorator on the analyze_energy_usage function.
    @mcp.tool()
    async def analyze_energy_usage() -> str:
  • Uses the _get_cached_data helper to fetch devices from the Domoticz API with caching support.
    async with create_client() as client:
        devices = await _get_cached_data(client, _device_cache, f"{DOMOTICZ_API_URL}?type=command¶m=getdevices&filter=all&used=true")
        results = []
        
        # Look for devices with 'Usage' or 'Counter' related fields
        for dev in devices:
            usage = dev.get("Usage")
            counter_today = dev.get("CounterToday")
            
            if usage is not None or counter_today is not None:
                results.append({
                    "idx": dev.get("idx"),
                    "Name": dev.get("Name"),
                    "CurrentUsage": usage,
                    "TodayTotal": counter_today,
                    "Type": dev.get("Type"),
                    "SubType": dev.get("SubType")
                })
        
        return json.dumps({"status": "OK", "result": results})
  • The create_client helper used by analyze_energy_usage to get an authenticated HTTP client.
    def create_client(own_client: bool = False) -> DomoticzClient:
        """Create a DomoticzClient instance.
    
        Args:
            own_client: If True, creates a dedicated client that will be closed on exit.
                        If False (default), uses a shared client for connection pooling.
        """
        return DomoticzClient(own_client=own_client)
  • The _get_cached_data helper that handles caching and API requests for device data.
    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"]
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavioral traits. It indicates a read-like analysis but does not state that it is non-destructive, nor does it mention any side effects, permissions, or limitations. The description lacks sufficient behavioral 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?

The description is a single, clear sentence with no redundant words. It is front-loaded and efficiently communicates the tool's purpose.

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

Completeness4/5

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

Given the tool has no parameters and an output schema exists, the description is largely complete. However, it could briefly note that the operation is read-only. Still, it is thorough enough for a simple analysis tool.

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 zero parameters, and schema description coverage is 100%. The description adds no parameter-specific information, but no further elaboration is needed. Score is baseline 3.

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

Purpose5/5

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

The description uses a specific verb ('Analyze') and resource ('all energy-reporting devices'), and clearly states the scope ('summarize their Today usage'). This distinguishes it from all sibling tools, none of which mention energy analysis.

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

Usage Guidelines3/5

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

The description implies usage for obtaining a summary of today's energy usage but provides no explicit guidance on when to use this tool versus alternatives, or conditions when not to use it.

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