Hi!
I’m doing my old doorbell a little bit smarter, similar to this:
Have set it up and it’s working as expected.
I do have two additional functions I need to implement:
- Only keep the relay on for ~100ms after the button are pressed. The current config keeps the relay closed until the button are released.
- Only trigger the relay once, even if the button are pressed repeatedly (only register 1 press every ~5s)
How shall I do/think to make those changes?
# Global to store the on/off state of the chime
globals:
- id: chime
type: bool
restore_value: true
initial_value: 'true'
# Exposed switches.
switch:
# Switch to turn on/off the chime.
- platform: gpio
id: relay
inverted: true
name: Doorbell Chime
pin: GPIO0
# Switch to turn on/off chime when
# doorbell button is pushed.
#
# It creates a "virtual" switch based
# on a global variable.
- platform: template
name: Doorbell Chime Active
id: chime_active
restore_state: false
turn_on_action:
- globals.set:
id: chime
value: 'true'
turn_off_action:
- globals.set:
id: chime
value: 'false'
lambda: |-
return id(chime);
# Binary sensor representing the
# Doorbell button push.
binary_sensor:
- platform: gpio
id: button
name: Doorbell Button
pin:
# Connected to GPIO on the ESP-01S.
number: GPIO2
mode: INPUT_PULLUP
inverted: true
filters:
# Small filter, to debounce the button press.
- delayed_on: 25ms
- delayed_off: 25ms
on_press:
# Only turn on the chime when it is active.
then:
if:
condition:
- switch.is_on: chime_active
then:
- switch.turn_on: relay
on_release:
# On release, turn of the chime.
- switch.turn_off: relay