Actions

Actions are responses you want MudPi to make when a trigger activates. An action can be either an event or a command. The more common response is an event that MudPi is already listening for and can then act on. For example, when a soil moisture sensor has a trigger set to check when the soil gets dry it can respond with an action that emits an event to a relay turning on a pump.

Event Actions

Event actions will emit event consisting of the object you set in the action option and on the channel you set in the topic. Emitting a Switch or Toggle event to a relay topic is a great way to link a trigger to control relays.

{
    "type": "event",
    "name": "Toggle Pump",
    "key": "toggle_pump",
    "action": {"event": "Toggle"},
    "topic": "garden/pi/relays/1"
}

Command Actions

A command action will run a command string you provide in the action option. This command can be an actual command or a file to run. If you wish to run an actual command and not a file you should set shell to true. The event data that triggers the action will be passed as an argument in the form of a JSON object.

Command actions leaves the opportunity for a wide range of user define actions. This feature is a great way to add custom actions to MudPi allowing you build quite a robust setup. For example you could fire a script that sends you a SMS message when your water tank is low. Below is an example of what that action might look like.

{
    "type": "command",
    "name": "Send SMS text",
    "key": "send_sms_text",
    "action": "python3 send_sms.py",
    "shell": true
}