Two Sides of a Trigger
A device trigger has two sides:- Device side — the device fires the trigger using
client.trigger()ordevice.trigger() - Agent side — you define what happens when the trigger arrives using
defineDeviceTrigger()
Think of it as:
A doorbell. The device presses it (fires the trigger). Your agent-side code decides what to do when it rings (the execute function).
Device Side: Firing Triggers
Node.js
trigger() method resolves when the server acknowledges receipt. It does not wait for the agent to finish processing.
Python
MicroPython
Agent Side: Handling Triggers
On the agent side, create a device trigger primitive usingdefineDeviceTrigger(). This is a standalone file that gets compiled, pushed, and deployed like any other Lua primitive.
The trigger
name on the agent side uses hyphens (e.g., low-stock). The trigger name on the device side uses underscores (e.g., low_stock). The gateway maps between the two conventions automatically.Both Sides Together
Deploying Device Triggers
Device triggers are compiled and pushed like other Lua primitives:LuaDeviceTriggerConfig Reference
string
required
Trigger name. Lowercase with hyphens (e.g.,
paper-low, temperature-alert).string
Description of when this trigger fires. Helps with debugging and documentation.
ZodType
Zod schema for validating the trigger payload. The payload is validated before
execute runs.(payload, context) => Promise<any>
required
The function that runs when the trigger fires. Receives the validated payload and a context object.
Execute Context
Theexecute function receives a context object:
Trigger Result Listening (Optional)
On the device side, you can optionally listen for the result of trigger execution:Next Steps
Agent Tools
How the other direction works — agent sending commands to devices
Self-Describing Commands
How devices declare their command capabilities
Warehouse Example
Full example with triggers for low stock alerts
Industrial Sensor
MicroPython trigger example for vibration anomalies

