get_user_variables
Retrieve all user variables from Domoticz to monitor and manage custom data in your home automation system.
Instructions
Get all user variables.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:710-715 (handler)The main handler function for the 'get_user_variables' tool. It is decorated with @mcp.tool() and registers itself as an MCP tool named 'get_user_variables'. It fetches all user variables from Domoticz via the cached API call and returns them as JSON.
@mcp.tool() async def get_user_variables() -> str: """Get all user variables.""" async with create_client() as client: vars = await _get_cached_data(client, _user_variable_cache, f"{DOMOTICZ_API_URL}?type=command¶m=getuservariables") return json.dumps({"status": "OK", "result": vars}) - src/domoticz_mcp/server.py:88-88 (helper)Cache object for user variables, used by the get_user_variables handler to cache results with a TTL of 5 minutes.
_user_variable_cache = {"data": None, "timestamp": 0} - src/domoticz_mcp/server.py:346-352 (helper)Generic caching helper (_get_cached_data) that the handler uses to fetch and cache user variable data from the Domoticz API.
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:383-385 (helper)Helper to resolve a user variable's idx by its name, used by other user variable tools (add, update, delete).
async def _resolve_user_variable_idx(client: "httpx.AsyncClient", idx: Optional[int] = None, name: Optional[str] = None) -> Optional[int]: """Resolve a user variable to its idx.""" return await _resolve_idx(client, idx, name, _user_variable_cache, f"{DOMOTICZ_API_URL}?type=command¶m=getuservariables")