2 * Copyright 2015 SmartThings
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
10 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
11 * for the specific language governing permissions and limitations under the License.
13 * SmartClockChatSender
15 * Author: Steve Vlaminck
21 name: "SmartBlock Chat Sender",
22 namespace: "vlaminck/Minecraft",
23 author: "SmartThings",
24 description: "Send chat messages into Minecraft via the SmartBlock mod",
25 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
26 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png"
30 page(name: "chatPage", title: "Send Notifications Into Minecraft", install: true, uninstall: true) {
32 input(name: "chatsEnabled", type: "bool", title: "Enable This Notification?", defaultValue: "true")
33 input(name: "modes", type: "mode", title: "Notify SmartBlock users when the mode changes to:", description: "(optional)", multiple: true, required: false)
34 input(name: "username", type: "string", title: "Only send to this username", required: false, description: "(optional)")
35 input(name: "customMessage", type: "string", title: "Custom message?", required: false, description: "(optional)")
37 section(hidden: true, hideable: true, title: "Other Options") {
38 label(title: "Label this Notification", required: false)
44 log.debug "Installed with settings: ${settings}"
50 log.debug "Updated with settings: ${settings}"
57 subscribe(location, modeChangeHandler)
60 def modeChangeHandler(evt) {
61 def newMode = evt.value
62 log.debug "evt: ${newMode}"
63 if (modes && modes.contains(newMode))
65 def message = customMessage ?: "SmartThings mode has changed to: \"${newMode}\""
66 chatMessageToMC(message)
70 def chatMessageToMC(message) {
72 def parent = app.getParent()
74 def url = "${parent.getServerURL()}/chat?message=${message.encodeAsURL()}"
78 url += "&username=${username.encodeAsURL()}"
80 log.debug "POST to ${url}"
82 httpPost(url, "foo=bar") { response ->
83 content = response.data
84 log.debug "response: ${content}"