[Tasker Tips & Tricks] slipsystem:
LINUX

Notify Me When Detecting Movement In My House

Overview

We will use simplecv as a security camera to detect motion in our house. it will then send a notification to our phone alerting us that someone is inside.

Requirements

SimpleCV

WebCam or IP Camera

Tasker

Autoremote

Setup

Install SimpleCV

Thanks To Tinkernut for this tutorial

Open Terminal and Type

sudo apt-get update
sudo apt-get install ipython python-opencv python-scipy python-numpy python-setuptools
sudo pip install https://github.com/sightmachine/SimpleCV/zipball/master
sudo pip install pyparsing svgwrite
simplecv

Setting Up The Script

Make a new python file called camera.py

sudo nano camera.py

and paste this code

'''THIS IS A MOTION DETECTING PROGRAM FOR THE RASPBERRY PI
It is part of a tutorial series that you can find here:
https://www.youtube.com/playlist?list=PLlg8lN4r9qWiDzF13lJY-lGtiTFHHGcpx
Running this program requires installing SimpleCV as well as
a few other prerequisits on your pi. You can find detailed
instructions for how to do that here:
http://tinkernut.com/YtQH9
The script was slightly modified by slipsystem to send a autoremote command
'''

#!/usr/bin/python

#import the SimpleCV, shutil and urllib libraries
from SimpleCV import *
import shutil
import urllib

#set autoremote variables
#key taken from http://goo.gl/xxxxx
autoremotekey = ""
#message to send autoremote
autoremotemessage = "Motion Detected"
#initialize the camera
cam = Camera()
#set the max display size
display = Display((800,600))

#create a threshold variable to change motion sensitivity
threshold = 0.5

#get the date for saving images
datestr = time.strftime("%Y%m%d")
#set a streaming variable to stream webcam online
streaming = JpegStreamer("0.0.0.0:1212")

#create destination directorie for the pictures
dst = "pic/%s" % (datestr) #destination directory for images

#if the picture directories don't exist, create them
if not os.path.exists(dst):
os.makedirs(dst)

#create a loop that constantly grabs new images from the webcam
while True:
#set a time variable that updates with the loop
current_time = time.time()
#grab an image still from the camera and convert it to grayscale
img01 = cam.getImage().toGray()
#wait half a second
time.sleep(0.05)
#grab an unedited still to use as our original image
original = cam.getImage()
#set webcam image
original.save(streaming)
#grab another image still from the camera and conver it to grayscale
img02 = cam.getImage().toGray()
#subract the images from each other, binarize and inver the colors
diff = (img01 - img02).binarize(50).invert()

#dump all the values into a Numpy matrix and extract the mean avg
matrix = diff.getNumpy()
mean = matrix.mean()

#find and highlight the objects within the image
blobs = diff.findBlobs()

#if the mean is greater than our threshold variable, then look for objects
if mean >= threshold:

#check to see if any objects were detected
if blobs:
#find the central point of each object
#and draw a red circle around it
for b in blobs:
try:
loc = (b.x,b.y) #locates center of object
original.drawCircle(loc,b.radius(),Color.RED,2)
except:
e = sys.exc_info()[0]
#use the current date to create a unique file name
timestr = time.strftime("%H%M%S")

#initialize the counter variable
i = 1

#check to see if the filename already exists
while os.path.exists("pic/motion%s-%s.png" % (timestr, i)):
#if it does, add one to the filename and try again
i += 1
#once a unique filename has been found, save the image
original.save(dst + "/motion%s-%s.png" % (timestr, i))
#print results to terminal
print("Motion Detected")
f = urllib.urlopen("https://autoremotejoaomgcd.appspot.com/sendmessage?key=" + autoremotekey + "&message=" + autoremotemessage)
print("Message Send " + f.read())

open autoremote and follow your link (goo.gl/xxxx)

once you have opened the link you will notice the url say something like key=xxxxx

paste the key inside autoremotekey = ""

save the script by typing ctrl+x

run the python script by typing

python camera.py

now your camera server should be running ,if you move in front of the camera you should see a output of motion detected

Create The Task

The Task can be whatever you want to run when the camera detects motion in my case I have it play your dongeon is under attack then open the camera viewer. but for the purpose of this tutorial we are going to make it just open the camera.

Open Tasker

Press the TASKS Tab

Press The +

Give The Task A Name Like Camera

Press The +

Click Net

Click Browse URL

Enter the Ip address of your computer(ifconfig) followed by :1212 (192.168.1.12:1212)

Press the back button to save

Press the +

Press Task

Press Wait

adjust the slider to one minute so we don’t get bombarded with messages

press back twice to save configuration and task

Create The Profile

Press the profiles tab

Press the + Button to add a new profile

Select State

Select Plugin

Select Autoremote

Press the Configuration pencil

Check Event Behavior

Message Filter type Motion Detected

press back twice to save

click the newly created task