add_user_variable
Create a custom user variable with specified name, type (integer, float, string, date, or time), and initial value for Domoticz smart home automation.
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:724-738 (handler)The `add_user_variable` async function is the handler that adds a new user variable via the Domoticz API. It takes `name` (str), `vtype` (int: 0=Integer, 1=Float, 2=String, 3=Date, 4=Time), and `value` (str). It calls the Domoticz JSON API with param=adduservariable and invalidates the user variable cache after the request.
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:724-733 (schema)The input schema is defined via the function signature and docstring: `name: str`, `vtype: int` (with documented enum values 0-4), and `value: str`. The output is the raw JSON response from the Domoticz API.
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) """ - src/domoticz_mcp/server.py:723-723 (registration)The tool is registered with the MCP framework via the `@mcp.tool()` decorator on line 723, which makes it available as an MCP tool named 'add_user_variable'.
@mcp.tool() - src/domoticz_mcp/server.py:736-737 (helper)The cache invalidation on line 736 (`_user_variable_cache['timestamp'] = 0`) is a helper mechanism to ensure subsequent reads of user variables fetch fresh data after adding a new variable.
_user_variable_cache["timestamp"] = 0 # Invalidate cache return response.text