8000 GitHub - casakampa/doorbell: Python doorbell script running as a systemd service on my Raspberry Pi 4
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

casakampa/doorbell

< B63E a type="button" aria-label="Go to Branches page" href="/casakampa/doorbell/branches" class="prc-Button-ButtonBase-c50BI OverviewContent-module__Button_1--_1Ng2" data-loading="false" data-no-visuals="true" data-size="medium" data-variant="invisible" aria-describedby=":Relab:-loading-announcement">

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

Doorbell

The doorbell is installed as a systemd-service. The script itself contains various functions that are explained below the installation steps. And if you want to build this yourself, take a look at the hardware section.

Steps for installation:

  1. Become root

    sudo -i
  2. Download the necessary Python3 packages:

    apt install python3-tz python3-rpi.gpio python3-paho-mqtt
  3. Create the file doorbell.py file (I use nano, but you can use the editor you prefer):

    nano /home/user/doorbell/doorbell.py

    and add the code from the file doorbell.py found in this repository.

  4. Save the file and exit nano:

    • Ctrl + o
    • Enter
    • Ctrl + x
    • Enter
  5. Create the configuration for systemd:

    • Create a new file

       nano /etc/systemd/system/doorbell.service
    • Copy the text below into the file:

       [Unit]
       Description=Run doorbell.py in /home/user/doorbell/
      
       [Service]
       ExecStart=/usr/bin/python3 /home/user/doorbell/doorbell.py
       Restart=always
       User=root
      
       [Install]
       WantedBy=multi-user.target
      
    • Save the file and exit nano:

      • Ctrl + o
      • Enter
      • Ctrl + x
      • Enter
    • Make it executable

       chmod +x /home/user/doorbell/doorbell.py
  6. Update systemd:

    service daemon-reload
  7. Enable the doorbell service (so it starts when the system restarts):

    systemctl enable doorbell.service
  8. Start the doorbell service:

    systemctl start doorbell.service

If everything went well, your doorbell should ring when you press the doorbell button.

The inner workings of the doorbell script

The script reads the GPIO pins on the Raspberry Pi. The 3.3V DC power supply is used for the doorbell button. GPIO pin 24 - right next to the 3.3V pin - is used as a sensor to detect power. When someone presses the doorbell button, the circuit closes and GPIO pin 24 detects power.

Then the script checks if someone presses the doorbell button between certain times, and if so, switches a relay - controlled by GPIO pin 17 - to trigger the real doorbell. At the same time, a message is sent to Home Assistant via MQTT to perform some automations related to the doorbell.

Hardware

The following hardware is used to make all this possible:

  • Raspberry Pi 2 or higher
  • Doorbell push button - the most standard version that can be found online - connected to a 3.3V pin and a GPIO pin (I use physical pin 17 (3.3V) and 18 (GPIO pin 24) for detection).
  • 1 channel relay board - connected to the 5v power pins of the Raspberry Pi and GPIO pin 17

Wiring the doorbell

The doorbell wiring is connected to the 1 channel relay as Normally Open (NO). A Normally Open relay will switch to Normally Closed (NC) when the coil is activated. This will result in the circuit being closed and so the doorbell will ring.

About

Python doorbell script running as a systemd service on my Raspberry Pi 4

Topics

Resources

Stars

Watchers

Forks

Languages

0