create_virtual_sensor
Create a virtual sensor in Domoticz by providing the hardware index, sensor name, and sensor type (e.g., temperature, humidity).
Instructions
Create a virtual sensor.
hw_idx: IDX of the dummy hardware.
sensortype (Sensor Type): 1: Temperature 2: Humidity 3: Temp + Humidity 4: Barometer 5: Temp + Hum + Baro 6: Rain 7: UV 8: Wind 10: Lux 11: Voltage 12: Current 13: Distance 14: Text 15: Alert 17: Percentage 19: Counter 113: kWh (Energy)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hw_idx | Yes | ||
| sensorname | Yes | ||
| sensortype | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:1033-1061 (handler)The main handler for the create_virtual_sensor tool. It is decorated with @mcp.tool() and registers itself as an MCP tool. It takes hw_idx (dummy hardware IDX), sensorname (sensor name), and sensortype (integer code for sensor type), then calls the Domoticz JSON API endpoint 'createvirtualsensor'. It also invalidates the device cache after creation.
@mcp.tool() async def create_virtual_sensor(hw_idx: int, sensorname: str, sensortype: int) -> str: """Create a virtual sensor. hw_idx: IDX of the dummy hardware. sensortype (Sensor Type): 1: Temperature 2: Humidity 3: Temp + Humidity 4: Barometer 5: Temp + Hum + Baro 6: Rain 7: UV 8: Wind 10: Lux 11: Voltage 12: Current 13: Distance 14: Text 15: Alert 17: Percentage 19: Counter 113: kWh (Energy) """ async with create_client() as client: response = await _do_request(client, "GET", f"{DOMOTICZ_API_URL}?type=command¶m=createvirtualsensor&idx={hw_idx}&sensorname={urllib.parse.quote(sensorname)}&sensortype={sensortype}") _device_cache["timestamp"] = 0 # Invalidate cache return response.text - src/domoticz_mcp/server.py:1033-1034 (registration)Registration via the @mcp.tool() decorator on line 1033 registers 'create_virtual_sensor' as an MCP tool in the FastMCP server instance.
@mcp.tool() async def create_virtual_sensor(hw_idx: int, sensorname: str, sensortype: int) -> str: - src/domoticz_mcp/server.py:1035-1057 (schema)Input schema defined via the docstring and type annotations: hw_idx (int), sensorname (str), sensortype (int). The docstring also documents the valid sensortype integer codes.
"""Create a virtual sensor. hw_idx: IDX of the dummy hardware. sensortype (Sensor Type): 1: Temperature 2: Humidity 3: Temp + Humidity 4: Barometer 5: Temp + Hum + Baro 6: Rain 7: UV 8: Wind 10: Lux 11: Voltage 12: Current 13: Distance 14: Text 15: Alert 17: Percentage 19: Counter 113: kWh (Energy) """