forked from SmartThingsCommunity/SmartThingsPublic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ce9919
commit fec415c
Showing
3 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
devicetypes/BrettSheleski/composite-switch.src/composite-switch.groovy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
metadata { | ||
definition(name: "Composite Switch", namespace: "BrettSheleski", author: "Brett Sheleski") { | ||
capability "Switch" | ||
} | ||
|
||
tiles { | ||
multiAttributeTile(name:"switch", type: "generic", width: 6, height: 4, canChangeIcon: true){ | ||
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") { | ||
attributeState "on", label: '${name}', action: "off", icon: "st.switches.switch.on", backgroundColor: "#79b821" | ||
attributeState "off", label: '${name}', action: "on", icon: "st.switches.switch.off", backgroundColor: "#ffffff" | ||
} | ||
} | ||
|
||
main "switch" | ||
details(["switch"]) | ||
} | ||
|
||
preferences { | ||
input "onButton", "capability.momentary", title: "On Button", description: "The button to press when going to the ON state", displayDuringSetup: true | ||
input "offButton", "capability.momentary", title: "Off Button", description: "The button to press when going to the OFF state", displayDuringSetup: true | ||
} | ||
} | ||
|
||
def on(){ | ||
log.debug "ON" | ||
|
||
onButton.push() | ||
sendEvent(name: "switch", value: "on") | ||
} | ||
|
||
def off(){ | ||
log.debug "OFF" | ||
|
||
offButton.push() | ||
sendEvent(name: "switch", value: "off") | ||
} |
29 changes: 29 additions & 0 deletions
29
devicetypes/BrettSheleski/dummy-switch.src/dummy-switch.groovy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
metadata { | ||
definition(name: "Dummy Switch", namespace: "BrettSheleski", author: "Brett Sheleski") { | ||
capability "Switch" | ||
} | ||
|
||
tiles { | ||
multiAttributeTile(name:"switch", type: "generic", width: 6, height: 4, canChangeIcon: true){ | ||
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") { | ||
attributeState "on", label: '${name}', action: "off", icon: "st.switches.switch.on", backgroundColor: "#79b821" | ||
attributeState "off", label: '${name}', action: "on", icon: "st.switches.switch.off", backgroundColor: "#ffffff" | ||
} | ||
} | ||
|
||
main "switch" | ||
details(["switch"]) | ||
} | ||
} | ||
|
||
def on(){ | ||
log.debug "ON" | ||
|
||
sendEvent(name: "switch", value: "on"); | ||
} | ||
|
||
def off(){ | ||
log.debug "OFF" | ||
|
||
sendEvent(name: "switch", value: "off"); | ||
} |
101 changes: 101 additions & 0 deletions
101
smartapps/BrettSheleski/composite-switch.src/composite-switch.groovy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
definition( | ||
name: "Composite Switch", | ||
namespace: "BrettSheleski", | ||
author: "Brett Sheleski", | ||
description: "Make a switch from two buttons", | ||
category: "SmartThings Labs", | ||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/App-BigButtonsAndSwitches.png", | ||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]" | ||
) | ||
|
||
preferences { | ||
input "onButton", "capability.momentary", title: "On Button", required: true | ||
input "offButton", "capability.momentary", title: "Off Button", required: true | ||
input "theSwitch", "capability.switch", title: "The Switch", required: true | ||
} | ||
|
||
def installed() { | ||
log.debug "Installed with settings: ${settings}" | ||
initialize() | ||
} | ||
|
||
def updated() { | ||
log.debug "Updated with settings: ${settings}" | ||
initialize() | ||
} | ||
|
||
def uninstalled() { | ||
removeChildDevices(getChildDevices()) | ||
} | ||
|
||
def initialize(){ | ||
/* | ||
def namespace = app.namespace | ||
def deviceName = "Dummy Switch" | ||
def theHubId = location.hubs[0].id | ||
def deviceId = "${app.id}-switch" | ||
def theSwitch = getSwitch() | ||
if (theSwitch){ | ||
log.debug "FOUND child device found for ${childDevice.deviceNetworkId}" | ||
} | ||
else{ | ||
log.debug "NOT FOUND child device, creating one..." | ||
def deviceMap = [completedSetup: false] | ||
deviceMap['name'] = app.label + " - Switch"; | ||
deviceMap['label'] = deviceMap['name']; | ||
theSwitch = addChildDevice(namespace, deviceName, deviceId, theHubId, deviceMap) | ||
log.debug "Switch Created" | ||
} | ||
*/ | ||
|
||
subscribe(onButton, "momentary.push", handleOnButtonPush) | ||
subscribe(offButton, "momentary.push", handleOffButtonPush) | ||
subscribe(theSwitch, "switch", handleSwitchEvent) | ||
} | ||
|
||
def getSwitch(){ | ||
/* | ||
def deviceId = "${app.id}-switch" | ||
def theSwitch = getChildDevice(deviceId); | ||
*/ | ||
return theSwitch | ||
} | ||
|
||
def handleOnButtonPush(){ | ||
log.debug "Handle ON BUTTON push" | ||
|
||
//def theSwitch = getSwitch(); | ||
|
||
if (theSwitch){ | ||
//sendEvent(theSwitch, [name : "switch", value: "on"]) | ||
//theSwitch.on(); | ||
} | ||
} | ||
|
||
def handleOffButtonPush(){ | ||
log.debug "Handle OFF BUTTON push" | ||
|
||
//def theSwitch = getSwitch(); | ||
|
||
if (theSwitch){ | ||
//sendEvent(theSwitch, [name : "switch", value: "off"]) | ||
//theSwitch.off(); | ||
} | ||
} | ||
|
||
def handleSwitchEvent(evt){ | ||
log.debug "Handle SWITCH (${evt.value})" | ||
|
||
def isOn = evt.value == "on"; | ||
|
||
if (isOn){ | ||
onButton.push(); | ||
} | ||
else{ | ||
offButton.push(); | ||
} | ||
} |