Abusing the Internet of Things

(Rick Simeone) #1
/**
* Text Me When It Opens
*
* Author: SmartThings
*/
definition(
name: "Text Me When It Opens",
namespace: "smartthings",
author: "SmartThings",
description: "Get a text message sent to your phone when an open/close sensor
is opened.",
category: "Convenience",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/window_contact.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/
[email protected]"
)
preferences {
section("When the door opens...") {
input "contact1", "capability.contactSensor", title: "Where?"
}
section("Text me at...") {
input "phone1", "phone", title: "Phone number?"
}
}
def installed()
{
subscribe(contact1, "contact.open", contactOpenHandler)
}
def updated()
{
unsubscribe()
subscribe(contact1, "contact.open", contactOpenHandler)
}
def contactOpenHandler(evt) {
log.trace "$evt.value: $evt, $settings"
log.debug "$contact1 was opened, texting $phone1"
sendSms(phone1, "Your ${contact1.label ?: contact1.name} was opened")
}

This program sets up a virtual contact (emulating the SmartSense Multi Sensor) that can
be toggled using the IDE. Once this contact is toggled to the open state, the code in contactO
penHandler(evt) is invoked, which in turn invokes the sendSms service to send a text message.
Take a look at Figure 4-7 again. Notice that the SmartThings service uses a short code
(like a phone number, but specific to text messages) of 512-69. If anyone in the world (even
those who don’t own a single SmartThings product) were to sign up for a free SmartThings


CHAPTER 4: BLURRED LINES—WHEN THE PHYSICAL SPACE MEETS THE VIRTUAL

(^102) SPACE

Free download pdf