SlideShare a Scribd company logo
Programming Your SmartThings 
Janet Huang 
janetyc@gmail.com 
2014.10.22 @ NTU CSIE
How to Program SmartThings
Outline 
• Introduction 
• Conceptual Architecture 
• SmartThings Architecture 
• How to Program SmartThings 
• Build a SmartApp 
• Build a Device Type
Important Concepts 
Image 
Capture 
Lock 
Contact 
Sensor 
Switch Music Player 
Temperature 
Measurement
Conceptual Architecture
SmartThings Architecture
SmartApps 
SmartDevices 
SmartThings Shield 
Customized Smart Device 
Arduino-compatible board 
(Uno, Mega, Duemilanove, and Leonardo) 
+ 
Sensor, Actuator 
= 
1 
2 
3 ZigBee or ZigWave Device
SmartApp 
Event Handler SmartApps 
Subscribe events and call a handler 
method 
Solution Module SmartApps 
Built-in apps in dashboard 
Service Manager SmartApps 
Be used to connect to your external 
devices 
Device Type 
Hub Connected Devices 
ZigBee Home Automation Devices 
Z-Wave Devices 
Cloud Connected Devices 
Authenticate via a standard OAuth2 flow 
Communicate via HTTP-based APIs 
LAN-Connected Devices 
Communicate via REST or with SOAP 
requests using UPnP (Universal Plug 
and Play)
Device Type Handler
SmartApp Execution 
1. Event Subscription 
attribute changes -> creates an event (triggers 
a subscription, calls a handler method) 
2. Scheduled Events 
call a method at a particular time, e.g. runIn() 
3. Endpoint Triggers 
create an endpoint accessible over the web that calls a 
method within your SmartApp
Capabilities 
device state action 
https://graph.api.smartthings.com/ide/doc/capabilities
Your First SmartApp
SmartApp Empty Template 
define input 
install setting 
update setting
https://graph.api.smartthings.com
Create an Empty SmartApp
SmartThings IDE
Choose SmartApp Examples
How to Program SmartThings
Example 1a: Lights Off, When Closed (Built-in example) 
app setting 
define input 
subscribe event 
define action
Example 1b: Lights On/Off, When Opened/Closed 
https://gist.github.com/janetyc/22c0ecf586f1550669b5
check the state of the door 
https://gist.github.com/janetyc/22c0ecf586f1550669b5
1 
Select location 
2 
Select testing devices 
4 Testing on real devices 
3 Testing on simulator
Your First Device Type
Create an Empty SmartDevice
profile 
select capabilities
Device Type Empty Template 
define capability, command 
define UI 
parse events 
commands
Tile Definitions 
standardTile() 
valueTile() 
controlTile() 
Tile Layouts 
valueTile("temperature", 
"device.temperature", 
width: 
2, 
height: 
2) 
main 
"temperature" 
details(["temperature", 
“mode", 
…])
https://gist.github.com/janetyc/34c1642f8eaa3e4299da 
metadata 
{ 
definition 
(name: 
"On/Off 
Shield 
(Janet)", 
namespace: 
"janetyc", 
author: 
"Janet 
Huang") 
{ 
capability 
"Switch" 
capability 
"Sensor" 
command 
"hello" 
} 
simulator 
{ 
// 
TODO: 
define 
status 
and 
reply 
messages 
here 
status 
"on": 
"catchall: 
0104 
0000 
01 
01 
0040 
00 
0A21 
00 
00 
0000 
0A 
00 
0A6F6E" 
status 
"off": 
"catchall: 
0104 
0000 
01 
01 
0040 
00 
0A21 
00 
00 
0000 
0A 
00 
0A6F6666" 
// 
reply 
messages 
reply 
"raw 
0x0 
{ 
00 
00 
0a 
0a 
6f 
6e 
}": 
"catchall: 
0104 
0000 
01 
01 
0040 
00 
0A21 
00 
00 
0000 
0A 
00 
0A6F6E" 
reply 
"raw 
0x0 
{ 
00 
00 
0a 
0a 
6f 
66 
66 
}": 
"catchall: 
0104 
0000 
01 
01 
0040 
00 
0A21 
00 
00 
0000 
0A 
00 
0A6F6666" 
} 
tiles 
{ 
// 
TODO: 
define 
your 
main 
and 
details 
tiles 
here 
standardTile("switch", 
"device.switch", 
width: 
2, 
height: 
2, 
canChangeIcon: 
true, 
canChangeBackground: 
true) 
{ 
state 
"on", 
label: 
'${name}', 
action: 
"switch.off", 
icon: 
"st.shields.shields.arduino", 
backgroundColor: 
"#79b821" 
state 
"off", 
label: 
'${name}', 
action: 
"switch.on", 
icon: 
"st.shields.shields.arduino", 
backgroundColor: 
"#ffffff" 
} 
standardTile("greeting", 
"device.greeting", 
width: 
1, 
height: 
1, 
canChangeIcon: 
true, 
canChangeBackground: 
true) 
{ 
state 
"greeting", 
label: 
'hello', 
action: 
"hello", 
icon: 
"st.switches.switch.off", 
backgroundColor: 
"#ccccff" 
} 
valueTile("message", 
"device.message", 
inactiveLabel: 
false) 
{ 
state 
"message", 
label:'${currentValue}', 
unit:"" 
} 
valueTile("sensorValue", 
"device.sensorValue", 
){ 
state 
"sensorValue", 
label:'${currentValue}', 
inactiveLabel: 
false, 
backgroundColors:[ 
[value: 
31, 
color: 
"#153591"], 
[value: 
44, 
color: 
"#1e9cbb"], 
[value: 
59, 
color: 
"#90d2a7"], 
[value: 
74, 
color: 
"#44b621"], 
[value: 
84, 
color: 
"#f1d801"], 
[value: 
120, 
color: 
"#d04e00"], 
[value: 
195, 
color: 
"#bc2323"] 
] 
} 
main 
"switch" 
details(["switch","greeting","message","sensorValue"]) 
} 
}
// 
parse 
events 
into 
attributes 
def 
parse(String 
description) 
{ 
log.debug 
"raw: 
${description}” 
! 
def 
value 
= 
zigbee.parse(description)?.text 
def 
linkText 
= 
getLinkText(device) 
def 
descriptionText 
= 
getDescriptionText(description, 
linkText, 
value) 
def 
handlerName 
= 
value 
def 
isStateChange 
= 
value 
!= 
"ping" 
def 
displayed 
= 
value 
&& 
isStateChange 
def 
name 
= 
"null" 
if 
(value?.startsWith("lightValue: 
")) 
{ 
value 
= 
value 
-­‐ 
"lightValue: 
" 
name 
= 
"sensorValue" 
value 
= 
Integer.parseInt(value) 
}else 
if 
(value?.startsWith("irValue: 
")) 
{ 
value 
= 
value 
-­‐ 
"irValue: 
" 
name 
= 
"irValue" 
value 
= 
Integer.parseInt(value) 
}else 
{ 
name 
= 
value 
in 
["on","off"] 
? 
"switch" 
: 
(value 
&& 
value 
!= 
"ping" 
? 
"message" 
: 
"null") 
value 
= 
value 
} 
def 
result 
= 
[ 
value: 
value, 
name: 
name, 
handlerName: 
handlerName, 
linkText: 
linkText, 
descriptionText: 
descriptionText, 
isStateChange: 
isStateChange, 
displayed: 
displayed 
] 
result 
} 
debug log 
parse zigbee message 
attribute name 
https://gist.github.com/janetyc/34c1642f8eaa3e4299da
// 
handle 
commands 
def 
on() 
{ 
log.debug 
"Executing 
'on'" 
zigbee.smartShield(text: 
"on").format() 
//send 
'on' 
to 
device 
} 
def 
off() 
{ 
log.debug 
"Executing 
'off'" 
zigbee.smartShield(text: 
"off").format() 
//send 
'off' 
to 
device 
} 
//customized 
commands 
def 
hello() 
{ 
log.debug 
"Executing 
'hello'" 
zigbee.smartShield(text: 
"hello").format() 
//send 
'hello' 
to 
device 
} 
https://gist.github.com/janetyc/34c1642f8eaa3e4299da
It’s Your Turn!! 
Build Your SmartApp & SmartDevice

More Related Content

PPTX
Dan Lieberman of SmartThings - Open House: How Open Platforms are Making Our ...
PDF
How to hack electronics
PDF
TestowanieIoT2016
PPTX
Smart things
PDF
Web-based Smart Things Ecosystems
PPTX
Smart things
PPTX
Présentation smartthing v4
PDF
Security analysis of emerging smart home applications 11.2016
Dan Lieberman of SmartThings - Open House: How Open Platforms are Making Our ...
How to hack electronics
TestowanieIoT2016
Smart things
Web-based Smart Things Ecosystems
Smart things
Présentation smartthing v4
Security analysis of emerging smart home applications 11.2016

Viewers also liked (20)

PPTX
Smartthings
PDF
Understanding Samsung SmartThings from Patents
PPT
Internet of Things and its applications
PPTX
Itsm group15 project
PPTX
PPTX
Samsung ARTIK Cloud and Genuino MKR100
PPTX
PCCW Teleservics Overview
PDF
Modern vs. Traditional SIEM
PPTX
SIEM 101: Get a Clue About IT Security Analysis
PDF
SIEM evolution
PPTX
Leap motion
PDF
Track 3 session 1 - st dev con 2016 -ieee- iot standards adn open source
PPTX
Five Best and Five Worst Practices for SIEM by Dr. Anton Chuvakin
PPTX
Golden Mean in Design
PDF
The Golden Age of Wearables:
 Personal Networks, Smart Things & Intimate Know...
PPTX
IoT Platform Meetup - HP Enterprise
PPTX
IoT Platform Meetup - IBM
PDF
NISTs Cybersecurity Framework -- Comparison with Best Practice
PDF
Samsung Indonesia: Tizen Platform Overview and IoT
Smartthings
Understanding Samsung SmartThings from Patents
Internet of Things and its applications
Itsm group15 project
Samsung ARTIK Cloud and Genuino MKR100
PCCW Teleservics Overview
Modern vs. Traditional SIEM
SIEM 101: Get a Clue About IT Security Analysis
SIEM evolution
Leap motion
Track 3 session 1 - st dev con 2016 -ieee- iot standards adn open source
Five Best and Five Worst Practices for SIEM by Dr. Anton Chuvakin
Golden Mean in Design
The Golden Age of Wearables:
 Personal Networks, Smart Things & Intimate Know...
IoT Platform Meetup - HP Enterprise
IoT Platform Meetup - IBM
NISTs Cybersecurity Framework -- Comparison with Best Practice
Samsung Indonesia: Tizen Platform Overview and IoT
Ad

Similar to How to Program SmartThings (20)

PPTX
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...
PDF
Control all the Things with Node-JS
PPTX
[University] Capstone Design Project 2 (SAIOT)
PPTX
Introduction to Things board (An Open Source IoT Cloud Platform)
PPT
Phidget sensors
PDF
Home Automation System using ZigBee and PandaBoard as a Gateway (HAS-ZP)
PPT
Smarthome Presentation
PDF
Hardware hackers - hacking appliances with netduino + xamarin
PPTX
Introduction to Node MCU
PPT
Pluggable Realworld Interfaces
PPTX
SenseHome : IoT based home automation system
PDF
The Smart Device Specification for Remote Labs
PDF
Energy Meters using Internet of Things Platform
PPTX
Bare metal Javascript & GPIO programming in Linux
PPTX
Connecting Stuff to Azure (IoT)
PPTX
Bosch hackathon tech
PDF
Training thethings.iO
PPTX
IoT Application Development
PDF
IoT Toolkit and the Smart Object API Tutorial Introduction
PDF
IoT Toolkit and Smart Object API Tutorial Introduction
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...
Control all the Things with Node-JS
[University] Capstone Design Project 2 (SAIOT)
Introduction to Things board (An Open Source IoT Cloud Platform)
Phidget sensors
Home Automation System using ZigBee and PandaBoard as a Gateway (HAS-ZP)
Smarthome Presentation
Hardware hackers - hacking appliances with netduino + xamarin
Introduction to Node MCU
Pluggable Realworld Interfaces
SenseHome : IoT based home automation system
The Smart Device Specification for Remote Labs
Energy Meters using Internet of Things Platform
Bare metal Javascript & GPIO programming in Linux
Connecting Stuff to Azure (IoT)
Bosch hackathon tech
Training thethings.iO
IoT Application Development
IoT Toolkit and the Smart Object API Tutorial Introduction
IoT Toolkit and Smart Object API Tutorial Introduction
Ad

More from Janet Huang (13)

PDF
Transferring Sensing to a Mixed Virtual and Physical Experience
PDF
Collecting a Image Label from Crowds Using Amazon Mechanical Turk
PDF
Art in the Crowd
PDF
Designing physical and digital experience in social web
PDF
Of class3
PDF
Of class2
PDF
Of class1
PDF
Iphone course 3
PDF
Iphone course 2
PDF
Iphone course 1
PDF
The power of example
PDF
Responsive web design
PDF
Openframworks x Mobile
Transferring Sensing to a Mixed Virtual and Physical Experience
Collecting a Image Label from Crowds Using Amazon Mechanical Turk
Art in the Crowd
Designing physical and digital experience in social web
Of class3
Of class2
Of class1
Iphone course 3
Iphone course 2
Iphone course 1
The power of example
Responsive web design
Openframworks x Mobile

Recently uploaded (20)

PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Machine learning based COVID-19 study performance prediction
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Cloud computing and distributed systems.
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Big Data Technologies - Introduction.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The Rise and Fall of 3GPP – Time for a Sabbatical?
Programs and apps: productivity, graphics, security and other tools
Encapsulation_ Review paper, used for researhc scholars
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
sap open course for s4hana steps from ECC to s4
Machine learning based COVID-19 study performance prediction
Mobile App Security Testing_ A Comprehensive Guide.pdf
Cloud computing and distributed systems.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Big Data Technologies - Introduction.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Review of recent advances in non-invasive hemoglobin estimation
Building Integrated photovoltaic BIPV_UPV.pdf
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf

How to Program SmartThings

  • 1. Programming Your SmartThings Janet Huang janetyc@gmail.com 2014.10.22 @ NTU CSIE
  • 3. Outline • Introduction • Conceptual Architecture • SmartThings Architecture • How to Program SmartThings • Build a SmartApp • Build a Device Type
  • 4. Important Concepts Image Capture Lock Contact Sensor Switch Music Player Temperature Measurement
  • 7. SmartApps SmartDevices SmartThings Shield Customized Smart Device Arduino-compatible board (Uno, Mega, Duemilanove, and Leonardo) + Sensor, Actuator = 1 2 3 ZigBee or ZigWave Device
  • 8. SmartApp Event Handler SmartApps Subscribe events and call a handler method Solution Module SmartApps Built-in apps in dashboard Service Manager SmartApps Be used to connect to your external devices Device Type Hub Connected Devices ZigBee Home Automation Devices Z-Wave Devices Cloud Connected Devices Authenticate via a standard OAuth2 flow Communicate via HTTP-based APIs LAN-Connected Devices Communicate via REST or with SOAP requests using UPnP (Universal Plug and Play)
  • 10. SmartApp Execution 1. Event Subscription attribute changes -> creates an event (triggers a subscription, calls a handler method) 2. Scheduled Events call a method at a particular time, e.g. runIn() 3. Endpoint Triggers create an endpoint accessible over the web that calls a method within your SmartApp
  • 11. Capabilities device state action https://graph.api.smartthings.com/ide/doc/capabilities
  • 13. SmartApp Empty Template define input install setting update setting
  • 15. Create an Empty SmartApp
  • 19. Example 1a: Lights Off, When Closed (Built-in example) app setting define input subscribe event define action
  • 20. Example 1b: Lights On/Off, When Opened/Closed https://gist.github.com/janetyc/22c0ecf586f1550669b5
  • 21. check the state of the door https://gist.github.com/janetyc/22c0ecf586f1550669b5
  • 22. 1 Select location 2 Select testing devices 4 Testing on real devices 3 Testing on simulator
  • 24. Create an Empty SmartDevice
  • 26. Device Type Empty Template define capability, command define UI parse events commands
  • 27. Tile Definitions standardTile() valueTile() controlTile() Tile Layouts valueTile("temperature", "device.temperature", width: 2, height: 2) main "temperature" details(["temperature", “mode", …])
  • 28. https://gist.github.com/janetyc/34c1642f8eaa3e4299da metadata { definition (name: "On/Off Shield (Janet)", namespace: "janetyc", author: "Janet Huang") { capability "Switch" capability "Sensor" command "hello" } simulator { // TODO: define status and reply messages here status "on": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E" status "off": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666" // reply messages reply "raw 0x0 { 00 00 0a 0a 6f 6e }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E" reply "raw 0x0 { 00 00 0a 0a 6f 66 66 }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666" } tiles { // TODO: define your main and details tiles here standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true, canChangeBackground: true) { state "on", label: '${name}', action: "switch.off", icon: "st.shields.shields.arduino", backgroundColor: "#79b821" state "off", label: '${name}', action: "switch.on", icon: "st.shields.shields.arduino", backgroundColor: "#ffffff" } standardTile("greeting", "device.greeting", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) { state "greeting", label: 'hello', action: "hello", icon: "st.switches.switch.off", backgroundColor: "#ccccff" } valueTile("message", "device.message", inactiveLabel: false) { state "message", label:'${currentValue}', unit:"" } valueTile("sensorValue", "device.sensorValue", ){ state "sensorValue", label:'${currentValue}', inactiveLabel: false, backgroundColors:[ [value: 31, color: "#153591"], [value: 44, color: "#1e9cbb"], [value: 59, color: "#90d2a7"], [value: 74, color: "#44b621"], [value: 84, color: "#f1d801"], [value: 120, color: "#d04e00"], [value: 195, color: "#bc2323"] ] } main "switch" details(["switch","greeting","message","sensorValue"]) } }
  • 29. // parse events into attributes def parse(String description) { log.debug "raw: ${description}” ! def value = zigbee.parse(description)?.text def linkText = getLinkText(device) def descriptionText = getDescriptionText(description, linkText, value) def handlerName = value def isStateChange = value != "ping" def displayed = value && isStateChange def name = "null" if (value?.startsWith("lightValue: ")) { value = value -­‐ "lightValue: " name = "sensorValue" value = Integer.parseInt(value) }else if (value?.startsWith("irValue: ")) { value = value -­‐ "irValue: " name = "irValue" value = Integer.parseInt(value) }else { name = value in ["on","off"] ? "switch" : (value && value != "ping" ? "message" : "null") value = value } def result = [ value: value, name: name, handlerName: handlerName, linkText: linkText, descriptionText: descriptionText, isStateChange: isStateChange, displayed: displayed ] result } debug log parse zigbee message attribute name https://gist.github.com/janetyc/34c1642f8eaa3e4299da
  • 30. // handle commands def on() { log.debug "Executing 'on'" zigbee.smartShield(text: "on").format() //send 'on' to device } def off() { log.debug "Executing 'off'" zigbee.smartShield(text: "off").format() //send 'off' to device } //customized commands def hello() { log.debug "Executing 'hello'" zigbee.smartShield(text: "hello").format() //send 'hello' to device } https://gist.github.com/janetyc/34c1642f8eaa3e4299da
  • 31. It’s Your Turn!! Build Your SmartApp & SmartDevice