Docs
Commands API

Commands API

Send commands to your devices and read sensor data in real-time.

Send Command

Execute a tool/command on a device module.

POST /api/devices/command

Request Body

{
  "deviceId": "550e8400-e29b-41d4-a716-446655440000",
  "moduleId": "NeoPixel",
  "tool": "set_pixel",
  "params": {
    "index": 0,
    "r": 255,
    "g": 0,
    "b": 128
  }
}
FieldTypeRequiredDescription
deviceIduuidNoTarget specific device (omit for all devices)
moduleIdstringNoTarget specific module type
toolstringYesThe tool/command to execute
paramsobjectNoTool-specific parameters

Response

{
  "success": true,
  "message": "Tool \"set_pixel\" executed on 1 device(s)",
  "results": [
    {
      "deviceId": "550e8400-e29b-41d4-a716-446655440000",
      "deviceName": "Living Room Hub",
      "moduleId": "NeoPixel",
      "moduleName": "RGB LED Strip",
      "success": true,
      "method": "websocket",
      "result": { "status": "ok" }
    }
  ],
  "summary": {
    "total": 1,
    "successful": 1,
    "queued": 0,
    "failed": 0
  }
}

Command Delivery

Commands are delivered via WebSocket for immediate execution. If a device is offline, commands are queued and will be executed when the device reconnects.

MethodDescription
websocketCommand delivered in real-time
queuedDevice offline, command queued for later

Read Sensor

Read a current sensor value from a device.

POST /api/devices/read

Request Body

{
  "deviceId": "550e8400-e29b-41d4-a716-446655440000",
  "moduleId": "SHT40",
  "tool": "read_temperature"
}
FieldTypeRequiredDescription
deviceIduuidYesThe device to read from
moduleIdstringYesThe module to read from
toolstringYesThe read tool to execute
paramsobjectNoTool-specific parameters

Response

{
  "deviceId": "550e8400-e29b-41d4-a716-446655440000",
  "moduleId": "SHT40",
  "tool": "read_temperature",
  "value": 23.5,
  "unit": "celsius",
  "timestamp": "2024-01-15T10:30:00Z"
}

Common Tools

Sensors

ToolModule TypesDescriptionReturns
read_temperatureSHT40, SHTC3, BMP280Read temperature{ value: number, unit: "celsius" }
read_humiditySHT40, SHTC3Read relative humidity{ value: number, unit: "percent" }
read_luxVEML7700Read ambient light{ value: number, unit: "lux" }
read_pressureBMP280Read barometric pressure{ value: number, unit: "hPa" }
read_vocSGP40Read VOC index{ value: number, unit: "index" }
read_allAnyRead all available sensors{ temperature: ..., humidity: ..., ... }

Actuators

ToolModule TypesDescriptionParameters
turn_onRelay, NeoPixelTurn output onNone
turn_offRelay, NeoPixelTurn output offNone
toggleRelay, NeoPixelToggle stateNone
set_brightnessNeoPixelSet LED brightness{ brightness: 0-255 }
set_colorNeoPixelSet LED color{ r: 0-255, g: 0-255, b: 0-255 }
set_pixelNeoPixelSet individual pixel{ index: number, r, g, b }
play_toneBuzzerPlay a tone{ frequency: Hz, duration: ms }

Broadcast Commands

To send a command to all devices with a specific module type, omit the deviceId:

{
  "moduleId": "NeoPixel",
  "tool": "set_color",
  "params": { "r": 0, "g": 255, "b": 0 }
}

This will execute the command on every device that has a NeoPixel module.

Error Handling

Device Offline

{
  "success": true,
  "message": "Tool \"set_color\" queued for 1 offline device(s)",
  "results": [
    {
      "deviceId": "...",
      "success": false,
      "method": "queued",
      "queued": true,
      "error": "Device not connected"
    }
  ]
}

Module Not Found

{
  "success": false,
  "error": "Module not found",
  "message": "Could not find module NeoPixel on your devices.",
  "availableDevices": [
    {
      "id": "...",
      "name": "Living Room Hub",
      "modules": [
        { "id": "SHT40", "name": "Temperature & Humidity" }
      ]
    }
  ]
}