Smart Doorbell - Using Raspberry Pi 5 / Jitsi / Telegram
by roosgr in Circuits > Raspberry Pi
157 Views, 1 Favorites, 0 Comments
Smart Doorbell - Using Raspberry Pi 5 / Jitsi / Telegram
What
This smart doorbell notifies the owner on Telegram when the button is pressed. It sets up a Jitsi videocall meeting and the owner can talk with the visitor for a brief time. The LED indicates when the camera is on to inform the visitor.
Background
Smart doorbells are incredibly popular in the Netherlands. As of 2024, 15% of Dutch households have one. However, the popular brands and their users are often not compliant with Dutch and European privacy laws. Public space is filmed against the rules, images of people are posted online without consent, faces are never blurred, people are rarely informed when they're being filmed, and footage is stored longer than necessary.
Can a responsible smart doorbell exist? The smart doorbell in this Instructable is a first experiment of a smart doorbell that's open source and compliant with Dutch law. It is just a prototype that isn't a "responsible smart doorbell" yet. We're also not quite sure if it could really survive Dutch rain.
Please remember, a smart device that's placed outside of your house, is always a security liability. On every smart device (even a fancy Ring Doorbell), the owner's Wi-Fi password is stored. In theory, a smart hacker could remove the smart device from your facade and gain access to your home's network.
All in all, proceed with care and understanding.
This workshop is developed by media artist Roos Groothuizen and Tkkrlab hackerspace founder Dave Borghuis.
Supplies
Used techniques:
- Circuitry
- 3D printing
- Python
- API implementation (Telegram bot)
- Jitsi videocalling
- Terminal commands
- Raspberry Pi imaging & remote connection
- Soldering electronics
- Threaded inserts + soldering iron
Needed apps/accounts:
- Raspberry Pi Imager
- Telegram (phone or web)
- Raspberry Pi Connect (or a different VNC viewer of your choosing)
- 3D printer slicer when you're printing yourself
Needed hardware
- Tiny philips screwdriver
- Soldering iron and soldering supplies
- Sharp knife
- 3D printer and supplies when you're printing yourself
- (Tweezers to hold screws and inserts in place)
Doorbell hardware (no affiliate links):
- Raspberry Pi 5 4GB RAM + official power adapter
- Pi 5 CPU heatsink of your preference (it gets a bit hot in the case)
- 90° angled USB C male-female connector
- USB speaker, taken apart
- USB microphone
- Pi Camera 3 + Pi5 ribbon cable (usually comes with the camera, double-check before you buy)
- LED reset button
- 5mm LED
- 5mm LED holder
- 150Ohm resistor
- 4x M2 threaded inserts
- 4x M2 5mm bolts
- 6x M2.5 threaded inserts
- 6x M2.5 6mm bolts
- 6 jumper wires with one female end, other end stripped for soldering (15-20cm long, gives you some wiggle room when you're putting the box together)
- Heatshrinks for your soldered connections or a different insulation method
Set Up Raspberry Pi
We're skipping the Raspberry setup details since there's good documentation on this.
- Set up your Raspberry Pi with Raspberry's Imager.
- Use custom settings. Enter a custom username, pi name and password, your Wi-Fi credentials and enable SSH.
- Boot up your Pi with the imaged SD card.
- Log into your Pi through the terminal and SSH (trick: instead of using ssh <username>@<ip address>, you can also try ssh <username>@<pi name>.local )
- Set up Raspberry Pi Connect
- Once that's set up, turn off your Raspberry Pi and remove the power plug, as we'll move on to adding circuitry to the board.
Soldering
- Solder a 150Ohm resistor to the long leg (anode) of the 5mm LED
- Then, solder a jumper wire with a female end to the resistor
- Solder a jumper wire with a female end to the short leg (cathode) of the 5mm LED
Note: The LED in the picture had its legs cut short to make it more manageable in the doorbell box. Heatshrink was added afterwards.
- The button has four legs. Two are for the button and two are for the ring light. Both systems operate individually. Next to each leg, we read one of the following symbols: +, -, NO, NO
- The plus and minus are for the ring light (also an LED)
- The two NO legs indicate 'Normally Open'. This means the switch is always open. When pressed, two metal pieces make contact inside of the button, thus closing the circuit and allowing voltage to go through.
- Solder a jumper wire with a female end to each leg.
Note: It's important to use a color system when using jumper wires. Always use black or brown for negative/ground connections, use red or orange for positive/voltage connections and use the other colors for data connections.
Stripping and Resoldering the USB Speaker
While writing this, we haven't figured out a better solution for a tiny speaker setup for the Pi 5.
The Pi 5 no longer has an audio jack and the audio firmware has been removed. That means a speaker can no longer be connected to the GPIO pins (at least, we haven't been able to figure it out. Let us know if you have the trick!) The only way of connecting audio with the Pi 5 is through HDMI, Bluetooth or USB.
We've found this small USB speaker online with a tiny USB audio board and left+right speakers. It is automatically recognized by the Pi as an audio device. The audio quality is fine for our purpose. Multiple webshops sell this specific speaker (search for "double usb speaker, small, black" or something like that).
- On the backside of the speaker, pry the black dot out of the casing with a sharp knife.
- Unscrew the tiny screw.
- Cut the usb wire to about 15-20 cm length and take the shell off.
- Remove one of the speakers by carefully prying it loose from the board.
- Resolder the existing usb connector, or use a brand new one from a USB connector kit.
Note: It's very important to re-solder the wires in the correct order. Again, black and red are negative and positive, white and green are data. See picture for reference.
Circuitry
Make sure the power adapter is disconnected to prevent short-circuits
- Connect the positive (anode) of the 5mm LED to GPIO 14 (Pin 8)
- Connective the negative (cathode) of the 5mm LED to ground (Pin 9)
- Connect the button's positive (+) leg to 5 Volts (Pin 4)
- Connect the button's negative (-) leg to ground (Pin 6)
- Connect one of button's NO leg to GPIO 26 and the other one to ground (Pin 37 & 39).
- Connect the Pi Camera [youtube how-to]. Be careful not to sharply fold or crunch your ribbon cable.
- Connect the USB microphone to the upper left USB port
- Connect the USB speaker to the bottom left USB port
- Stick a heatsink on your Pi's CPU if you've bought one
Clone Git
Boot your Pi and connect with your remote viewer.
The code is written in Python. When the button is pressed, it sends a message to Telegram and sets up a Jitsi call.
Find the most recent version of our code on: https://github.com/zeno4ever/zip_pi_doorbell. In this tutorial, we'll clone the entire folder via the Pi's terminal.
- Clone our Github repository. Terminal: git clone https://github.com/zeno4ever/zip_pi_doorbell
- Enter your newly created folder 'zip_pi_doorbell' with Terminal: cd zip_pi_doorbell
- Copy 'config.py.example' to 'config.py' with the 'cp' command in Terminal: cp config.py.example config.py
- We'll edit config.py after setting up the Telegram bot.
config.py needs to know the following:
- Your pi's username
- Your Telegram bot token
- Your Telegram channel id
- Your personalized Jitsi url
config.py
Testing Your Hardware
- Test the camera, speaker and mic by setting up a Jitsi call on [https://meetme.bit.nl/ or a different Jitsi server]
- Note: Adjust your sound to full volume in the Pi's upper bar right corner
- Test the button and 5mm LED with a simple Python script that we wrote and is included in zip_pi_doorbell:
- Terminal: cd zip_pi_doorbell (only use this if your Terminal is not in that folder anymore)
- Terminal: python test_led.py
- When you press the button, the LED should turn on for 3 seconds
- Stop the script with ctrl+c in the terminal
test_led.py
Set Up Telegram Bot and Jitsi URL
For this step, you'll need to download Telegram and a user account. This step can be followed on Telegram's phone app, web app or desktop version. Learn more about Telegram bots here.
- Create a Telegram bot via these steps.
- BotFather will congratulate you on creating a new bot and give you its token. It is a long string with numbers, a colon and then a lot of characters.
- Create a new channel in Telegram, be creative with a name. Set the channel to private.
- In the channel's settings, add a new admin. Add your bot as an admin. As far as we know, the admin permissions are not really important.
- Now, navigate in your webbrowser to the following url: https://api.telegram.org/bot<token>/getUpdates . Replace <token> with your bot token. *
- You should see some JSON-related information, including 'ok: true'
- Say hi in your new channel by typing something to your liking.
- Refresh that JSON page. You should now see some information like in the picture here, including your sent message. Listed under 'chat', there is a variable called 'id' with a long number with a dash in front of it. This is your channel id, including the dash. *
We're using Jitsi to set up a video call between the doorbell and the user's smartphone. Jitsi is a free and open-source videocalling platform. Anyone can set up a Jitsi service on their own server if they are tech-savvy enough. Many websites offer their Jitsi platform for free to others. We're using https://meetme.bit.nl/ in this tutorial, but with a quick web search you can also find alternatives.
- Terminal: cd zip_pi_doorbell (only use this if your Terminal is not in that folder anymore)
- Edit config.py on your Pi with the Terminal command: nano config.py
- In the url placeholder, change {your_channel} to a unique Jitsi meeting name to your liking. It's a bit like a password.
- Change the telegram_token placeholder to your bot token. Keep the apostrophes.
- Change the telegram_chat placeholder to your channel id. Include the dash. No apostrophes.
- Change userid to your pi's username.
- Use crtl+o to save your file, then ctrl+x to exit the editor.
*Alternatively to the JSON method, you can also run the test_telegram.py script included in zip_pi_doorbell.
- Update your config.py first with your bot token.
- Run Terminal: python test_telegram.py
- The script returns the channel id to you and sends a message in your Telegram channel.
Test the Script
- Terminal: cd zip_pi_doorbell (only use this if your Terminal is not in that folder anymore)
- Test the code by running Terminal: python doorbell.py
- The script lets you know if things are running correctly.
- When the bell is pressed for the first time, double-check your permissions when the browser is opening in the pi (check all the boxes for 'firefox as standard browser', 'remember mic and camera permissions' etc)
- Turn your volume up in the upper right corner if you haven't already
Autostart
Create an autostart directory.
- Terminal: mkdir ~/.config/autostart
- Change the directory paths in the doorbell.desktop file: Terminal: nano zip_pi_doorbell/doorbell.desktop
- Change this part: Exec=/home/pi/zip_pi_doorbell/doorbell.py replace pi with your pi's username
- ctrl+o to save, then ctrl+x to exit the editor
- Move file 'doorbell.desktop' to ~.config/autostart/ in Terminal: mv zip_pi_doorbell/doorbell.desktop ~/.config/autostart/
- Reboot the pi and wait until its fully booted. Pres the button and enjoy your own DIY smart doorbell.
3D Printing
We've made a couple of designs and used a Prusa MK3S to print everything.
If you don't own a multi-material printer like us, the trick is to print just 1 layer of the graphic on the printer bed first (adjust the height of the model to your preferred layer-height in your slicer). When the print's finished, swap out the filament and start printing the case right on top of the graphic. The heat will glue the 2 colors together and you're left with a smooth, flush base layer.
For the result in the picture, we've used the concentric layer lines setting in Prusa slicer.
Included files:
- 1 STL base
- 1 STL lid*
- 4 SVG graphics
- 4 3MF PrusaSlicer files with the graphics pre-aligned to the lid
- A how-to on how to export the files as gcode correctly
* The LED hole is located differently in every design so it's excluded from the lid .stl file. You'll need to add a 7mm hole in the slicer or drill it after printing. Manually add this in PrusaSlicer by right-clicking the object, <add negative volume>, <cylinder>.
Threaded Inserts
- Melt 4 M2 threaded inserts with a hot soldering iron into the camera screw holes of the case lid
- Melt 4 M2.5 threaded inserts into the Pi screw holes in the case base
- Melt 2 M2.5 threaded inserts into the left and right sides of the case base
Assembly
Assembling the Pi is less troublesome when the camera and jumper wires are disconnected. Be careful with your camera cable.
- Push your (unplugged) power adapter through the square hole, add an angled connector to it and connect it to the Pi.
- Guide your speaker wire under the Pi. The speaker goes into the little cup (double-sided tape can hold it in place).
- Squeeze the Pi down on top of the power wire, speaker wire and screw holes, and add M2.5 bolts to fasten it.
- Screw the camera into the case lid
- Push the LED holder through the hole from the outside, and add the LED by pushing it from the inside. You'll hear a faint click.
- Add the button, it comes with a nut to tighten it.
- Connect all the jumper wires to the correct pins.
- Time to put the lid on, carefully fold the ribbon cable and the jumper wires in the case while placing the lid.
- Screw it shut with the two M2.5 bolts on the sides