Documentation
Actions
Actions are operations MudPi performs in response to triggers, enabling automation of your garden system.
Overview
Actions define what happens when a trigger fires. They can control components, call namespace commands, or execute custom logic. Actions are the output side of MudPi's automation pipeline.
Action Categories
Actions fall into three categories based on how they are addressed:
Namespace Actions
Target a namespace-level action using the format {namespace}.{action}:
{
"action": "pump.turn_on"
}
Component Actions
Target a specific component by its key using the format .{component_key}.{action}:
{
"action": ".water_pump.turn_on"
}
Interface Actions
Target an interface within a namespace using the format {namespace}.{interface}.{action}:
{
"action": "toggle.gpio.turn_on"
}
Custom Actions
Call a registered custom action by key using the format .{action_key}:
{
"action": ".my_custom_action"
}
Example: Trigger with Toggle Action
Here is a complete example combining a trigger with an action to turn on a water pump when moisture is low:
Calling Actions Programmatically
From MudPi Core
Actions can be called directly from within the MudPi core using the action manager:
mudpi.actions.call('.water_pump.turn_on')
Via the Event System
You can also trigger actions by publishing an action_call event:
mudpi.events.publish('action_call', {
'action': '.water_pump.turn_on'
})
Via Redis CLI
Actions can be triggered externally through Redis pub/sub:
redis-cli PUBLISH "mudpi:action_call" '{"action": ".water_pump.turn_on"}'
Note
All actions must be registered before they can be called. Components automatically register their actions when loaded. Custom actions are registered through extensions.