SMS Alert Variables


#1

Hi All,
I’m currently using the Exosite portal to monitor some temperatures and send alerts if they reach certain conditions (ie above y for x minutes) using the built-in SMS alerts/events. Which is fine but now I’m trying to extend the info that’s being sent in that SMS to include what temperature it is and how long it’s been above the limit for.
I’m not sure if that can be configured within the default Event alerts so I’m assuming I need to create a script to do that but I’m not sure where to start. Is anyone able to direct me in the right direction with either an existing script or something similar.

I’d also like to know if it’s possible to email the graph of a data set when the same event above is triggered so the email recipients can see what’s been going on for a period of time up until the email was sent.

FYI if you want to see my exosite portal I’ve shared it publicly for people
https://portals.exosite.com/views/3154117992/2590528361

Cheers Alex


#2

Hey - great post question. SMS Alerts (these are a resource called dispatches in our One Platform) can technically have some data added in them, but not fully meet your needs. If you check out this docs section, it details this a bit more: http://docs.exosite.com/oneplatform/#dispatches

As a part of the ‘message’, you can use substitutions. Currently we support these two:

[[value]] - The value passed into this dispatch
[[subscribe.cid]] - The RID of the client of this resource.

Unfortunately though when using the alerts in Portals, which subscribe to a datarule (Event), the value will always be a 1 or 0 because of how datarules work. Although we may be able to get what you want through subscriptions (dataport -> datarule -> dispatches), it is much easier to do with Lua scripts in the platform.

There are a number of examples of platform lua scripts here: https://github.com/exosite-garage/PlatformScripts

Here is one that shows basics of sending a SMS: https://github.com/exosite-garage/PlatformScripts/blob/master/Dispatches/hello_sms.lua

The logic for triggering on a value over a certain threshold over a certain amount of time shouldn’t be too bad to create. Happy to review code if you want to post something here you come up with.

-Mike


#3

Cheers Mike,
So it is possible to do what I’m aiming too with Lua scripts I just have to do the whole process within a script.
Would it be I use the existing events I’ve created to trigger a script to pull the current value from a data Alias and then email/SMS it?
or would I have to create a script that does the whole process including the conditional checks?

I’ve currently been playing around and gotten this script. Which debug wise pulls the temp but can I swap that dataport_alias to an event alias to trigger the script then pull the temp data as I’ve done here to send?

-- This script will send every new value from the dataport of
-- your choice over an email message.

--------------- Configure These Variables ---------------------
local dataport_alias = alias['28-0000062ae0fa'] -- dataport to monitor
local email_recipient = 'alex@ynema.net' -- user email address
---------------------------------------------------------------

debug("Started")

while true do
  local timestamp = dataport_alias.wait()
  local email_msg = "At "..date().." the temperature: "..dataport_alias.value.."°C"
  local email_sub = email_msg
  dispatch.email(email_recipient, email_sub, email_msg)
  debug("Debug: "..email_msg)
end

#4

You ‘could’ use the events (datarules) and trigger off of those since datarules are just like dataports in regards to reading their values in scripts or waiting for new values in the scripts.

Yes you can do this, datarules (events in portals) can be aliased the same way as dataports. You’ll have to be sure your datarule has an alias. You’ll also want to check if the datarule only changes value on state change or if it writes a value each time it processes the new data value.

If you haven’t already - our command line tool Exoline has some nice features to easily look at your device and it’s resources, etc.