Skip to content

Commit

Permalink
added some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettSheleski committed Dec 3, 2017
1 parent 3ce9919 commit fec415c
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
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 devicetypes/BrettSheleski/dummy-switch.src/dummy-switch.groovy
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 smartapps/BrettSheleski/composite-switch.src/composite-switch.groovy
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();
}
}

0 comments on commit fec415c

Please sign in to comment.