Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/diarpicu2022-commits/backend-AgroPulse/llms.txt

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

Rules are the automation engine of AgroPulse. Each rule watches a specific sensor type and fires an action — typically activating an actuator — when a live reading crosses a configured threshold. For example, you can define a rule that turns on an irrigation pump whenever soil moisture drops below 30%, or that activates a fan whenever temperature exceeds 35 °C. Rules are evaluated server-side each time a sensor reading is ingested.
The condition field uses short operator codes: gt (greater than), lt (less than), gte (greater than or equal), lte (less than or equal), and eq (equal). Values are stored and compared as double precision floats.

Endpoints

GET /api/rules

Returns all rules as a JSON array (not wrapped in an envelope object). Response A bare JSON array of rule objects.
example request
curl http://localhost:8080/api/rules
example response
[
  {
    "id": 1,
    "name": "Low moisture pump trigger",
    "sensor": "SOIL_MOISTURE",
    "condition": "lt",
    "conditionValue": 30.0,
    "action": "activate_pump",
    "actuatorId": 5,
    "active": true,
    "createdAt": "2024-03-10T09:00:00"
  }
]

POST /api/rules

Creates a new automation rule. Request body
name
string
required
Human-readable label for the rule, e.g. "Low moisture pump trigger".
sensor
string
required
The sensor type whose readings this rule evaluates. Use the same type string your sensors report, e.g. SOIL_MOISTURE, TEMPERATURE, HUMIDITY, CO2, LIGHT.
condition
string
required
Comparison operator applied to incoming readings against conditionValue. See the condition reference below.
conditionValue
number
required
Threshold value to compare against. Stored and evaluated as a double-precision float.
action
string
Free-form string describing the action to perform when the condition is met, e.g. "activate_pump" or "turn_on_heater". Interpreted by the action dispatcher.
actuatorId
number
ID of the actuator to control when the rule fires. Must reference an existing actuator.
active
boolean
default:"true"
Whether this rule is enabled and evaluated against incoming readings. Defaults to true on creation.
Condition values
The condition field accepts the following operator strings:
ValueMeaningFires when reading is…
gtgreater thanstrictly above conditionValue
ltless thanstrictly below conditionValue
gtegreater than or equalat or above conditionValue
lteless than or equalat or below conditionValue
eqequalexactly equal to conditionValue
Response Returns the created rule object.
curl -X POST http://localhost:8080/api/rules \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Low moisture pump trigger",
    "sensor": "SOIL_MOISTURE",
    "condition": "lt",
    "conditionValue": 30,
    "action": "activate_pump",
    "actuatorId": 5,
    "active": true
  }'

PUT /api/rules/

Updates one or more fields on an existing rule. Only fields present in the request body are changed; omitted fields retain their current values. Path parameters
id
number
required
The rule’s integer ID.
Request body All body fields are optional. Include only the fields you want to change.
name
string
New display name.
sensor
string
New sensor type string to watch.
condition
string
New comparison operator (gt, lt, gte, lte, or eq).
conditionValue
number
New threshold value.
action
string
New action string.
actuatorId
number
Reassign the rule to a different actuator.
active
boolean
Enable or disable the rule without deleting it.
Returns the updated rule object. Returns 404 Not Found if no rule exists with that ID.
curl -X PUT http://localhost:8080/api/rules/3 \
  -H "Content-Type: application/json" \
  -d '{"conditionValue": 25, "active": true}'
example response
{
  "id": 3,
  "name": "Low moisture pump trigger",
  "sensor": "SOIL_MOISTURE",
  "condition": "lt",
  "conditionValue": 25.0,
  "action": "activate_pump",
  "actuatorId": 5,
  "active": true,
  "createdAt": "2024-03-15T11:05:00"
}

DELETE /api/rules/

Permanently removes a rule. The linked actuator is not affected. Path parameters
id
number
required
The rule’s integer ID.
Returns {"deleted": true} on success. Returns 404 Not Found if no rule exists with that ID.
example request
curl -X DELETE http://localhost:8080/api/rules/3
example response
{
  "deleted": true
}

Worked example: SOIL_MOISTURE < 30 → activate actuator 5

This example walks through creating a rule that turns on a pump (actuator ID 5) whenever soil moisture drops below 30%.
curl http://localhost:8080/api/actuators/5
Confirm the response includes "type": "PUMP" and "active": true before linking a rule to it.
curl -X POST http://localhost:8080/api/rules \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Soil moisture low — run pump",
    "sensor": "SOIL_MOISTURE",
    "condition": "lt",
    "conditionValue": 30,
    "action": "activate_pump",
    "actuatorId": 5,
    "active": true
  }'
Note the id returned in the response. You will need it to update or delete the rule.
Submit a reading below the threshold to trigger evaluation:
curl -X POST http://localhost:8080/api/readings \
  -H "Content-Type: application/json" \
  -d '{
    "sensorType": "SOIL_MOISTURE",
    "value": 22.5,
    "greenhouseId": 3
  }'
curl http://localhost:8080/api/actuators/5
Expect "status": "ON" if the rule evaluation and actuator control pipeline are working correctly.
The fastest way to confirm a rule is working end-to-end is to post a sensor reading that deliberately crosses the threshold, then immediately fetch the target actuator and check its status field. If status has moved to ON (or OFF, depending on your rule), the automation pipeline is functioning correctly.

The rule object

id
number
required
Auto-generated integer primary key.
name
string
required
Human-readable label for the rule.
sensor
string
The sensor type string this rule monitors, e.g. SOIL_MOISTURE, TEMPERATURE.
condition
string
Comparison operator: gt, lt, gte, lte, or eq.
conditionValue
number
Threshold value as a double-precision float.
action
string
Action descriptor string passed to the action dispatcher when the rule fires.
actuatorId
number
ID of the actuator to control when this rule fires.
active
boolean
Whether this rule is currently enabled. Disabled rules are not evaluated. Defaults to true.
createdAt
string
ISO-8601 timestamp of when the rule was created.

Build docs developers (and LLMs) love