4 * Copyright 2015 Andrew Mager & Kris Schaller
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.
18 namespace: "com.smartthings.dev",
19 author: "Andrew Mager & Kris Schaller",
20 description: "Update a Hue bulb's color based on a tweet.",
21 category: "Fun & Social",
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 which functions will fire when you hit certain endpoints. */
46 log.debug "Installed with settings: ${settings}"
52 log.debug "Updated with settings: ${settings}"
63 * Body: { color=[yourcolor] } to change color
66 * "value" : " #smartthings is so color=blue"
71 def tweetText = request.JSON.text
72 log.info "POST: $tweetText"
75 def tweetColor = (tweetText =~ /color=(\w+)/)[0][1].toLowerCase()
76 log.debug (tweetText =~ /color=(\w+)/)
77 setHueColor(tweetColor)
80 log.trace "POST: Check Body (e.g: @RT: #smartthings color=red)"
84 private setHueColor(color) {
120 state.previous[it.id] = [
121 "switch": it.currentValue("switch"),
122 "level" : it.currentValue("level"),
123 "hue": it.currentValue("hue"),
124 "saturation": it.currentValue("saturation")
128 log.debug "current values = $state.previous"
130 def newValue = [hue: hueColor, saturation: saturation, level: 100]
131 log.debug "new value = $newValue"
133 hues*.setColor(newValue)