Doorbell project - filter out annoying multi-button-and-long-press-users

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:

  1. Only keep the relay on for ~100ms after the button are pressed. The current config keeps the relay closed until the button are released.
  2. 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
switch:
  - platform: gpio
    name: "R1"
    pin: GPIO0
    id: my_switch
    inverted: yes
    on_turn_on:
    - delay: 0.1s
    - switch.turn_off: Relay1
script:
  - id: my_script
    mode: single
    then:
      - switch.turn_on: my_switch
      - delay: 5s
# in a trigger:
on_...:
  then:
    - script.execute: my_script
1 Like