A while back I wanted an app to notify several people when something happened. It came in handy when my phone’s batteries had died yesterday. One of the other recipients got the message as was able to address the situation. Anyway, I thought I’d share the little snip that can be used anywhere you send an SMS in your apps.
To use it, create a phone number input in your preferences. When you want to have multiple numbers, separate them with a semicolon. Like you do in multiple email addresses.
It can be written a lot better, but I kept it basic and longhand. Here’s the snip:
def msg = "This is a message to you from my SmartThings thing"
if (phone) {
if ( phone.indexOf(";") > 1){
def phones = phone.split(";")
for ( def i = 0; i < phones.size(); i++) {
log.debug "sending SMS ${i+1} to ${phones[i]}"
sendSms(phones[i], msg)
}
}
else {
log.debug "sending SMS to ${phone}"
sendSms(phone, msg)
}
}
Ah, so the input is just a string type textbox with numbers separated by semicolons?
I still keep hoping that “people” in SmartThings become a first class citizen that can have phone numbers and presence tags associated with them that we can enumerate, etc.
Thanks. I tested putting two numbers into the SmartThings native apps separated by either a semicolor or a comma. It does not work. If more than one number exists in the SMS text field, nothing is sent. This really is something that SmartThings apps should support. When the security alarm is ringing or motion is detected where it should not be, I would think most people would want to send the SMS text to more than one phone.
hi,
can anyone help me how to send sms notification in particular instance even when the person doesn’t have smart app. I tries using the code “sendSms” but still not receiving any message