update_user_variable
Update an existing user variable in Domoticz by specifying its name, type (integer, float, string, date, or time), and new value.
Instructions
Update an existing user variable.
vtype (Variable Type): 0: Integer 1: Float 2: String 3: Date (DD/MM/YYYY) 4: Time (HH:MM)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| vtype | Yes | ||
| value | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:733-747 (handler)The handler function for the 'update_user_variable' tool. It is decorated with @mcp.tool(), takes name, vtype, and value parameters, makes an HTTP GET request to Domoticz API with 'updateuservariable' command, invalidates the user variable cache, and returns the response.
@mcp.tool() async def update_user_variable(name: str, vtype: int, value: str) -> str: """Update an existing user variable. vtype (Variable Type): 0: Integer 1: Float 2: String 3: Date (DD/MM/YYYY) 4: Time (HH:MM) """ async with create_client() as client: response = await _do_request(client, "GET", f"{DOMOTICZ_API_URL}?type=command¶m=updateuservariable&vname={name}&vtype={vtype}&vvalue={value}") _user_variable_cache["timestamp"] = 0 # Invalidate cache return response.text - src/domoticz_mcp/server.py:733-734 (registration)The @mcp.tool() decorator registers the function as an MCP tool named 'update_user_variable'.
@mcp.tool() async def update_user_variable(name: str, vtype: int, value: str) -> str: - src/domoticz_mcp/server.py:734-742 (schema)Docstring describing the input parameters: name (str), vtype (int with mapping 0-4 for types), and value (str).
async def update_user_variable(name: str, vtype: int, value: str) -> str: """Update an existing user variable. vtype (Variable Type): 0: Integer 1: Float 2: String 3: Date (DD/MM/YYYY) 4: Time (HH:MM) - src/domoticz_mcp/server.py:383-385 (helper)Helper function to resolve a user variable name to its idx, used by other user variable tools but not directly by update_user_variable (which uses name directly).
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") - src/domoticz_mcp/server.py:88-88 (helper)Cache for user variables, which is invalidated (timestamp reset to 0) by update_user_variable after updating.
_user_variable_cache = {"data": None, "timestamp": 0}