As title says, I connected an active buzzer I’m planning to use for audio feedback/notification. It’s a simple 5v buzzer with just + and - connections, works fine using a 2n2222 transistor for driving it. Works fine with this script to play a single beep.
esphome:
# whatever your would put here
on_boot:
priority: -10
then:
rtttl.play: 'start:d=4,o=6,b=200:c,e,2g'
# or in any other action block
rtttl:
output: buzzer
# speaker connection
output:
- platform: ledc
pin: GPIO26
id: buzzer
Thanks I didn’t know about scripts, this looks exactly like what I need. Looks like I can even define different beep codes and call them from different automations, which is what I’m looking for. Will try and report back.
Finally got around to test this! I did a script with short 4 beeps, and it works, but the switch looks like this when it’s running: https://files.catbox.moe/94y8ad.mov
Is there a way to avoid the switch flicker? I’m afraid not.
I know this is old post. Have you tried to use different pin rather than D3 to confirm its not flickering?
Anyone trying to setup something like this, you may use simplified version of this as given below. I am using this on esp8266 d1 mini.
switch:
- platform: gpio
pin: GPIO14 #Your GPIO where the buzzer is connected at
id: buzzer
name: "Your Alarm"
on_turn_on:
- script.execute: buzzer_five # Name this as you want.
script:
- id: buzzer_five # Use the same buzzer name you have given above.
then:
- repeat:
count: 5
then:
- switch.turn_on: buzzer
- delay: 500ms
- switch.turn_off: buzzer
- delay: 1000ms
Hi sri4iot, the solution to the switch flickering was just to use a button instead of the switch. With newer esphome versions I have also found that there is less random delays in beeps.