Activate Buzzer

I have searched but was unsuccessful in finding a solution. I have an ESP8266 with ESPHOME installed on it. There are 3 sensors and 1 buzzer connected to the ESP8266. I want to create an automation that will trigger the buzzer when certain parameters go out of range. For example, if the water temperature exceeds 75 degrees, I want the buzzer to sound. Is this achievable with ESPHOME and HA Automation? Here is my current YAML source code; any guidance would be much appreciated.

substitutions:
  name: "saltwater"
  friendly_name: Salt Water Fish Tank

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: '1.0'

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:

# Allow provisioning Wi-Fi via serial
improv_serial:

wifi:
  # Set up a wifi access point
  ap: {}

# In combination with the `ap` this allows the user
# to provision wifi credentials to the device via WiFi AP.
captive_portal:

dashboard_import:
  package_import_url: github://esphome/example-configs/esphome-web/esp8266.yaml@main
  import_full_config: true

# To have a "next url" for improv serial
web_server:

# Define buzzer component (replace GPIOx with a supported pin)
output:
  - platform: gpio
    pin: GPIO15  # Replace GPIO15 with a valid GPIO pin number
    id: buzzer_output

# Define binary sensor for water float sensor
binary_sensor:
  - platform: gpio
    pin: GPIO2
    name: "SaltWater - Water Level Sensor"
    filters:
      - delayed_on: 500ms
      - delayed_off: 500ms

# Define sensors
dallas:
  - pin: GPIO4

 # Define sensors  
sensor:
  - platform: dallas
    address: 0x0e0302979409c628
    name: "Salt Water Temperature"
    unit_of_measurement: "°F"
    filters:
      - lambda: return x * (9.0/5.0) + 32.0;
    

  - platform: adc
    pin: GPIO17
    name: "SaltWater - TDS Sensor"
    update_interval: 60s
    filters:
      - calibrate_linear:
          - 0.0 -> 0.0
          - 4095.0 -> 2000.0  # Adjust this calibration value according to your TDS sensor
    unit_of_measurement: "ppm"

What is this buzzer?

1 Like

Yes this is possible.

To get started, take a look at Automations.

And this may be helpful depending on your buzzer.

Add this to your sensor

on_value_range:
- above: 75
then:
- output.turn_on: buzzer_output

…and when you get tired of that sound, study Automations to make it turn off…

It all comes down to whether its a passive buzzer or not. If you dont know because you didnt build the circuit yourself then if you could identify the board name or even a picture.

1 Like

I created my own PCB. It’s a 2 wire buzzer as shown in my picture. I will try what Karosm said as that looks like what I needed.

2024-05-11_09h38_40

1 Like

Active and passive buzzers are both two pin components. Did you try it? If it’s passive, your code would’t make it beep.

I struggled for 10 minutes getting the format/spacing correct on what you gave me. I finally got it and it works like a charm. So this is done via the yaml file and not in the automation area correct? I need to add other alerts like if water is below 65F , then buzzer. If I want to setup email alerts, that would be done in the automation area and or in the yaml file right?

Below is what I put in and it worked perfectly. Your assistance is very much appreciated.

 # Define sensors  
sensor:
  - platform: dallas
    address: 0x0e0302979409c628
    name: "Salt Water Temperature"
    unit_of_measurement: "°F"
    on_value_range:
      - above: 75
        then:
        - output.turn_on: buzzer_output
    filters:
      - lambda: return x * (9.0/5.0) + 32.0;

You’re welcome.
I don’t even know, what automation area is…

This area

I don’t use home assistant (even if I have esphomes taking care of my home automations).

I also added below for temp and it works perfectly. Again I appreciate your help Karosm!!

Heretic :open_mouth: lol

I do have one more thing I need help adding. I have a water float sensor. It is a 2 wire. It’s either on or off. How can I add the same feature to sound buzzer if the state is changed to off?

# Define binary sensor for water float sensor
binary_sensor:
  - platform: gpio
    pin: GPIO2
    name: "SaltWater - Water Level Sensor"
    filters:
      - delayed_on: 500ms
      - delayed_off: 500ms

c’mon, you really should at least have a look of “automation” section of esphome guide…

on_press:

Esphome is actually working fabulously standalone. Web Server and Automations, HTTP api and MQTT is all what I really need. I don’t need fancy dashboard on my wall.
Only thing I have ever missed is numeric input on the web server.

Few Esphomes are taking care of my PV system, power diverter for hot water, ble thermo-hygrometers, heat pumps, some switches and outlets…

Most of the time you can do this either on the esphome device, or in home assistant.

on_press and on_value_range are literally the first two examples on the automation page (link was provided earlier).

So please do give that a read.

Understood, my apologies. I really do not understand the code much, but I will refrain from asking anything else. Thanks.

We are here for asking and answering. No apologies.

on_value: for sensors that give a value
on_press: for everything that is on/off (like binay sensor,button,switch etc)