diff --git a/devicetypes/BrettSheleski/composite-switch.src/composite-switch.groovy b/devicetypes/BrettSheleski/composite-switch.src/composite-switch.groovy new file mode 100644 index 00000000000..ecc25c2eb07 --- /dev/null +++ b/devicetypes/BrettSheleski/composite-switch.src/composite-switch.groovy @@ -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") +} \ No newline at end of file diff --git a/devicetypes/BrettSheleski/dummy-switch.src/dummy-switch.groovy b/devicetypes/BrettSheleski/dummy-switch.src/dummy-switch.groovy new file mode 100644 index 00000000000..bd441629a92 --- /dev/null +++ b/devicetypes/BrettSheleski/dummy-switch.src/dummy-switch.groovy @@ -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"); +} \ No newline at end of file diff --git a/smartapps/BrettSheleski/composite-switch.src/composite-switch.groovy b/smartapps/BrettSheleski/composite-switch.src/composite-switch.groovy new file mode 100644 index 00000000000..b0b7b41d331 --- /dev/null +++ b/smartapps/BrettSheleski/composite-switch.src/composite-switch.groovy @@ -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/App-BigButtonsAndSwitches@2x.png" +) + +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(); + } +}