2 * [Workshop Demo] SMS to Hue
4 * Copyright 2015 Andrew Mager
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13 * for the specific language governing permissions and limitations under the License.
17 name: "[Workshop Demo] SMS to Hue",
18 namespace: "com.smartthings.dev",
19 author: "Andrew Mager",
20 description: "Change the color of Hue bulbs from an SMS.",
22 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
23 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
24 iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
29 section("Control these hue bulbs...") {
30 input "hues", "capability.colorControl", title: "Which Hue Bulbs?", required:false, multiple:true
35 // This block defines an endpoint, and which functions will fire depending on which type
36 // of HTTP request you send
38 // The path is appended to the endpoint to make request
53 This function receives a JSON payload and parses out the color from a tweet.
54 For example, someone tweets, "@SmartThingsDev #IoTWorld2015 color=blue". Then it sends the
55 correct color as a string to setHueColor().
59 "request.JSON?" checks to make sure that the object exists. And ".text" is the
60 key for the value that we're looking for. It's the body of the tweet.
62 def color = (request.JSON?.value).toLowerCase()
65 // Finds the text "color=[colorname]" and parses out the color name
69 log.trace "Something went wrong."
74 // This function takes a String of text and associates it with an Integer value for the color.
75 private setHueColor(color) {
77 // Initaliaze values for hue, saturation, and level
110 // Set the new value of hue, saturation, and level
111 def newValue = [hue: hueColor, saturation: saturation, level: level]
113 // Update each Hue bulb with the new values
114 hues*.setColor(newValue)