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.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.
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
example response
POST /api/rules
Creates a new automation rule. Request bodyHuman-readable label for the rule, e.g.
"Low moisture pump trigger".The sensor type whose readings this rule evaluates. Use the same type string your sensors report, e.g.
SOIL_MOISTURE, TEMPERATURE, HUMIDITY, CO2, LIGHT.Comparison operator applied to incoming readings against
conditionValue. See the condition reference below.Threshold value to compare against. Stored and evaluated as a double-precision float.
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.ID of the actuator to control when the rule fires. Must reference an existing actuator.
Whether this rule is enabled and evaluated against incoming readings. Defaults to
true on creation.The
condition field accepts the following operator strings:| Value | Meaning | Fires when reading is… |
|---|---|---|
gt | greater than | strictly above conditionValue |
lt | less than | strictly below conditionValue |
gte | greater than or equal | at or above conditionValue |
lte | less than or equal | at or below conditionValue |
eq | equal | exactly equal to conditionValue |
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 parametersThe rule’s integer ID.
New display name.
New sensor type string to watch.
New comparison operator (
gt, lt, gte, lte, or eq).New threshold value.
New action string.
Reassign the rule to a different actuator.
Enable or disable the rule without deleting it.
404 Not Found if no rule exists with that ID.
example response
DELETE /api/rules/
Permanently removes a rule. The linked actuator is not affected. Path parametersThe rule’s integer ID.
{"deleted": true} on success. Returns 404 Not Found if no rule exists with that ID.
example request
example response
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%.Step 1 — verify the actuator exists
Step 1 — verify the actuator exists
"type": "PUMP" and "active": true before linking a rule to it.Step 2 — create the rule
Step 2 — create the rule
id returned in the response. You will need it to update or delete the rule.Step 3 — post a test sensor reading
Step 3 — post a test sensor reading
Submit a reading below the threshold to trigger evaluation:
Step 4 — confirm actuator status changed
Step 4 — confirm actuator status changed
"status": "ON" if the rule evaluation and actuator control pipeline are working correctly.The rule object
Auto-generated integer primary key.
Human-readable label for the rule.
The sensor type string this rule monitors, e.g.
SOIL_MOISTURE, TEMPERATURE.Comparison operator:
gt, lt, gte, lte, or eq.Threshold value as a double-precision float.
Action descriptor string passed to the action dispatcher when the rule fires.
ID of the actuator to control when this rule fires.
Whether this rule is currently enabled. Disabled rules are not evaluated. Defaults to
true.ISO-8601 timestamp of when the rule was created.