Setting up intermittent warning buzzer

I am using a couple of ESP8266 boards with Home Assistant for sensors and alarms.  All is working fine.

I have just added a 3.3v piezo buzzer to pin 8 of one of my boards to use as an alarm pending warning.  The buzzer works fine if set up as a continuous sounder.  I would like to set it up as an intermittent warning buzzer.  The following code works fine:

 

      switches:
        - pin: 8
          name: 'Warning buzzer'
          momentary: 500
          pause: 500
          repeat: 15

 However, I would like a continuous buzzer that stays on until the switch is switched off.  I have tried:

 

      switches:
        - pin: 8
          name: 'Warning buzzer'
          momentary: 500
          pause: 500
          repeat: -1

 As per the documentation.  With this setup, the buzzer sounds only once and then stops.  The switch in HA acts as a momentary switch, and turns off about a second after turning on.

Any idea what I am doing wrong?

Figured this out (thanks Nate).  The beep feature was added in a later version of the firmware - I have updated all of my boards and they are now working as expected.

Hi @mail2 @nate

I hope that it is ok that I ask here even though this is an old topic. Did the commands changed a bit since you posted here? I get some errors with your code.

I would like to set up my buzzer to give 2 beeps every time it is turned on. It was one of the options with the konnected firmware. From what I read, I could use a momentary switch to get one beep:


switch:
  - platform: gpio
    pin: $out
    id: warningbeep
    name: warning beep 1
    on_turn_on:
    - delay: 50ms
    - switch.turn_off: warningbeep

Could you please advise me on how to combine it with the repeat action to get a double beep? I am very new to ESPhome. I can think of some kind of virtual switch that is triggered when the warningbeep switch is turned on and then if the virtual switch is turned on: delay 50ms → switch.warningbeep OFF, delay 50ms, ON, delay 50ms, OFF, turn the virtual switch OFF but is there a cleaner way?

Here is what I do to configure the buzzer in esphome I use for my door chirp:

Configure the output

output:

  • platform: ledc
    pin: GPIO13
    id: buzzer_output

switch:

  • platform: output
    name: ‘buzzer’
    id: buzzer
    output: buzzer_output
    on_turn_on:
    then:
    - output.turn_on: buzzer_output
    - output.ledc.set_frequency:
    id: buzzer_output
    frequency: “200Hz”
    - output.set_level:
    id: buzzer_output
    level: “100%”
    - delay: 80ms
    - output.turn_off: buzzer_output
    - delay: 70ms
    - output.turn_on: buzzer_output
    - output.ledc.set_frequency:
    id: buzzer_output
    frequency: “200Hz”
    - output.set_level:
    id: buzzer_output
    level: “100%”
    - delay: 80ms
    - output.turn_off: buzzer_output
    - switch.turn_off: buzzer

    on_turn_off:
    then:
    - output.turn_off: buzzer_output

Thank you! I have couple of questions to make sure that I understand this correctly. Why are you using the ledc platform? To modulate the frequency? I am using the simplest possible buzzer where I can only have it on or off. In such case, would you still recommend using platform: ledc?

Anyway, it seems like a virtual switch would is the best solution. I just tried this and it works as it should! I am not sure if it is the best solution but as long as it works… :slight_smile:

Now I am wondering if it is possible to trigger a buzzer if a sensor wired to another ESP is triggered. Then I could move more automations to ESPHome

switch:
  - platform: template
    name: "buzzer virtual switch"
    id: buzzervs
    restore_mode: always_off
    turn_on_action:
      - switch.turn_on: warningbeep
      - delay: 100ms
      - switch.turn_off: warningbeep
      - delay: 100ms
      - switch.turn_on: warningbeep
      - delay: 100ms
      - switch.turn_off: warningbeep
      - switch.turn_off: buzzervs

  - platform: gpio
    pin: $out
    name: 2nd_floor_buzzer
    id: warningbeepk2
    restore_mode: always_off

If you’re using Konnected’s ESPHome packages, there’s a built in warning_beep that acts as a light entity so we can use the strobe effect to make it beep repeatedly until turned off. This is already built-in! Just turn it on and off like this:

- light.turn_on:
    id: warning_beep
    effect: strobe

You can change how fast the beeps are by setting the substitution variable warning_beep_pulse_time and warning_beep_pause_time:

substitutions:
  warning_beep_pulse_time: 50ms
  warning_beep_pause_time: 60ms

Pulse is the duration of the beep and pause is the time between beeps.

To make a buzzer that makes only X beeps every time it’s pressed, I my suggestion would be to create a button template that activates the buzzer_output in your desired pattern on press:

button:
  - platform: template
    name: Two beeps
    on_press:
      - repeat:
          count: 2
          then:
            - output.turn_on: buzzer_output
            - delay: 50ms
            - output.turn_off: buzzer_output
            - delay: 50ms