Skip to content

Commit

Permalink
Merge pull request #37 from konnected-io/konnected-switch
Browse files Browse the repository at this point in the history
Konnected switch
  • Loading branch information
heythisisnate authored Sep 4, 2017
2 parents 66e558f + a8ecf87 commit 24e51f5
Show file tree
Hide file tree
Showing 16 changed files with 471 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Konnected Beep/Blink
*
* Copyright 2017 konnected.io
*
* 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: "Konnected Beep/Blink", namespace: "konnected-io", author: "konnected.io") {
capability "Switch"
capability "Actuator"
capability "Momentary"
capability "Tone"
}

preferences {
input name: "invertTrigger", type: "bool", title: "Low Level Trigger",
description: "Select if the attached relay uses a low-level trigger. Default is high-level trigger"
input name: "beepDuration", type: "number", title: "Pulse (ms)",
description: "Each beep or blink duration"
input name: "beepPause", type: "number", title: "Pause (ms)",
description: "Pause between beeps/blinks in milliseconds"
input name: "beepRepeat", type: "number", title: "Repeat",
description: "Times to repeat the pulse"
}

tiles {
multiAttributeTile(name:"main", type: "generic", width: 6, height: 4, canChangeIcon: true) {
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
attributeState "off", label: 'Beep', action: "tone.beep", backgroundColor: "#ffffff", nextState: "pushed"
attributeState "on", label: 'Beep', action: "tone.beep", backgroundColor: "#00a0dc"
attributeState "pushed", label:'pushed', action: "tone.beep", backgroundColor:"#00a0dc", nextState: "off"
}
}
main "main"
details "main"
}
}

def updated() {
parent.updateSettingsOnChildDevice(device.deviceNetworkId)
}

def updatePinState(Integer state) {
sendEvent(name: "switch", value: "on", isStateChange: true, display: false)
sendEvent(name: "switch", value: "off", isStateChange: true, display: false)
}

def off() {
beep()
}

def on() {
beep()
}

def push() {
beep()
}

def beep() {
def val = invertTrigger ? 0 : 1
parent.deviceUpdateDeviceState(device.deviceNetworkId, val, [
momentary : beepDuration ?: 250,
pause : beepPause ?: 150,
times : beepRepeat ?: 3
])
}

def triggerLevel() {
return invertTrigger ? 0 : 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Konnected Switch
*
* Copyright 2017 konnected.io
*
* 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: "Konnected Momentary Switch", namespace: "konnected-io", author: "konnected.io") {
capability "Switch"
capability "Actuator"
capability "Momentary"
}

preferences {
input name: "invertTrigger", type: "bool", title: "Low Level Trigger",
description: "Select if the attached relay uses a low-level trigger. Default is high-level trigger"
input name: "momentaryDelay", type: "number", title: "Momentary Delay",
description: "Off delay (in milliseconds)"
}

tiles {
multiAttributeTile(name:"main", type: "generic", width: 6, height: 4, canChangeIcon: true) {
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
attributeState "off", label: 'Push', action: "momentary.push", backgroundColor: "#ffffff", nextState: "pushed"
attributeState "on", label: 'Push', action: "momentary.push", backgroundColor: "#00a0dc"
attributeState "pushed", label:'pushed', action: "momentary.push", backgroundColor:"#00a0dc", nextState: "off"
}
}
main "main"
details "main"
}
}

def updated() {
parent.updateSettingsOnChildDevice(device.deviceNetworkId)
}

def updatePinState(Integer state) {
sendEvent(name: "switch", value: "on", isStateChange: true, display: false)
sendEvent(name: "switch", value: "off", isStateChange: true, display: false)
}

def off() {
push()
}

def on() {
push()
}

def push() {
def val = invertTrigger ? 0 : 1
parent.deviceUpdateDeviceState(device.deviceNetworkId, val, [
momentary : momentaryDelay ?: 500
])
}

def triggerLevel() {
return invertTrigger ? 0 : 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,59 @@ metadata {
capability "Switch"
capability "Actuator"
}

preferences {
input name: "invertTrigger", type: "bool", title: "Low Level Trigger",
description: "Select if the attached relay uses a low-level trigger. Default is high-level trigger"
}

tiles {
multiAttributeTile(name:"main", type: "generic", width: 6, height: 4, canChangeIcon: true) {
tileAttribute ("device.alarm", key: "PRIMARY_CONTROL") {
attributeState ("off", label: "Off", icon:"st.security.alarm.clear", action:"alarm.both", backgroundColor:"#ffffff")
attributeState ("both", label: "Alarm!", icon:"st.security.alarm.alarm", action:"alarm.off", backgroundColor:"#e86d13")
attributeState ("off", label: "Off", icon:"st.security.alarm.clear", action:"alarm.both", backgroundColor:"#ffffff", nextState: "turningOn")
attributeState ("both", label: "Alarm!", icon:"st.security.alarm.alarm", action:"alarm.off", backgroundColor:"#e86d13", nextState: "turningOff")
attributeState ("turningOn", label:'Activating', icon:"st.security.alarm.alarm", action:"alarm.off", backgroundColor:"#e86d13", nextState: "turningOff")
attributeState ("turningOff", label:'Turning off', icon:"st.security.alarm.clear", action:"alarm.on", backgroundColor:"#ffffff", nextState: "turningOn")
}
}
main "main"
details "main"
}
}

def off() {
sendEvent([name: "switch", value: "off", displayed: false])
sendEvent([name: "alarm", value: "off"])
parent.deviceUpdateDeviceState(device.deviceNetworkId, 0)
def updated() {
parent.updateSettingsOnChildDevice(device.deviceNetworkId)
}

def updatePinState(Integer state) {
def val
if (state == 0) {
val = invertTrigger ? "on" : "off"
} else {
val = invertTrigger ? "off" : "on"
}
log.debug "$device is $val"
sendEvent(name: "switch", value: val, displayed: false)
if (val == "on") { val = "both" }
sendEvent(name: "alarm", value: val)
}

def off() {
def val = invertTrigger ? 1 : 0
parent.deviceUpdateDeviceState(device.deviceNetworkId, val)
}

def on() {
sendEvent([name: "switch", value: "on", displayed: false])
sendEvent([name: "alarm", value: "both"])
parent.deviceUpdateDeviceState(device.deviceNetworkId, 1)
def val = invertTrigger ? 0 : 1
parent.deviceUpdateDeviceState(device.deviceNetworkId, val)
}

def both() { on() }

def strobe() { on() }

def siren() { on() }
def siren() { on() }

def triggerLevel() {
return invertTrigger ? 0 : 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Konnected Switch
*
* Copyright 2017 konnected.io
*
* 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: "Konnected Switch", namespace: "konnected-io", author: "konnected.io") {
capability "Switch"
capability "Actuator"
}

preferences {
input name: "invertTrigger", type: "bool", title: "Low Level Trigger",
description: "Select if the attached relay uses a low-level trigger. Default is high-level trigger"
}

tiles {
multiAttributeTile(name:"main", type: "generic", width: 6, height: 4, canChangeIcon: true) {
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
attributeState ("off", label: '${name}', icon:"st.switches.switch.off", action:"switch.on", backgroundColor:"#ffffff", nextState: "turningOn")
attributeState ("on", label: '${name}', icon:"st.switches.switch.on", action:"switch.off", backgroundColor:"#00A0DC", nextState: "turningOff")
attributeState ("turningOn", label:'Turning on', icon:"st.switches.switch.on", action:"switch.off", backgroundColor:"#00a0dc", nextState: "turningOff")
attributeState ("turningOff", label:'Turning off', icon:"st.switches.switch.off", action:"switch.on", backgroundColor:"#ffffff", nextState: "turningOn")
}
}
main "main"
details "main"
}
}

def updated() {
parent.updateSettingsOnChildDevice(device.deviceNetworkId)
}

def updatePinState(Integer state) {
def val
if (state == 0) {
val = invertTrigger ? "on" : "off"
} else {
val = invertTrigger ? "off" : "on"
}
log.debug "$device is $val"
sendEvent(name: "switch", value: val)
}

def off() {
def val = invertTrigger ? 1 : 0
log.debug "Turning off $device.label (state = $val)"
parent.deviceUpdateDeviceState(device.deviceNetworkId, val)
}

def on() {
def val = invertTrigger ? 0 : 1
log.debug "Turning on $device.label (state = $val)"
parent.deviceUpdateDeviceState(device.deviceNetworkId, val)
}

def triggerLevel() {
return invertTrigger ? 0 : 1
}
Loading

0 comments on commit 24e51f5

Please sign in to comment.