Skip to content

Human/smart-doorbell

Repository files navigation

Purpose

  • This program turns your Raspberry Pi into a doorbell. It can replace a traditional hardware doorbell, and it integrates with openHAB and has a number of customization features.

Features

  1. Integration with openHAB via its simple HTTP API. Know if your doorbell's been rung and take actions accordingly.

  2. Silent mode. It's beneficial for babies or people who act like babies all day when the doorbell interrupts their sleep.

  3. Selectable indoor/outdoor sound location (based on stereo channel). Even if it's silent inside, you can make it play outside so that someone doesn't think your doorbell's broken and resort to knocking.

  4. Configurable sound. You can go with a traditional sound or pick novelty sounds for holidays, specific guests, UPS delivery, etc.

  5. Button timings match a real mechanical doorbell. The software reacts in real time, but there's a (configurable) delay that precedes the playback of the lower-pitch bell.

  6. On-the-fly re-load of configuration changes. This makes the configurable sound feature more powerful.

HOWTO

What You Need

  • Raspberry Pi. (Rev B tested, but any revision should work.)

  • A momentary switch.

  • A resistor. (The resistance depends on how you wire up your switch.)

  • A free GPIO pin.

  • Two WAV files.

  • At least 7% available CPU on your Pi.

  • Basic Linux skills (file copying and editing).

For all Doorbell Types

  1. Wire up a pushbutton on a GPIO pin of your choosing.

    1. There are many different ways to do this. _See online HOWTOs for doing this properly.

    2. The code does not enable built-in pulldown or pullup resistors, so you will need to provide your own resistor._

  2. Copy the project files and folders to a directory of your choosing on your Raspberry Pi.

  3. Edit doorbell_config.ini.

    1. Set input_pin to the 1-indexed board-centric pin number that you used above, as shown here.

    2. If your button takes your input pin LOW when pressed, set reverse_logic to True. Otherwise, set it to False.

    3. Set the paths of the WAV files you want to use (or leave them alone to use the default included sounds).

      1. ding_soundfile will be played on button press.

      2. dong_soundfile will be played on button release.

    4. Set noise_location to reflect where you want your doorbell sounds to play.

  4. In the directory where you copied the project files and directories, run this command:

    sudo python ./doorbell.py
    
  5. Press and release the button as you would a normal doorbell.

For openHAB Integration

  • In openHAB, add a "virtual" doorbell in your .items file for the doorbell, like so:
Switch Button_Front_Doorbell		"Doorbell"		(Outdoor)
  • Set up any rules you'd like to run when it's pressed and released. Example .rules entry:
rule "Virtual Front Doorbell"
when
	Item Button_Front_Doorbell received command
then
    if(receivedCommand==ON) {
      logInfo("Virtual Front Doorbell", "DING...")
    } else if(receivedCommand==OFF) {
      logInfo("Virtual Front Doorbell", "...DONG")
    }
end
  • In doorbell_config.ini, edit openhab_base_URL to point to the URL for your openHAB instance, and edit item_name to match your virtual doorbell. For example:
openhab_base_URL:http://openhab.igo:8080/CMD/
item_name:Button_FF_Doorbell

For Home Assistant Integration

  • In Home Assistant, add a "virtual" doorbell in configuration.yaml as an input_boolean, like so:
input_boolean:
  doorbell:
    name: doorbell state
    initial: off
  • Set up an automation you'd like to fire when it's pressed and released. Example automation:
- alias: notify of doorbell ring
  trigger:
    platform: state
    entity_id: binary_sensor.doorbell
    from: 'off'
    to: 'on'
  action:
    service: notify.medium_priority
    data:
      title: ''
      message: 'DOORBELL'
  • In doorbell_config.ini, edit ha_base_URL to point to the URL for your Home Assistant instance, and edit entity_id to match your virtual doorbell. For example:
ha_base_URL:http://hass.igo:8123/api/states/
entity_id:binary_sensor.doorbell

Additional Options

  • See the comments in doorbell_config.ini to learn about the other ways you can configure your doorbell.

For a Traditional Two-Tone Doorbell

  1. As above, but create or find two bell tones in WAV format. The 'DING' tone should be 3 half-tones in pitch higher than the 'DONG' tone.

For a Novelty Doorbell

  1. As above, using any two WAV files you like.

Example Novelty Ideas

  • DING: "somebody's" DONG: "at the door"

    • A larger value for dong_delay in doorbell_config.ini is likely necessary, to avoid "at the door" stepping over "somebody's."
  • DING: (a dog barking) DONG: (another dog barking)

  • DING: (spooky Halloween ambient sounds) DONG: (random spooky Halloween accent sound)

    • For the accent sound, write a script that periodically edits doorbell_config.ini to point dong_soundfile at a different WAV file.

Third-Party Extension Ideas

  1. Alter doorbell_config.ini to point to different sounds when different external conditions occur, such as calendar events (keywords, holidays, etc.), times of day.

Example Third-Party Extension Ideas

  • DING: "Happy" DONG: "Easter"

    • Use a calendar to pick different WAV files and dong_delay values for doorbell_config.ini.
  • DING: "Hi, [friend's name]." DONG: "I'll be right there."

    • Use openCV to do face or license plate recognition, then change ding_soundfile in doorbell_config.ini appropriately. Change it all back when done.
  • DING: "Hi. We're asleep right now, so please leave a message after the beep. BEEP" DONG: (silence)

  • Boodler is a Python soundscape generator. You could either generate "canned" instances of dynamically-generated soundscapes and switch between them using methods outlined above, or you could extend the software architecture to invoke Boodler instead of playing WAV files.

Questions?

  • I'm happy to field any questions in the comments on my corresponding blog post.