Device properties are a flexible key-value store (theDocumentation 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.
device_properties table) that lets mobile clients configure per-device behavior without changing firmware. Each property has a property_key and property_value string, and the full set is returned to the ESP32 on every sync and sensor-data response. This means a user can change a threshold in the app and the device will act on it within one measurement cycle — no OTA update required.
Property Storage
Properties live in thedevice_properties table with the following structure:
| Column | Type | Notes |
|---|---|---|
id | bigint | Auto-incrementing primary key |
device_id | bigint | Foreign key to devices; cascades on delete |
property_key | string(100) | Identifies the configuration knob, e.g. humidity_threshold |
property_value | string | The value, always stored as a string |
- A unique constraint on
(device_id, property_key)ensures exactly one value per key per device. - Use
PUT /api/my-devices/{id}/propertiesto create or update a property. The backend performs an upsert (updateOrCreate) — if the key already exists it is updated in-place; if not, a new row is inserted. - Every successful property update automatically creates a
COMMANDlog entry indevice_logsrecording which key was changed and the new value. - All values are stored as plain strings. The API casts values to
booleanorintas needed before returning them indevice_controland capability responses.
Standard Property Keys
The following property keys are recognized and consumed by the backend and firmware. Any other key is passed through to the ESP32 as-is in theconfig block.
| Property Key | Value Type | Example Value | Description |
|---|---|---|---|
auto_water | boolean string | "true" / "false" | Enable automatic watering based on the humidity threshold. When true and current_state is STANDBY, the ESP32 activates the pump autonomously. |
humidity_threshold | integer string | "60" | Humidity percentage below which auto_water triggers the pump. Defaults to 60 if not set. |
has_pump | boolean string | "true" / "false" | Declares whether the device has a pump actuator. Used by mobile clients to show or hide pump controls. |
has_humidity | boolean string | "true" / "false" | Declares whether the device has a humidity sensor. Used by mobile clients to show or hide humidity readings. |
has_light | boolean string | "true" / "false" | Declares whether the device has a light sensor. Exposed as has_light_sensor in the capabilities object. |
dimmer_level | integer string | "75" | Dimmer percentage for compatible actuators. Passed through to the ESP32 in the sync config block. |
pump_duration | integer string | "10" | Duration in seconds for a single pump activation cycle. |
Update a Property
PUT /api/my-devices/{id}/properties requires a valid Sanctum token and ownership of the device. It accepts a single property update per request.
Request body:
| Field | Type | Required | Description |
|---|---|---|---|
property_key | string | ✅ Yes | The property key to create or update |
property_value | string | ✅ Yes | The new value (always a string, even for booleans and integers) |
All property values are stored as strings. The API handles casting to boolean or
int when building structured responses. When setting boolean properties from a mobile client, always send the string "true" or "false" — not the JSON literals true or false.Properties in Device Responses
Properties surface in three different shapes depending on the caller:GET /api/my-devices and GET /api/my-devices/{id} — Mobile/Web clients
GET /api/my-devices and GET /api/my-devices/{id} — Mobile/Web clients
The
UserDeviceController reads properties and builds two typed objects:capabilities — hardware feature flags cast to boolean:settings — automation configuration with proper types (only present on the single-device endpoint):GET /api/device/sync — ESP32 firmware
GET /api/device/sync — ESP32 firmware
The The firmware is responsible for parsing the string values to the appropriate native types.
DeviceSyncController returns the raw properties as a flat key→value map under the config key. All values remain strings, matching what was stored:POST /api/sensor-data response — ESP32 firmware
POST /api/sensor-data response — ESP32 firmware
The
SensorDataController injects a device_control block with pre-cast values so the ESP32 can act immediately without string parsing:ESP32 Integration
See how the ESP32 consumes the sync config and device_control blocks in practice.
Device Overview
Review the full device lifecycle and the device_logs entries created by property updates.