PhloemDocs

Get a Slack message when a limit is crossed

Post to a Slack channel when a reading crosses a value. The test keeps running.

Before you start

  • A Slack connector on Connectors in the console. Its bot needs the chat:write scope. See Slack.
  • The bot invited to the channel it posts in.
  • A Trellis setup you can deploy from Phloem Computer. See Trellis.

Steps

  1. In the console, open Alerts and choose New role.

  2. Type a role name, such as test-conductor. Use lowercase letters, digits, - or _.

  3. Pick your Slack connector in choose a connector… and type the channel, such as #test-alerts. To post in more places, press + another channel.

  4. Press Save.

  5. In Computer, open Trellis and open your setup in Code. Add an alarm that names the role in notify=:

    setup("heater")
    
    ch = channels()
    ch.read("/demo/temperature", unit="degC")
    
    alarm(
        "too_hot",
        when=ch["/demo/temperature"].above(80),
        severity="warn",
        notify=["test-conductor"],
    )
    
    page("Heater test", layout=col(alarms()))
    whenabove(x), below(x), within(lo, hi) or outside(lo, hi) on a channel
    severityinfo, warn or critical
    notifyrole names from Alerts
  6. Press Deploy.

Check it worked

When the alarm fires, Slack gets a message such as [warn] too_hot on /demo/temperature …, with how long ago it fired.

On Alerts, Recent deliveries lists each firing and its outcome:

OutcomeMeans
deliveredposted to the channel
rolled upcounted together with repeats or a burst from the same device
too old to pagefired too long ago to post as live
no such rolenotify= names a role Alerts does not have
no working channelthe role's connector is gone or inactive
failed · retryingthe send failed and is retried; hover for the reason
Note

Messages are sent from the cloud. A firing reaches Slack once the device's data does, so an offline device posts late, with the firing's age.

Updated