Skip to content

sensor-monitor: action-based triggers with capture/reference data passing#9

Merged
Daniel Botros (danielbotros) merged 4 commits into
mainfrom
on-trigger-actions
Jun 25, 2026
Merged

sensor-monitor: action-based triggers with capture/reference data passing#9
Daniel Botros (danielbotros) merged 4 commits into
mainfrom
on-trigger-actions

Conversation

@danielbotros

@danielbotros Daniel Botros (danielbotros) commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What

Reworks sensor-monitor from "watch a sensor and notify via a fixed notifier" into a general action model: when a rule triggers or resolves, it fires DoCommands on any resources you name.

  • Each rule has on_trigger and on_resolve action lists; each action is { "resource": <name>, "command": <DoCommand payload> } targeting any component or service.
  • Notifying is just an action — point one at a notification service with { "command": "send", ... }. The dedicated notifier/message/sendNotification path is removed; the only fixed dependency is the watched sensor.
  • on_trigger fires on the triggering edge and repeats per cooldown_seconds while triggered (default 0 = edge-only); on_resolve fires on the clearing edge.
  • Action resources are declared as dependencies in Validate and resolved at construction by short name across any API (every resource.Resource implements DoCommand).

Capture & references (carrying data between commands)

Command string values may embed {{...}} references, resolved just before sending:

  • Rule/reading context: {{value}}, {{key}}, {{threshold}}, {{operator}} (this also replaces the old {value} message templating).
  • Captured responses: an action with "capture": "<name>" stores its DoCommand response; later actions reference its fields as {{name.field}}.

A value that is exactly one reference keeps the referenced value's type; an embedded reference is substituted as text. An unresolved reference skips that action. This is how a Slack message sent on trigger is reacted to on resolve — capture: "msg" on the send, then {{msg.ts}} / {{msg.channel}} in the resolve react command. Captures are overwritten on each cooldown re-fire (so resolve uses the latest) and cleared on resolve.

{{...}} (not ${...}) is used deliberately: the Viam config reader reserves ${...} for its own placeholder replacement and rejects unknown placeholders before the module ever sees the config.

Tests & docs

resolveValue unit tests (typed/embedded/nested/missing), trigger+resolve firing, cooldown repeat, capture-carries-across-trigger-resolve, capture-missing skip, and unresolved-dependency build failure. README rewritten for the action model.

Notes

🤖 Generated with Claude Code

Add per-rule on_trigger / on_resolve action lists, each naming a resource and a
DoCommand payload. On the triggering edge the monitor fires every on_trigger
action; on the clearing edge it fires every on_resolve action — best-effort,
edge-only (not repeated on cooldown). Action resources are declared as required
dependencies in Validate and resolved at construction by short name across any
API (every resource implements DoCommand), so an action can target a board,
sensor, generic service, etc.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Remove the dedicated notifier (notifier field, message templating,
sendNotification): notifying is now just an on_trigger action targeting a
notification service. Each rule's on_trigger/on_resolve actions fire DoCommands
on any resource, on the trigger edge (and cooldown repeats) and the resolve
edge respectively.

Action commands support ${...} references resolved before sending — against
rule context (${value}, ${key}, ${threshold}, ${operator}) and against
responses captured from earlier actions via "capture". This lets a message sent
on trigger be reacted to on resolve by capturing the send response and
referencing ${msg.ts}/${msg.channel}. An unresolved reference skips that action.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@danielbotros Daniel Botros (danielbotros) changed the title sensor-monitor: fire arbitrary DoCommands on trigger and resolve sensor-monitor: action-based triggers with capture/reference data passing Jun 24, 2026
@danielbotros Daniel Botros (danielbotros) merged commit a1b66d7 into main Jun 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants