Door bell with pi camera and motion detection

i tried a human detection script but it is too slow for the doorbell, takes around 5 seconds to process each cycle.
so will be honing the last script i posted above, I found because it is at my front door and it points to the outdoors , if a car moves or a tree sways with the wind too much it is triggered.
so im going to try and scan a section of the camera image and process it.

1 Like

This is fairly interesting, uses pre-recorded voice scripts, which could be interactively selected via a telegram bot https://www.hackster.io/naran-inc/diy-smart-home-doorbell-2-0-works-with-alexa-690c33

Also I edited the rpi-rf listen script to listen for a single code_of_interest. Now rather than printing ‘Bell pressed’ you could call the camera script. Let me know if this works out :slight_smile:

#!/usr/bin/env python3

import argparse
import signal
import sys
import time
import logging
from rpi_rf import RFDevice
rfdevice = None

# pylint: disable=unused-argument
def exithandler(signal, frame):
    rfdevice.cleanup()
    sys.exit(0)

logging.basicConfig(level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S',
                    format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', )

parser = argparse.ArgumentParser(description='Receives a decimal code via a 433/315MHz GPIO device')
parser.add_argument('-g', dest='gpio', type=int, default=27,
                    help="GPIO pin (Default: 27)")
args = parser.parse_args()

signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
logging.info("Listening for codes on GPIO " + str(args.gpio))

code_of_interest = '9181186'
while True:
    if rfdevice.rx_code_timestamp != timestamp:
        timestamp = rfdevice.rx_code_timestamp
        #logging.info(str(rfdevice.rx_code) +
         #            " [pulselength " + str(rfdevice.rx_pulselength) +
         #            ", protocol " + str(rfdevice.rx_proto) + "]")
        print(str(rfdevice.rx_code))
        if str(rfdevice.rx_code) == code_of_interest:
            print('Bell pressed')
            break
    time.sleep(0.01)
rfdevice.cleanup()
1 Like

Summary of things done and things to do.

I am going to use the rf button press, as it will be easier to have 2 small and neat enclosures (1 for the button and the other for the camera/pi)

Im toying with the idea of forgetting motion detection just poll for face detection and recognition.
So the device will work as follows.

The pi will be monitoring the camera live stream for face detection, so when a face is detected it will notify someone is approaching, it will send an MQTT message to home assistant with a photo of the face/es detected, personally I will the have HA send the photo to my phone via telegram, and to my Televisions if I can figure out a way of getting the image across.

When the doorbell is pressed a similar procedure will occur, just a different MQTT topic will be sent.

The idea of having both instances being triggered is because sometimes we get people at the front door who choose not to press the doorbell and just knock, or approach the door and then depart. I think it is a good security feature to have.

Both of these I have almost completed the code for, Im currently using it on the door now, but this is my previous attempt which is giving me silly amounts of false positives as it purely detects motion, and I found regardless of the settings it still detects the tree opposite my house swaying in the wind, it works beautifully on a nice calm day , but we are in the UK so we dont get many of those.

Next steps…
Once finished the previous steps I want to find something which allows me to communicate with the doorbell via my phone (Android). This seems to be the largest hurdle of all.
The idea of this as previously mentioned once the doorbell is pressed (depending on the Home/Away status within the script) If nobody is in it will send a notification to my phone which gives me a prompt to communicate with the person at the door.
If someone is home it will simply notify the household by a doorchime or any kind of notification/automation via home assistant, I like the idea of a HTML 5 notification so it pops up on any of my TV’s, if the face is recognised it could announce who is at the door, which is the icing on the cake.

1 Like

I think I will concentrate on getting the script into a usable state before I do any more experimenting with the audio communication, as it is dragging on, then once I have that accomplished I can devote more time to experimenting with some ideas I have,first idea I thought maybe just record the wav file and just send it to and fro as the conversation requires, the downside being there will probably be a fair bit of latency involved.
Another option will be using vlc to stream the audio from each end , but not 100% how this will be implemented.

Recently I havent had much time to devote to the project as recently I have found out I am going to be a Grandad \o/ , so Ive been helping my daughter move house, and settling in.

However I intend on spending the next few evenings finishing off my scripts testing and adjusting it so hoping I will have a completed model by the end of the weekend.

1 Like

Congratulations on becoming a grandad! I’ve been spending my time trying to get this iOS app working :joy:

1 Like

Which app is that?

Just the home-assistant app

Thinking to add this project on https://www.hackster.io/home-assistant as a work in progress, could be better to present overall progress than in a forum thread?

I was thinking this has become a blog, more than anything.

how is the actual implementation?

how? Interested in doing this as well

Will start a post on the Hackster channel for my progress :slight_smile:

Still working on this once Ive ironed out a few kinks I will post an updated script, its been a couple of hectic weeks here so I havent spent as much time as i liked completing the code.

OK so it is super easy to send the image via MQTT (https://home-assistant.io/components/camera.mqtt/):

1 Like

For voice? https://www.raspberrypi.org/magpi/google-aiy-voice-magpi-57/

1 Like

Just to let you know , I havent abandoned this project , I have a dabble every moment I have to spare but I seem to be hitting obstacles with almost every implementation of code.
As it stands now I have it running as a doorbell/camera, which polls for face detection (not recognition), when it detects a face at the front door it then sends a photo to my phone via telegram (via home assistant) , It does the same thing when someone presses the doorbell (without the face detection).
It is still buggy , crashes every now and then.
The doorbell button wired into the GPIO still, I havent found any 433rf input modules which work for python 2. I did try to get a few to work with future, but either I havent got a grips to how it works or Im not doing it right so still a work in progress. Ill keep you posted , but things still hectic at the moment, trying to sell the house and helping our daughter settle in , new job, it all seems to be happening at once, lol.

Sound very busy! Also the project sounds pretty complete? OpenCV just made it into HA so il look at having a HASS instance on my pi zero and running it in master-slave config. Currently writing up my progress on Hackster

When it is running , its great. But it will randomly crash with a conflict error, I havent had much time to pursue that side of it, Ive got my piannouncer running on the zero which is tied in with owntracks and home assistant, So when i arrive home it greets me. Unfortunately this is where I think the conflict is, so I might run the announcer on my PI (running home assistant), the only thing is I can barley hear it from the front door as I walk in, as the pi is in the office at the back of our house.

Nice! With the new Hassbian it should be possible to have multiple zero/hass instances dotted about, and could hook up to speakers in convenient locations

Posted my progress on https://www.hackster.io/robin-cole/pi-camera-doorbell-with-notifications-408d3d

4 Likes