Created
August 20, 2017 04:17
-
-
Save robstenzinger/bc9dffd0c834f4bc43c48a6e869d92d4 to your computer and use it in GitHub Desktop.
A Smartthings Device Handler groovy script. Based on examples at: https://github.com/jrhbcn/smartthings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright 2015 SmartThings | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
* in compliance with the License. You may obtain a copy of the License at: | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed | |
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License | |
* for the specific language governing permissions and limitations under the License. | |
* | |
*/ | |
metadata { | |
// | |
definition (name: "Simulated Garagedoor Controller V3", namespace: "YOUR.NAME.SPACE", author: "YOUR NAME") { | |
capability "Actuator" | |
capability "Switch" | |
capability "Sensor" | |
command "door1" | |
command "door2" | |
} | |
// when setting up your device via the smartthings app, these preference settings are available | |
preferences { | |
// the LAN IP address and port for the server for example: 192.168.0.100:8080 | |
input("host", "string", title:"Host", description: "The IP address and port of the Raspberry Pi.", required: true, displayDuringSetup: true) | |
} | |
// these are the tiles displayed in the smartthings app when you setup this device | |
tiles(scale:2) { | |
multiAttributeTile(name:"controllerstatus", type: "generic", width: 6, height: 4) { | |
tileAttribute ("device.status", key: "PRIMARY_CONTROL") { | |
attributeState("online", label:'${name}', icon:"st.Home.home9", backgroundColor:"#79b821") | |
} | |
} | |
standardTile("door1", "device.button", width: 2, height: 2) { | |
state "default", label: "Door 1", backgroundColor: "#ffffff", action: "door1", icon:"" | |
} | |
standardTile("door2", "device.button", width: 2, height: 2) { | |
state "default", label: "Door 2", backgroundColor: "#ffffff", action: "door2", icon:"" | |
} | |
details(["controllerstatus","door1","door2"]) | |
} | |
} | |
// | |
def getHostAddress() { | |
return "${host}" | |
} | |
// | |
def door1() { | |
def cmds = [] | |
cmds << http_command("/door/door1/activate") | |
log.debug cmds | |
sendEvent(name: "door1", value: "pushed", data: [buttonNumber: "1"], descriptionText: "$device.displayName door1 button was pushed", isStateChange: true) | |
return cmds | |
} | |
// | |
def door2() { | |
def cmds = [] | |
cmds << http_command("/door/door2/activate") | |
log.debug cmds | |
sendEvent(name: "door2", value: "pushed", data: [buttonNumber: "2"], descriptionText: "$device.displayName door2 button was pushed", isStateChange: true) | |
return cmds | |
} | |
// | |
private http_command(uri) { | |
log.debug("Executing hubaction ${uri} on " + getHostAddress()) | |
def hubAction = new physicalgraph.device.HubAction( | |
method: "GET", | |
path: uri, | |
headers: [HOST:getHostAddress()]) | |
return hubAction | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment