Introduction: Who's at the Door, an Alexa Actuated Camera System
Sometimes while watching TV you don't want to answer the door unless it is important. This project allows you to view the person at the door by simply telling Amazon's Echo device "Alexa, turn on the door monitor". You check out who appears on the TV screen, then back to normal TV programming "Alexa, turn on the TV". The system could also be of value to older adults or children that would be vulnerable to being taken advantage of by salespersons, thieves, and the like. This allows the large screen TV of your entertainment system to be the camera display monitor for not only the front door camera, but for any other security cameras you might have; in fact it could even be extended to display video from internet cameras, like beach cams, etc.
Parts:
Entertainment system :
TV with several HDMI inputs (most TV sets have them)
Cable or DVR box
Router and internet connection via cable box (might not be needed if you have WiFi)
Amazon Echo ("Alexa")
Harmony Hub
Camera(s)
IP camera at front door (Power Over Ethernet -POE- type preferred)
Raspberry Pi3 in a project box (original Pi may work) with HDMI cable
Arduino Pro Mini 8 Mhz, 3.3v
IR module (most common types will work)
Step 1: Setup, Preliminary Programming (testing)
This project relies on the Pi3 omxplayer which decodes video with hardware acceleration. Omxplayer can be test run from a command line in the Pi terminal using the appropriate rtsp://user@password@ipaddress format that your camera requires. The Pi should be connected to Ethernet (though Pi3 could be connected via WiFi too, but not tested) and physically located at the entertainment center so the Pi's HDMI output cable can reach the TV HDMI input jack. The Arduino and IR module will connect to the Pi, and relay the information gained from reading the TV remote control button presses. The Pi could do this decoding directly from the IR module, but I am better at Arduino programming than Python programming and besides it saves processor resources for the Pi's main task of decoding the video stream(s).
Since my security system has multiple cameras, I used the Pi powered monitoring display as a way to display 4 cameras at once, plus display individual cameras full screen. Follow those instructions, however you will probably have lots of problems getting the cameras to display in a stable manner.
One of the problems is that the 4 window sizes listed in the program may not fit your particular TV resolution. Find what resolutions your monitor supports while noting the camera resolution your cameras have. Most IP cameras have a high resolution (1080p) and a low resolution (640x480) stream, so if you just want one high resolution video of the front door, go with the high resolution stream rtsp:// format. Go with the low resolution stream for cameras in 4 quadrants, you won't notice much difference with the smaller picture sizes. You can go with my bash script (test.sh) window sizes (in 1080p resolution mode, displaying 4 equal sized 640x480 cameras scaled to fit). Otherwise, use graph paper to layout your TV pixels then sketch in how many rectangles you want in that area. Next find how many 640x480 videos will fit without too much aspect changing (stretching horizontally looks better than vertically). I don't like borders, so didn't calculate for them. Number the rectangles from top left to lower right 1, 2, 3..etc. Then make a column of window numbers, for each row of those numbers write down the upper left x,y pixel and lower right pixel x,y. Those numbers are then substituted into the script to get a custom display, you could have a 3 x 3 display if desired. If you only want one display, just comment out the other 3 cameras and make the window size the full screen resolution (and use the high resolution rtsp stream) and title the script "test1.sh". Make as many scripts as you want, the btn.py Python program will call them up as the GPIO pins get changed by the Arduino.
One problem in getting a stable display (top of image fine, but lower image vertical streaks) is that many cameras stream much better using rtsp over tcp (I use Hikvision 2 to 5 Mp IP cameras). Therefore, use "--avdict rtsp_transport:tcp" in omxplayer as shown. Other useful omxplayer commands are volume (--vol -6000 for mute) and buffer (--video queue x) where x=1 or more.
IP camera settings can also cause problems with omxplayer. All the IP cameras should be set to the same frames per second or the picture will break up. When set to radically different frame rates, time displayed on one camera time stamp actually went backward for a few seconds, then forward then back etc.. Be sure your omxplayer windows don't overlap, or the overlapping part will flicker.
Step 2: Putting It Together
You could manually control the cable box and TV to allow the Pi to show the front door camera. However, that requires quite a few button presses, including appropriate switching the universal remote from cable mode to TV mode to allow changing the HDMI input source to the Pi camera decoder (HDMI 2). If you want the ability to show additional camera screens, then you also have to switch the universal remote to AUX to control the Arduino and thus the Pi camera selection. To simplify this process, use a Harmony Hub and associated Harmony smartphone app, teaching it to control the TV and cable box for normal TV viewing in one Activity, then create another Activity to control the Pi video monitor. The Activity includes turning the TV on, the TV input to HDMI 2, and controlling the virtual NECx TV (ie., the Arduino and Pi) buttons 0 through 5. This allows controlling everything through the Harmony smartphone app. To make things even easier, link the Amazon Echo Dot (Alexa) app with the Harmony app to voice control the TV or door monitoring functions. The Harmony website provides details on how to enable these new Alexa skills. New skills . Once linked with new Alexa skills, keywords like "Turn On the TV" or "Turn on the Door Monitor" will enable the appropriate actions without needing IR from the universal remote.
The Pi is connected via Ethernet to your LAN, and via HDMI cable to the TV. I installed a 3.3 volt Pro Mini via wires to the Pi as an option to add additional camera switching. The Pro Mini can be powered from the 3.3 volt pin of the Pi. An IR module connects to pin 2 of the Arduino, and the attached sketch decodes the button press 0 to 5 (actually 0 to 9, but some Arduino pins aren't connected yet). The Arduino outputs connect to digital input GPIO pins of the Pi, where a bash script interrupt determines which "button" was pressed, then stops one display view option and starts another.
My cable box is from Spectrum (formerly Time Warner Cable), which is a Motorola DVR model DCX3510. It uses GI Cable protocol for IR. The Sony TV uses Sony protocol 2. I thought one or the other of those codes would be fine to control the Pi IR receiver and either did work, although it turned out not to be practical. The remote control would expect additional commands, or automatically change the input source as well when a button 0 to 9 was pressed. Therefore, I had to use a different code that wouldn't interact with the cable tuner or TV. I found my universal remote had a previously programmed code for an AUX device (don't know what it controlled) and decided to use it. The codes produced said it used NECx, a 32 bit code, so I entered those button codes into the Arduino IR_Rev_Codes_Pi_Monitor sketch. Change the program if you have the a different model by using the receive program in IRLib2 and note the maker, protocol and hex values for the buttons pressed.
Attachments
Step 3: Conclusion
The door monitor is practical home automation project. It was my first experience programming the Pi with Python. Python allows programming an interrupt, a feature I thought was reserved for microcontrollers. The interrupt allows the program to run normally, running omxplayer, without constantly checking if another action is required like changing the display to a new camera feed. However, if the interrupt occurs, the program then determines which new video feed should be brought up. The Arduino is set up to provide a pulse to trigger the Python interrupt. If the interrupt occurs, then the program searches for which particular Arduino output (corresponding to the IR remote button pressed) is activated. Finally, the program kills any current omxplayer display and starts the new omxplayer display.
I learned that the Pi does not set its GPIO pins to input like the Arduino does by default- not a fault of the Pi, but it is the way the Broadcom BCM2837 is from the factory. I do like the 4 core, 1.2 Ghz processor, a low power, low cost computer that can display great HD video. IR button 1 shows the quad display, and buttons 2 through 5 each show a single large display of a camera in High Definition.
Pressing IR remote button 0 cancels the video display and shows the Pi command line. If you want to watch Youtube videos or the like, use a Bluetooth keyboard, type "startx" and use the Pi browser to navigate to the Youtube video and play it full screen in High Definition.