Documentation
Triggers
Triggers evaluate sensor data against thresholds and activate actions when conditions are met.
Overview
Triggers are the backbone of MudPi's automation system. They monitor data from sensors, controls, and other components, comparing values against configured thresholds. When a condition is met, the trigger fires and executes one or more actions.
Trigger Interfaces
Triggers can monitor different types of data sources through interfaces:
| Interface | Description |
|---|---|
sensor |
Monitor sensor readings (moisture, temperature, etc.) |
control |
React to control state changes |
state |
Watch for changes in any component's state |
cron |
Time-based triggers using cron expressions |
toggle |
React to toggle on/off state changes |
group |
Combine multiple triggers with AND/OR logic |
Activation Frequency
Triggers can be configured to fire with different frequencies:
once— The trigger fires only the first time the condition is met and will not fire again until the condition resets (goes false and then true again).many— The trigger fires every time the condition is evaluated as true, on each polling cycle.
Note
If not specified, triggers default to once to prevent repeated action calls from a single sustained condition.
Thresholds
Thresholds define the conditions a trigger evaluates. Each threshold specifies a comparison operator, a value, and an optional source format.
Comparison Operators
| Operator | Name | Description |
|---|---|---|
eq |
Equal | Value equals the threshold |
ne |
Not Equal | Value does not equal the threshold |
gt |
Greater Than | Value is greater than the threshold |
gte |
Greater Than or Equal | Value is greater than or equal to the threshold |
lt |
Less Than | Value is less than the threshold |
lte |
Less Than or Equal | Value is less than or equal to the threshold |
ex |
Exists | Value exists (is not null) |
is |
Is | Strict equality check (type-sensitive) |
not |
Not | Strict inequality check (type-sensitive) |
in |
In | Value is contained within a list |
Threshold Configuration Options
| Option | Type | Description |
|---|---|---|
comparison |
String | The comparison operator to use (see table above) |
value |
Mixed | The threshold value to compare against |
type |
String | Data type to cast value to before comparison |
format |
String | Format string for parsing the threshold value |
source_type |
String | Data type to cast the source value to before comparison |
source_format |
String | Format string for parsing the source value |
Example Configurations
A simple trigger that fires when soil moisture drops below 40%:
{
"key": "low_moisture_trigger",
"interface": "sensor",
"source": "soil_sensor_1",
"nested_source": "moisture",
"thresholds": [
{
"comparison": "lt",
"value": 40,
"type": "int"
}
],
"actions": [
{
"action": "turn_on",
"component": "water_pump"
}
],
"frequency": "once"
}
A trigger that checks if temperature is within a specific range:
{
"key": "temp_range_trigger",
"interface": "sensor",
"source": "greenhouse_temp",
"thresholds": [
{
"comparison": "gte",
"value": 85,
"type": "float"
}
],
"actions": [
{
"action": "turn_on",
"component": "exhaust_fan"
}
]
}
Trigger Groups
Trigger groups let you combine multiple triggers with logical operators. A group trigger uses the group interface and references other triggers by key. This is useful when you need multiple conditions to be true before taking action.
{
"key": "safe_to_water",
"interface": "group",
"triggers": ["low_moisture_trigger", "not_raining_trigger"],
"operator": "and",
"actions": [
{
"action": "turn_on",
"component": "water_pump"
}
]
}
Tip
Use trigger groups with the and operator for safety checks. For example, only water when moisture is low and it's not currently raining.