Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/GaelCeballos/Smart_Enviro_Backend/llms.txt

Use this file to discover all available pages before exploring further.

Toggles the actuator state of a device owned by the authenticated user. The new current_state (ON, OFF, or STANDBY) is persisted and returned to the ESP32 on its next GET /api/device/sync call or in the device_control block of the next POST /api/sensor-data response.

Endpoint

FieldValue
MethodPOST
Path/api/my-devices/{id}/toggle
AuthBearer token required (Authorization: Bearer YOUR_TOKEN)

Path Parameters

id
integer
required
The unique ID of the device whose state should be changed. The device must belong to the authenticated user.

Request Body

state
string
required
The new actuator state to set. Must be exactly one of:
  • ON — activate the actuator
  • OFF — deactivate the actuator
  • STANDBY — place the device in standby mode

Request Example

curl -X POST http://localhost/api/my-devices/1/toggle \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"state": "ON"}'

Responses

200 OK

The device state was updated successfully.
{
  "status": "success",
  "message": "Estado acutalizado a ON",
  "current_state": "ON"
}
status
string
Always "success" on a 200 response.
message
string
Confirmation including the new state (e.g. "Estado acutalizado a ON"). Note: the message text is returned verbatim from the controller.
current_state
string
The device’s new state after the update: ON, OFF, or STANDBY.

404 Not Found

The device does not exist or does not belong to the authenticated user.
{
  "status": "error",
  "message": "Dispositivo no encontrado"
}

422 Unprocessable Entity

The state field is missing or contains a value other than ON, OFF, or STANDBY.
{
  "message": "The state field must be one of ON, OFF, STANDBY.",
  "errors": {
    "state": ["The selected state is invalid."]
  }
}

The state change is not pushed to the device in real-time. The ESP32 will receive the new command on its next GET /api/device/sync request or in the device_control.current_state field of its next sensor data response.

Build docs developers (and LLMs) love