I have an old Videx intercom that acts as a doorbell by the speaker end of the handset buzzing. It’s difficult to hear it in other parts of the house. I had put an esp32 with a 5V dry contact relay in the handset so I could open the gate remotely. I didn’t fancy connecting anything directly to the buzzer. So I attached a KY-038 to the esp32 as well.
Added a biniary sensor by gpio to the ESPhome bin.
Setup an automation to notify me by telegram bot when KY-038 detected a loud sound like the buzzer right next to it going off. The problem was it also alerted me when it picked up doors slamming in the hall where the buzzer was.
The first 2 readings are doors and the 3rd reading is the longer buzzer.
The binary sensor of the KY-038 would fire off multiple times on/off for a door slam and several times more for a buzzer.
binary_sensor:
- platform: gpio
pin: 2
name: "Sound level"
filters:
- delayed_off: 35ms
I started trying different filters for the binary sensor. I found at 35ms a door slam would generate 2 or 3 on/off’s and a few more for the buzzer. Adjusting potentiometer on KY-038 is too difficult to useful.
I then setup an automation to count the on/off’s and only send a telegram when got more than 4. I set it to reset the count every minute
In configuration.yaml
input_number:
loudnoise:
name: loudnoise
icon: mdi:clock-start
initial: 0
min: 0
max: 6
step: 1
in automations.yaml
- alias: 'Automation to increment input_number when sensor is turned on'
trigger:
- platform: state
entity_id: binary_sensor.sound_level_2
to: 'on'
from: 'off'
action:
- service: input_number.increment
data:
entity_id: input_number.loudnoise
- alias: 'Reset input number after 1 minute after the sensor is triggered for the first time (after sensor triggering the input number becomes 1)'
trigger:
- platform: numeric_state
entity_id: input_number.loudnoise
above: '0'
below: '2'
action:
- delay: 00:01:00
- service: input_number.set_value
data_template:
entity_id: input_number.loudnoise
value: '0'
- alias: 'Turn on switch when input_number.loudnoise reaches 4'
trigger:
platform: numeric_state
entity_id: input_number.loudnoise
above: 3
below: 6
action:
- service: notify.telegrambot
data:
message: Doorbell
Seems to work so far.