|
Post by papa on Mar 2, 2018 14:01:50 GMT
I had a Raspberry Pi 2 B running Raspbia via NOOBS & to it, I recently added a Raspberry Pi NoIR Camera V2. With these devices, my son & I set up Motion, (a Linux motion detection software). While I continue to make tweaks, I now have a modest motion-detecting security camera that shows a video stream on the OpenHAB User Interface. I had tried another installation, but my son started us using this Pi SecurityCam blog that was helpful & I believe is mostly complete. I made some additions & explanatory notes for the blog that I will list below.
If I do not mention something in the blog, then that probably worked as is for us. Note: I have OpenHAB 2 running via openhabian on a Raspberry Pi 3 B. Continues ...
|
|
|
Post by papa on Mar 2, 2018 14:05:05 GMT
Papa's Additions & Explanatory Notes for the Pi SecurityCam blog. (mostly following the blog's sequence) My parts list was similar to the blog, except:
Raspberry Pi 2 B running Raspbian via NOOBS (may use Pi Zero next time) Ethernet Cable connection (plan to use WiFi later) No Camera mount (I plan to aim & stabilize the camera on the Pi's case) No special Pi Zero camera cable needed Continues ...
|
|
|
Post by papa on Mar 2, 2018 14:14:52 GMT
Papa's Additions & Explanatory Notes for This Pi SecurityCam blog. (mostly following the blog's sequence) Installing Motion ... A note at the end of the blog says, "If you are using Raspian Stretch then use the pi_stretch_motion_4.0.1-1_armhf.deb file when installing Motion. If you are using Raspian Jessie then use the pi_jessie_motion_4.0.1-1_armhf.deb file." Configuring the Pi ... After update Raspian Jessie commands, I also recommend the command: sudo rpi-update I used the blog's recommended configuration entries (which worked), but I made other changes (listed in later posts). In order for changes in configuration files to take effect, one may need to reboot after the configuration changes. Continues ...
|
|
|
Post by papa on Mar 2, 2018 14:21:38 GMT
Papa's Additions & Explanatory Notes for This Pi SecurityCam Blog. (mostly following the blog's sequence) "Running Motion for the First Time" Blog: "While Motion starts up, watch for any error messages." papa: When Motion is started this way, one can watch whether it is successful or throws errors to correct. Started this way, Motion will stop when the Pi is rebooted. Later (after Motion runs successfully) the blog instructs us on starting Motion at the Pi's booting up. Blog: "Note that Motion occasionally fails to start up due to previous Motion processes that have failed to shut down properly and are running in the background." papa: Also only one program can access the camera. Stop & disable any camera software other than Motion or Motion will not complete its startup. Continues ...
|
|
|
Post by papa on Mar 2, 2018 14:36:21 GMT
Papa's Additions & Explanatory Notes for This Pi SecurityCam Blog. (mostly following the blog's sequence)Blog: " View the video stream with http://[IPaddress]:[stream_port]" papa: This means if the Pi's IP is 192.168.1.131 & motion.conf has the default setting of stream_port 8081, then see the Pi Motion video stream with 192.168.1.131:8081 Also if motion.conf has the default setting of webcontrol_port 8080, then access Motion's control panel with 192.168.1.131:8080The motion.conf setting of "text_changes on" shows the number of changed pixels (upper right corner of the video stream or saved images). Watch the video stream with activity going on in the camera's view. In the upper right, notice the number of pixels changing. This number can help you tweak the threshold setting to help avoid false positives. View the saved .jpg images in the target_dir which the blog sets to be /home/pi/Documents/motion. Again the upper right shows the number of changed pixels. Also a red box shows the vicinity of the the changed pixels. Continues ...
|
|
|
Post by papa on Mar 2, 2018 14:53:38 GMT
Papa's Additions & Explanatory Notes for This Pi SecurityCam Blog. (mostly following the blog's sequence)
The blog's Email Alerts setups worked for me. Motion now emails me images when motion is detected. Removing Old Files of Saved ImagesAlthough Motion's saved images are less than 40kb, there are many of them, even when tweaks reduce false positives (later post). So one must decide a balance of how far back one wants to be able review saved images & a system of removing old files so they don't fill the storage. I approached removing old files a little differently than the blog referenced: sudo nano /etc/crontab To crontab, add something like the following lines & save the edited crontab file: # find camera pic files more than 3 days ago & delete (-mtime counts 24 hour periods) @daily root find /home/pi/Documents/motion -type f -mtime +2 -delete Note: The above crontab edits seem to run once a day in early morning (6:xx am ??) & have been working to remove old files as desired. Continues ...
|
|
|
Post by papa on Mar 2, 2018 15:17:36 GMT
Papa's Additions & Explanatory Notes for This Pi SecurityCam Blog. (mostly following the blog's sequence)Blog: "On some days I received 50 alert emails due to these false positives, which tended to undermine the usefulness of the camera. Motion allows you to tweak the amount of pixels needed to trigger an alert, but then you risk making the camera less effective." papa: I found that tweaks do reduce false positives (emails & saved images) & yet the system seemed to detect more than enough motion. One should be careful how far the tweaks are taken. Additional tweaks I made in motion.conf settings to avoid false positives:# Ignore sudden massive light intensity changes given as a percentage of the picture # default was 0 = disabled lightswitch 35 # Threshold for number of changed pixels in an image that # triggers motion detection (default: 1500) threshold 4000 # Noise threshold for the motion detection (default: 32) noise_level 100 Continues ...
|
|
|
Post by papa on Mar 2, 2018 15:23:45 GMT
Papa's Additions & Explanatory Notes for This Pi SecurityCam Blog. (mostly following the blog's sequence) More tweaks for motion.conf based on this later chapter of the Blog:I may change minimum_motion_frames from 1 to 2. This means that two frames of movement need to be detected before a motion event is triggered. I set text_double to on. This doubles the size of the text displayed on the image. I set text_left to GarageCam to identify my camera. ------------------------------ I also set rotate to 180 to rotate the image 180 degrees (my camera is upside down for the time being). Continues ...
|
|
|
Post by papa on Mar 2, 2018 15:29:28 GMT
Papa's Additions & Explanatory Notes for This Pi SecurityCam Blog.One will probably need to experiment with placement & aim of the Raspberry Pi & camera. Place them close enough to a power outlet & to view a key area. Perhaps avoid nearby areas that regularly change (like TV screens), but are not worthy of recording. Now that I have this working, I will save an image of the Pi's SD memory card to restore a card that may get corrupted later or perhaps to clone & tweak for another Pi Security Cam. Instructions for saving the image are at this site. Continues ...
|
|
|
Post by papa on Mar 2, 2018 15:30:12 GMT
Papa's Additions & Explanatory Notes for This Pi SecurityCam Blog. To display the Motion video stream on the OpenHAB User Interface:To your OpenHAB .sitemap configuration file, add a section something like this (using the IP address of the Pi that hosts Motion & your camera) ... // shows link to new page Text label="Security Cams via Motion" icon="video" { Frame label="GarageCam" { // for pi camera & Motion software Image url="http:// 192.168.1.131:8081" refresh=5000 } } ======================== On your main user interface page, this .sitemap section will display a link, which if clicked will go to a new page that displays the Motion video steam. I assume that you are connected to the OpenHAB cloud so you can see the OpenHAB user interface on a computer or mobile device wherever you are. If Motion sends you an email that motion is detected, you can then use this User Interface feature to double check what is going on. I suppose inside the outer curly brackets { }, we could add frames of other Pi Cams & have a whole page of security footage ... // shows link to new page Text label="Security Cams via Motion" icon="video" { Frame label=" GarageCam" { // for pi camera & Motion software Image url="http://192.168.1. 131:8081" refresh=5000 } Frame label=" FrontDoorCam" { // for pi camera & Motion software Image url="http://192.168.1. 135:8081" refresh=5000 } }Enjoy.
|
|
|
Post by papa on Mar 2, 2018 20:00:37 GMT
Papa's Additions & Explanatory Notes for This Pi SecurityCam Blog
Above I wrote: "Also if motion.conf has the default setting of webcontrol_port 8080, then access Motion's control panel with 192.168.1.131:8080
However, without another change to motion.conf, the webcontrol port will not list or allow changes to configuration settings. As follows, I changed webcontrol-parms 0 to webcontrol-parms 1, which I believe (after rebooting) will allow webcontrol to list parameters that can be changed without rebooting.
# Parameters to include on webcontrol. 0=none, 1=limited, 2=advanced, 3=restricted # Default: 0 (none) webcontrol_parms 1
Continues ...
|
|
|
Post by papa on Mar 2, 2018 20:19:10 GMT
Papa's Additions & Explanatory Notes for This Pi SecurityCam Blog Use Motion's webcontrol to change limited parameters on the fly without rebooting.At http://[Pi IP]:8080/0/config/ get then output_pictures in the drop down list, one can "get" the current value of the that parameter AND options for it: output_pictures = on Output 'normal' pictures when motion is detected (default: on) Valid values: on, off, first, best, centerWhen set to 'first', only the first picture of an event is saved. Picture with most motion of an event is saved when set to 'best'. Picture with motion nearest center of picture is saved when set to 'center'. Can be used as preview shot for the corresponding movie. At http://[Pi IP]:8080/0/config/ set then output_pictures in the drop down list, one can enter a new value from the options listed above. To turn off saving motion-detection pictures & emails (but the video stream continues), I temporarily changed that parameter to: output_pictures = off To restart output_pictures, set the parameter to on. This does not change the motion.conf file which would restore its versions of parameters upon rebooting. At http://[Pi IP]:8080/0/config/ write, one can save the webcontrol-changed parameters within the motion.conf file that will be used upon rebooting Note the output_pictures options above by which we might tweak Motion's operation.
|
|
|
Post by papa on Mar 2, 2018 20:51:57 GMT
Papa's Additions & Explanatory Notes for This Pi SecurityCam Blog Using the API for HTTP Interface for Motion to Check & Change Configs:For changing several Motion configs, we can use the Motion webcontrol user interface, as in the last post. Or we can use the API to change configs ... I got hints from this site that is cryptic & could have used some examples. If the computer hosting Motion has an IP address of 192.168.1.131, then ... http:// 192.168.1.131:8080/0/config/ get?query=output_pictures gets the current value of output_pictures & options for this config. http:// 192.168.1.131:8080/0/config/ set?output_pictures= off turns off output_pictures & email alerts until reboot unless the API writes the change into motion.conf. http:// 192.168.1.131:8080/0/config/ set?output_pictures= on turns on output_pictures & email alerts until reboot unless the API writes the change into motion.conf. http:// 192.168.1.131:8080/0/config/ write After an " Are you sure?" confirmation, this saves the latest config changes to motion.conf so a reboot will not revert to old settings. http:// 192.168.1.131:8080/0/config/ writeyes With no "Are you sure?" confirmation, this saves latest config changes to motion.conf so a reboot will not revert to old settings.
|
|
|
Post by papa on Mar 3, 2018 0:55:25 GMT
|
|
|
Post by papa on Mar 3, 2018 4:42:11 GMT
|
|
|
Post by papa on Mar 3, 2018 15:39:21 GMT
I was close to an OpenHAb item that would change Motion's output_pictures setting: ^^ This threw no log errors, but did not actually change the setting. I got help from Flole at community.openhab.org who told me to use a GET request instead of POST in the http binding. So after changing from POST to GET, this item works great to switch the output_pictures setting: Simple solution. GET did not seem logical for a command to change a setting. Using GET instead of POST in http bindings could apply to other situations. It's also good to know that one can transfer a browser string as is to an OpenHAB http binding.
|
|
|
Post by papa on Mar 3, 2018 16:01:20 GMT
Changing Motion's output_pictures setting via OpenHAB's User Interface:
If the computer hosting Motion has an IP address of 192.168.1.131, then ...
For your situation, adapt an entry in your xxx.items file similar to Switch GarageCamOutput { http=">[ON:GET:http://192.168.1.131:8080/0/config/set?output_pictures=on] >[OFF:GET:http://192.168.1.131:8080/0/config/set?output_pictures=off]" }
For your situation, adapt an entry in your xxx.sitemap file similar to Switch item=GarageCamOutput
When you click the switch on OpenHAB's User Interface, Motion's output_pictures setting will switch to the opposite state. Unless written to the motion.conf file, this setting will revert to the unchanged motion.conf value at reboot.
So the User Interface switch can be used to activate or cancel saving motion-detection images (& email alerts) while the video stream continues.
This approach to changing Motion settings could apply to other settings in Motion's "limited" list, an actually long list of settings that can be changed on the fly without needing a reboot.
|
|
|
Post by papa on Mar 3, 2018 19:14:31 GMT
Changing Motion's output_pictures setting via OpenHAB's User Interface (This other approach via rules mostly replaces the approach in the last post):
If the computer hosting Motion has an IP address of 192.168.1.131, then ...
For your situation, adapt an xxx.items file entry similar to this (no HTTP binding): Switch GarageCamOutput
For your situation, adapt xxx.rules file entries similar to these:
For your situation, adapt an xxx.sitemap file entry similar to Switch item=GarageCamOutput
When you click the switch on OpenHAB's User Interface, Motion's output_pictures setting will switch to the opposite state. Unless written to the motion.conf file, this setting will revert to the unchanged motion.conf value at reboot.
So the User Interface switch can be used to activate or cancel saving motion-detection images (& email alerts) while the video stream continues.
This approach to changing Motion settings could apply to other settings in Motion's "limited" list, an actually long list of settings that can be changed on the fly without needing a reboot.
Note: Perhaps use the last post's item approach when you are toggling motion-detection on one device. Perhaps the sendHttpGetRequest() command in a rule could be part of arming/disarming more than one security device by clicking one User Interface switch.
|
|
|
Post by papa on Mar 5, 2018 13:40:32 GMT
Display 4 Motion Cameras on OpenHAB's User Interface (Resizable via a Slider) Camera_feed_4 _pub.html (2.11 KB) << Download this .html file. Near the end, the 4 camera IP address are all the same. Edit the IP addresses to be the IP addresses of your one to four Motion-controlled cameras. ( This site provided the .html file.) On the computer hosting Motion, save the edited .html file in the /html folder nested in OpenHAB 2's config folder (/etc/openhab2/html for an apt-get install of OpenHAB2). You may rename the file, but use the new name consistently with the following instructions Continues ...
|
|
|
Post by papa on Mar 5, 2018 15:36:12 GMT
Display 4 Motion Cameras on OpenHAB's User Interface (Resizable via a Slider)The following is an edit of .sitemap entries from this post above: New text is in this bright blue.
Replace the IP address & hostname with that of your Pi that hosts Motion & a camera. For me, the host name (openhabianpi) worked for me, but not the 192.168.1.131 IP. Note that one port is 8080 & the other is 8081 In your local network router, remember to give the PI a static IP address. // shows link to new page Text label="Security Cams via Motion" icon="video" { // null Frame label raises the rest of the page Frame label= "" { // UNcomment for pi camera & Motion software // Image url="http:// 192.168.1.131:8081" refresh=5000 // UNcomment for 4 Motion Camera Feeds (resizable) Webview url="http://openhabianpi:8080/static/Camera_feed_4 _pub.html" height=20 } } ================== Note: Apparently OpenHAB 2 knows that the /static folder is the /html folder nested in OpenHAB2's configuration folder. Note 2: In each Pi's motion.conf, use the text_left value to identify each camera at the lower left corner of the video feed.
|
|
|
Post by anthonyws on Jul 12, 2018 19:31:46 GMT
Hi papa, great thread. I have a USB webcam, can this be used instead of the Raspberry Pi NoIR Camera V2
thanks
|
|
|
Post by papa on Jul 13, 2018 12:50:41 GMT
Yes, I believe you can. I have not tried that. Setting up the camera with the Pi software may be a little different. Online, I believe I've seen that people have used USB cameras similarly. The picture quality & other performance may not be as good as with the Pi camera.
|
|