How to make a doorbel using RPI-GPIO? (moving custom python to HA)

Hello All
I am new here. I have read through a lot of stuff and used the search engine however I need help to figure out how o convert my current doorbell on the RPI to HA.
The current doorbell is written in Python does the following:

  1. waits for an interrupt on a GPIO pin-16. When detected, someone pressed the doorbell
  2. when an interrupt is received on pin-16, GPIO pin-15 is made active to enable the amplifier (custom amplifier with enable to save power and also will not have any noise when off).
  3. Next a sound is played which depends on the time of day (horn in the afternoon, crowing rooster in the morning :wink: )
  4. the date/time is logged. Which by the way is very valuable if DHL, FEDEX or UPS or similar says that you where not home and you can show them that they did not even rang the bell…
  5. as last action the GPIO-15 is made low again to disable the amplifier.

If have found how to play a sound. I have found that there is a rpi_gpio platform. But I do not know how to use a GPIO pin as input? And I would like to use interrupts as well, as polling can be too slow, or is that not needed?

Made some good progress. With the binary sensor I can detect when the boor bell button is pressed. When the button is pressed (makes connection to gnd) some lights will flash. Next step is to play a sound.

Configuration.yaml

binary_sensor:
  - platform: rpi_gpio
    ports:            
      22: Deurbel
    pull_mode: UP

Automations.yaml

- alias: Doorbell pressed 
  trigger:                
    - platform: state     
      entity_id: binary_sensor.doorbell
      from: "on"                      
      to: "off" 
  action:       
    - service: light.turn_on
      data:                 
        entity_id:          
        - light.xxxx
        - light.yyyy
        flash: long

Hi ! Nice project!

I Just want to connect my doorbell with the rpi gpio pin. Could you guide me witch physical pins i need and what to setup as sensor pin?

Hi Martin

For input pin, where you connect your doorbell switch to, I would suggest GPIO-22 which is pin 15 of the RPI connector.
You need to a a so called debounce circuit. You can make it by adding a 100nF capacitor between your input pin (GPIO-22) and GND (pin 6, 9, 14, 20 or 25 for example). Secondly a resistor of 47kOhm between +3.3V (pin 1) and the input pin.

hope this helps
[EDIT corrected resistor to 3.3V not 5V as wrote earlier)

Hi Why would i need that? A pi has build in resistors.

You could try without the resistor, as long as you have the pullup option switched on. Although I am not sure and have not tried it if the debouncer will still work. The capacitor you will still need for sure.

If you do not have the debouncing circuit, you will get multiple triggers when someone presses the bell. You might even get triggers when no one is pressing the bell, just be some other events that generate some static electrical fields. It will happen, I know from experience :frowning:

I have it working. In the ‘share your projects!’ you can find how I have done it.