Skip to content

Rules & Automations

Rules are IF/THEN automations evaluated by the RuleEngine against incoming glucose data. A rule belongs to a patient: a trigger (e.g. glucose > 200, or always) fires up to 3 ordered actions (Webhook, Telegram, Home Assistant, …) via the IntegrationService registry.

Rules have no API-key REST equivalent: manage them from the dashboard (/rules, session cookie) or through the MCP server (list_rules, create_rule, test_rule, delete_rule). test_rule executes the actions for real, so it requires a write-scoped key.

Limits

PlanRules
Free5
Pro / Clinic / Founder50

Each rule supports at most MAX_ACTIONS_PER_RULE = 3 actions (ACTION_LIMIT_REACHED beyond that). Enforced on create/update via canCreateRule → 402.

Execution model

  • triggerConditions describe the IF side; actions run in executionOrder sequence.
  • triggerOnce latches the rule after the first fire until conditions clear.
  • Rule executions in the last 5 minutes feed the admin rulesPerMinute metric — executions are the transport webhooks live on.

Logs

GET /api/v1/rules/:id/logs (dashboard, session auth) shows executions from the last 30 days; if the window is empty it falls back to the latest 2,000 records (paginated). Old rows are never deleted by this logic — it only scopes reads.

Webhook actions

Prefer webhook-as-action over the removed standalone webhooks (see Webhooks). Payloads support {{sgv}}-style variables, with 3× exponential-backoff retry and X-Levelcast-Signature: sha256=… HMAC on delivery.