-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from konnected-io/konnected-switch
Konnected switch
- Loading branch information
Showing
16 changed files
with
471 additions
and
85 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
devicetypes/konnected-io/konnected-beep-blink.src/konnected-beep-blink.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,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 | ||
} |
69 changes: 69 additions & 0 deletions
69
devicetypes/konnected-io/konnected-momentary-switch.src/konnected-momentary-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,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 | ||
} |
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
70 changes: 70 additions & 0 deletions
70
devicetypes/konnected-io/konnected-switch.src/konnected-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,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 | ||
} |
Oops, something went wrong.