add_user_variable
Add a new user variable to Domoticz by specifying its name, type, and initial value.
Instructions
Add a new 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:717-731 (handler)The actual tool handler for add_user_variable. Registered with @mcp.tool(), it sends a GET request to Domoticz API with 'adduservariable' command, passing name, vtype, and value. Also invalidates the user variable cache so subsequent reads get fresh data.
@mcp.tool() async def add_user_variable(name: str, vtype: int, value: str) -> str: """Add a new 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=adduservariable&vname={name}&vtype={vtype}&vvalue={value}") _user_variable_cache["timestamp"] = 0 # Invalidate cache return response.text - src/domoticz_mcp/server.py:717-717 (registration)Registration of add_user_variable as an MCP tool via the @mcp.tool() decorator on line 717.
@mcp.tool() - src/domoticz_mcp/server.py:717-731 (schema)Input schema defined via type hints (name: str, vtype: int, value: str) and docstring that documents the vtype parameter values (0-4).
@mcp.tool() async def add_user_variable(name: str, vtype: int, value: str) -> str: """Add a new 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=adduservariable&vname={name}&vtype={vtype}&vvalue={value}") _user_variable_cache["timestamp"] = 0 # Invalidate cache return response.text - src/domoticz_mcp/server.py:717-731 (helper)Uses the helper function create_client() for HTTP client lifecycle and _do_request() for authenticated request handling with OAuth token refresh retry.
@mcp.tool() async def add_user_variable(name: str, vtype: int, value: str) -> str: """Add a new 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=adduservariable&vname={name}&vtype={vtype}&vvalue={value}") _user_variable_cache["timestamp"] = 0 # Invalidate cache return response.text - src/domoticz_mcp/server.py:88-88 (helper)The cache that stores user variables data; add_user_variable invalidates this cache by resetting its timestamp to 0.
_user_variable_cache = {"data": None, "timestamp": 0}