Skip to main content

API — Devices

Requires Authorization: Bearer {token}.

List devices

GET /api/v1/devices?per_page=15

Create device

POST /api/v1/devices
Content-Type: application/json

{
"name": "Living room light",
"room_id": 1,
"type": "lighting",
"relay_number": 1,
"esp32_name": "sala",
"energy_monitoring": false
}

Validation:

  • esp32_name: nullable, alpha_dash, regex ^[a-z0-9_-]+$
  • relay_number: 1–16

Update device

PUT /api/v1/devices/{id}

Toggle state

PATCH /api/v1/devices/{id}/toggle

Publishes MQTT:

  • smarthome/sala/relay/1 when esp32_name is set
  • smarthome/relay/1 when esp32_name is empty

Delete

DELETE /api/v1/devices/{id}

Sample response

{
"data": {
"id": 1,
"name": "Living room light",
"type": "lighting",
"status": "offline",
"room_id": 1,
"relay_number": 1,
"esp32_name": "sala",
"room": { "id": 1, "name": "Living Room" }
}
}