Piezo Actions: Quick Beep on contact open/close possible?

I've read through the online docs, and the forums and didn't find anything similarly answered.

Currently, the piezo stays ON until the contact is closed; I'm looking for a way to have it "chirp" 3 times consecutively/quickly on open and on close; similar to most standard alarm systems.

I have only been able to find a way in the SmartThings app to set the piezo sound ON to a minimum of 1 minute (duration WAY to long and no repeat option).

My piezo is connected to the GRD and OUT on the side (not the zone terminals) on the add-on panel.

Thanks in advance!

Did you figure this out yet? Mine beeps, but the pattern is never consistent and sometimes it stays on for like 10 seconds.  Any help would be great.

Using Hubitat. I wanted one beep for open and two quick beeps for close using a single piezo.

I edited the beep driver, assigning the original to the ‘push’ action (tone device) and a new beep2 to ‘on’ action (switch device). Default time settings changed to simulate beeps I wanted. Just edit the driver and save. Here’s a copy of the section of driver code I changed:

def on() {
beep2()
}

def push() {
beep()
}

def beep() {
parent.deviceUpdateDeviceState(device.deviceNetworkId, triggerLevel(), [
momentary : beepDuration ?: 150,
pause : beepPause ?: 150,
times : beepRepeat ?: 1
])
}

def beep2() {
parent.deviceUpdateDeviceState(device.deviceNetworkId, triggerLevel(), [
momentary : beepDuration ?: 150,
pause : beepPause ?: 50,
times : beepRepeat ?:2
])
}

Hi, could you please share a copy/paste of the entire driver code? Thanks so much!

/**

  • 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”, mnmn: “SmartThings”, vid: “generic-switch”) {
capability “Alarm”
capability “Switch”
capability “Actuator”
capability “Momentary”
capability “Tone”
}

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

// settings for momentary beep
input name: "beepDuration", type: "number", title: "Beep Pulse (ms)",
  description: "Each beep or blink duration", range: "10..*"
input name: "beepPause", type: "number", title: "Beep Pause (ms)",
  description: "Pause between beeps/blinks in milliseconds", range: "10..*"
input name: "beepRepeat", type: "number", title: "Beep Repeat",
  description: "Times to repeat the pulse", range: "1..*"

// settings for infinately repeating alarm
input name: "alarmDuration", type: "number", title: "Alarm Pulse (ms)",
  description: "Tone duration in alarm", range: "10..*"
input name: "alarmPause", type: "number", title: "Alarm Pause (ms)",
  description: "Pause between tones in alarm", range: "10..*"

}
}

def updated() {
parent.updateSettingsOnDevice()
}

def updatePinState(Integer state) {
if (state == -1) { // represents an infinate alarm activated
sendEvent(name: “alarm”, value: “siren”)
} else if (state == triggerLevel()) {
sendEvent(name: “switch”, value: “on”, isStateChange: true, display: false)
sendEvent(name: “switch”, value: “off”, isStateChange: true, display: false)
} else {
sendEvent(name: “alarm”, value: “off”)
}
}

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

def on() {
beep2()
}

def push() {
beep()
}

def beep() {
parent.deviceUpdateDeviceState(device.deviceNetworkId, triggerLevel(), [
momentary : beepDuration ?: 150,
pause : beepPause ?: 150,
times : beepRepeat ?: 1
])
}

def beep2() {
parent.deviceUpdateDeviceState(device.deviceNetworkId, triggerLevel(), [
momentary : beepDuration ?: 150,
pause : beepPause ?: 100,
times : beepRepeat ?:2
])
}

def siren() {
parent.deviceUpdateDeviceState(device.deviceNetworkId, triggerLevel(), [
momentary : alarmDuration ?: 55,
pause : alarmPause ?: 45,
times : -1
])
}

def both() {
siren()
}

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

def currentBinaryValue() {
invertTrigger ? 1 : 0
}

Thanks so much; this is also a useful code-learning project as well!

Ciao,
-peter-

Hello again J, I was just trying to swap in your code (exact copy/past of what you posted), unfortunately, I am seeing this error:

unexpected token: Beep @ line 17, column 30.

Any thoughts?

I cut/pasted the code into my hubitat and saw the same error. I looks like the " (quotes) were converted to left and right quotes as it was copied(paste as text). “alarm” vs “alarm”…

/**

  • 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”, mnmn: “SmartThings”, vid: “generic-switch”) {
capability “Alarm”
capability “Switch”
capability “Actuator”
capability “Momentary”
capability “Tone”
}

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

// settings for momentary beep
input name: "beepDuration", type: "number", title: "Beep Pulse (ms)",
  description: "Each beep or blink duration", range: "10..*"
input name: "beepPause", type: "number", title: "Beep Pause (ms)",
  description: "Pause between beeps/blinks in milliseconds", range: "10..*"
input name: "beepRepeat", type: "number", title: "Beep Repeat",
  description: "Times to repeat the pulse", range: "1..*"

// settings for infinately repeating alarm
input name: "alarmDuration", type: "number", title: "Alarm Pulse (ms)",
  description: "Tone duration in alarm", range: "10..*"
input name: "alarmPause", type: "number", title: "Alarm Pause (ms)",
  description: "Pause between tones in alarm", range: "10..*"

}
}

def updated() {
parent.updateSettingsOnDevice()
}

def updatePinState(Integer state) {
if (state == -1) { // represents an infinate alarm activated
sendEvent(name: “alarm”, value: “siren”)
} else if (state == triggerLevel()) {
sendEvent(name: “switch”, value: “on”, isStateChange: true, display: false)
sendEvent(name: “switch”, value: “off”, isStateChange: true, display: false)
} else {
sendEvent(name: “alarm”, value: “off”)
}
}

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

def on() {
beep2()
}

def push() {
beep()
}

def beep() {
parent.deviceUpdateDeviceState(device.deviceNetworkId, triggerLevel(), [
momentary : beepDuration ?: 150,
pause : beepPause ?: 150,
times : beepRepeat ?: 1
])
}

def beep2() {
parent.deviceUpdateDeviceState(device.deviceNetworkId, triggerLevel(), [
momentary : beepDuration ?: 150,
pause : beepPause ?: 100,
times : beepRepeat ?:2
])
}

def siren() {
parent.deviceUpdateDeviceState(device.deviceNetworkId, triggerLevel(), [
momentary : alarmDuration ?: 55,
pause : alarmPause ?: 45,
times : -1
])
}

def both() {
siren()
}

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

def currentBinaryValue() {
invertTrigger ? 1 : 0
}

Did the same thing again. I was correct when I replied…

Not familiar with this forum and posting code. Here it is using blockquote from menu:

/**

  • 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”, mnmn: “SmartThings”, vid: “generic-switch”) {
capability “Alarm”
capability “Switch”
capability “Actuator”
capability “Momentary”
capability “Tone”
}

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

// settings for momentary beep
input name: "beepDuration", type: "number", title: "Beep Pulse (ms)",
  description: "Each beep or blink duration", range: "10..*"
input name: "beepPause", type: "number", title: "Beep Pause (ms)",
  description: "Pause between beeps/blinks in milliseconds", range: "10..*"
input name: "beepRepeat", type: "number", title: "Beep Repeat",
  description: "Times to repeat the pulse", range: "1..*"

// settings for infinately repeating alarm
input name: "alarmDuration", type: "number", title: "Alarm Pulse (ms)",
  description: "Tone duration in alarm", range: "10..*"
input name: "alarmPause", type: "number", title: "Alarm Pause (ms)",
  description: "Pause between tones in alarm", range: "10..*"

}
}

def updated() {
parent.updateSettingsOnDevice()
}

def updatePinState(Integer state) {
if (state == -1) { // represents an infinate alarm activated
sendEvent(name: “alarm”, value: “siren”)
} else if (state == triggerLevel()) {
sendEvent(name: “switch”, value: “on”, isStateChange: true, display: false)
sendEvent(name: “switch”, value: “off”, isStateChange: true, display: false)
} else {
sendEvent(name: “alarm”, value: “off”)
}
}

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

def on() {
beep2()
}

def push() {
beep()
}

def beep() {
parent.deviceUpdateDeviceState(device.deviceNetworkId, triggerLevel(), [
momentary : beepDuration ?: 150,
pause : beepPause ?: 150,
times : beepRepeat ?: 1
])
}

def beep2() {
parent.deviceUpdateDeviceState(device.deviceNetworkId, triggerLevel(), [
momentary : beepDuration ?: 150,
pause : beepPause ?: 100,
times : beepRepeat ?:2
])
}

def siren() {
parent.deviceUpdateDeviceState(device.deviceNetworkId, triggerLevel(), [
momentary : alarmDuration ?: 55,
pause : alarmPause ?: 45,
times : -1
])
}

def both() {
siren()
}

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

def currentBinaryValue() {
invertTrigger ? 1 : 0
}

Makes sense - I have had the same issue with other coding projects. Thanks for catching that and replying!

-peter-