Who’s That? What’s That? CCTV setup

Hello Hello again.   Recently I was chiming in on a thread on reddit regarding CCTV.  I mentioned how my cameras/cctv is setup.  Then I thought.

light-bulb-momentHey, you know would like to know this?

EVERYONE!!!!

 

 

Really.  Conversation totally happened in my head.  Told you Doctors it’s not too crowded up there.

Let’s begin!!

This all really started because of my 3dprinter…..

“How…. Huh…. But you…..”  I hear you saying it.  It makes no sense.  But Ill fix that little red wagon.

Aerial_Vista_Security_Camera_preview_featuredI love searching around on thingiverse.com it’s actually part of my daily sites to check.   So I came across this thing.   It’s a security enclosure for a raspberry pi and pi camera… WHAT?!?!?!

I know.  I thought the same thing.  I need that…..   So I started printing the parts.

2016-03-18 07.09.022016-03-18 07.48.26

Once I had it printed, I threw in my pi camera (NOIR).  The NOIR made it even better for being a security camera.  Ok, so cool.  How about software?

I was looking for some super simple camera software as there are tons of “security” camera projects out there for the pi.  I came across this one “MotionEyeOS.”   58732063Being built off the program Motion I decided to get in and test it out.  Flash the SD card and boot it up, gets an IP.   I just checked my dhcp leases on the router to find the ip, then gave it a static IP.

 

Once you have the IP just throw that ish in the browser!!  Configure your network settings ect.  But in the expert settings there is a switch.  Turn it on.

 

No seriously.  Turn it on.

2016-06-16 15_38_25-iseeall.noip.me - Remote Desktop Connection Manager v2.7

Yes I know.  The fast network camera page on the wiki looks like it kills alot of stuff.

 

The Differences

When you have Fast Network Camera enabled, you’ll notice that:

  • your motionEyeOS-based camera can reach a significantly higher frame rate, at a higher resolution
  • you can tweak many CSI camera-specific parameters directly from the UI
  • your browser will eat up less CPU at the same frame rate/resolution (it uses a pure MJPEG stream, rather than triggering every refresh from JavaScript)

On the other hand, this doesn’t come without some disadvantages:

  • no more motion detection
  • no more motion notifications
  • no more pictures or movies
  • no more overlaid text (date/time, camera name)
  • a significantly higher network bandwidth usage
  • you’ll need to forward port 8081 as well, if you want to access your camera from the Internet

 

No motion detection!?!?!   Are you crazy that’s why I am even reading this stupid page!!!!!!

 

EcstaticTightBuckeyebutterfly-size_restrictedCalm down.   Please calm down.  Can you even use that as a weapon?!?!   

Just let me finish before you use that thing!!!

So you enable fast network camera.  This lets you get some faster higher quality out of the camera.  Now here is the fun part.

I setup a VM of ubuntu and installed MotionEye.  Not MotionEyeOS but MotionEye.

BeQZIS7CEAAemgwOnce you have it running hit your motioneye server (http://<motioneyeserverip:8765)  and you will get another nice web interface.

In here, you will add a new camera, and set it up to point to your raspberry pi camera.

camsettingNow what is really cool here is you can setup a few cameras.  When I first set it up, I had 1 camera and then I found 9 traffic cameras and marina cams and what not from places all over the world and was able to plug them in.  Truly felt like a super villain being able to see everything!

Now that you have your cameras in motioneye we can now use the motion eye server to handle our motion detection.  See, I told you I would get there.

There are some cool setting here that you can do.  For example:

settings1

settings2

 

 

 

 

 

 

  • I have my video streaming setup so I can embed individual streams if I want into a web page, maybe a security camera sitemap page in openhab?
  • I have still images setup and capture when motion is detected.
  • I have Motion Detection configured that more than 5% of the frame has to change.
  • Then the fun part in Motion Notifications

I have a script configured on motion detection.


/usr/bin/notifycam.sh %t


This script is very simple.  It has 2 lines currently.  I honestly could knock it down to one.   Or I could add some additional code to handle different items for each camera.  The %t just passes in the camera ID.
57448311Ill go over that in a minute…. I SAID IN A MINUTE!!!!!!

On my Kodi media system in my office I installed this great add in called

Security Camera Overlay

It’s a very interesting add in.  You configure it for your security camera.  Well, I have mine connected to motioneye.

2016-06-16 20_46_26-ubuntudev1In MotionEye if you click on the Streaming Video there is a link in there called “Snapshot URL”

2016-06-16 20_48_34-KodiGrab that, you will need it to configure your Kodi system.

Put that snapshot URL in the Image URL field when configuring your add on.

 

 

 

 

2016-06-16 20_48_22-KodiOn the Behaviors tab, if your camera supports 16×9 I definitely recommend changing the Window width/height.  I have it refresh every half second and auto close after 4 seconds.

 

 

2016-06-16 20_37_41-KodiSo what does this look like?  LIKE THIS FOOL!!!!

It pops up right over Bob’s Burgers!!! refreshes a few times, let’s me see what’s going on and slides right back off.

 

Back to the script


/usr/bin/curl -g "http://xx.xx.xx.xx:8080/jsonrpc?request={%22jsonrpc%22:%222.0%22,%22method%22:%22Addons.ExecuteAddon%22,%22params%22:{%22addonid%22:%22script.securitycam%22},%22id%22:%221%22})"
/usr/bin/curl --header "Content-Type: text/plain" --request POST --data "ON" http://xx.xx.xx.xx:8080/rest/items/PorchMotionDetected

Explanation:

Line1: sends a json packet to my Kodi install in my office telling activating the great addon Security Camera Overlay.  This makes it slide over whatever you are watching.

Line2: sends a “motion detected” packet to openhab.  In my openhab Items file there is a simple switch I can add all my rules around.

downloadIn writing this I learned something today.  I am going to make a couple modifications in the future.

The notifycam.sh file will be adjusted down to 1 line.

It will just make the call to openhab.

But it will look something like

<pre>/usr/bin/curl --header "Content-Type: text/plain" --request POST --data "ON" http://xx.xx.xx.xx:8080/rest/items/CameraMotion%1

That way I don’t have to recode the script when I add a camera. I just need to add a new item CameraMotion<ID> to openhab.

Then I can add all the camera’s to a gSecurityCam group and build some rules around state change in that group. Then openhab can send out the notifcations to pop up the stuff on my kodi and any other kodi system I wish, as well as send me notices through other openhab notifcations.

I hope this was long enough for you…

 

 

OpenHab Wall Switch

So recently I started thinking about my HA system when I have guests.  I have a small house (not a tiny house) just a small house.  When my parents visit they setup camp in the living room.

vYtvpWpWorking on getting PIR motion sensors to turn things on and off.  But with guests, I need a guest mode to disable the motion sensor…. and not because I tend to dance in front of the motion sensors.

 

 

89b1c00006954836a703dfc0457c8626But with the motion sensors disabled.  There still needs to be a way for the folks to control the lights.  So I started thinking.

What I came up with was physical buttons, pass something to mqtt, then to openhab.  Openhab rule to control “group” of lights aka living room.

So time to start proto typing some things.  First I wanted to see if I could somehow make it work without putting holes in the wall.   WAF = 10 on that one.

2016-06-12 17.31.52So I started by 3d printing a light switch blank panel.  It’s a rough print, but needed to see if I could make it deep enough to put some triple A batteries to run it.

Once I tested some depth I was happy.

Frank-GrimesNext to build build some electronics.

 

So I broke out the good old arduino uno.  This is my go to for initial builds even though I usually end up with a pro mini in the end.  The uno is a great test bed.

So it started out with Uno + Ethernet Sheild + 2 buttons.

2016-06-12 12.53.39-2

 

I ended up adding just a notifcation LED just so I know once it’s connected to MQTT since I am not watching via serial monitor now.   2016-06-12 17.34.42So what does this get us now?  Well.  It boots up.  You press one button, all the lights in the living room turn on.  Press the other and they turn off.  I know what you’re thinking.  So what?

One of the lights is a phillip hue light.  The other is controlled via z-wave.  So how did I do this.  Lets start with the item definitions in openhab.

//Group Definition
Group gLivingRoomLights

//Items
Switch Switch_LivingRoomStandingLight "Living Room Light"     <light> (gLivingRoomLights,gDashboard) { zwave="2:command=switch_binary" }
Switch LivingRoomTableLight   "Living bulb" (gLivingRoomLights,Switching) {hue="1"}

//Dummy ITEM that is set via mqtt
Switch LivingRoomLights "Living Room Lights" {mqtt="<[mqtt:switches/livingroomlights:state:default]"}

So in my items file, I have the 2 light items and a dummy switch.  Notice the 2 light items are in the “gLivingRoomLights” group.  This is important.

Now for the rules.


rule "Living Room Lights"

when
Item LivingRoomLights changed
then
if(LivingRoomLights.state==ON)
{
gLivingRoomLights.sendCommand(ON)
logInfo("All Living Room Lights","ON")
}
else
{
logInfo("All Living Room Lights","OFF")
gLivingRoomLights.sendCommand(OFF)
//off
}
end

So this rule is triggered when the Dummy Switch (LivingRoomLights) changes.  If the state was changed to ON then i send the “ON” command to the entire group.  Same for when I turn it off.  So to test it I used mqtt-spy and manually did it.  All is working.

k16232506

What’s next is I am going to work on shrinking said project down to using an arduino pro mini, 2 AAA batteries.  For the network transmission I am back and forth between 2 options.

  1.  esp8266 – using the esp is great, but it’s not very forgiving on power.   I know there are deep sleep modes, but they aren’t really good for what I need with multiple buttons.
  2. nrf24l01 – RF modules.  These little suckers are really easy on the power.  If I use these I have to build a rf->ethernet bridge.  But with these I think the power consumption is much simpler.

Either option I go with, I can use a pro mini and have 2 interrupts I can attach to buttons.

Down the road if I need more buttons, I can use a pro micro and get something like 14 interrupts and still be able to use deep sleep.

iphone-battery-iconIf I wanted to cut holes in the wall and run cable I wouldn’t be as concerned with the battery levels.

 

 

 

Want to see it being tested?