Skip to main content

Two Sides of a Trigger

A device trigger has two sides:
  1. Device side — the device fires the trigger using client.trigger() or device.trigger()
  2. Agent side — you define what happens when the trigger arrives using defineDeviceTrigger()
The device sends the event. The agent handles it.

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

The 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 using defineDeviceTrigger(). 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:
Or push everything at once:
Then deploy:

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

The execute function receives a context object:

Trigger Result Listening (Optional)

On the device side, you can optionally listen for the result of trigger execution:
This is optional. Most triggers are fire-and-forget.

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