I recently installed the open source iSpyConnect software for a surveillance camera and was put off to find that they wanted me to pay a subscription fee to get the version that emailed you when motion was detected. Kinda lame IMHO. I don’t mind paying for a “pro” version, but I really don’t like the subscription model for software (yes, I’m talking to you Adobe!).
Anyways, a quick Google search turned up this gem from a 2013 blog post. I don’t really know much about Windows PowerShell, but it’s similar to most scripting languages (DOS, VB, PERL, etc.), so it was fairly easy to do some minor tweaking to the original code to get it working on my system. After a few tests I got it going under Windows 8.1. It’s mostly the original code with a few modifications and updates. I have also found that for some unknown reason, this works more reliably if you call the Powershell script from a DOS batch file. There should be no difference, but this is my experience.
Here are the updated steps:
1. Open Notepad or your favorite text editor, enter the following Powershell code, and save it as c:\ispy\ispyalertmail.ps1
$date = get-date -format yyyy-MM-dd
$time = get-date -format H-mm-ss
$filename = $date+"_$time.jpg" #Define file name format. In my case, iSpy used: yyyy-MM-dd_H-mm-ss.jpg
$dir = "C:\Documents and Settings\Your_username\Application Data\iSpy\WebServerRoot\Media\video\FKJPK\grabs" #The filepath iSpy saves images to
$latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1 #Get the last created image
$filename = $latest.name
add-content c:\ispy\cam1log.txt "Motion detected at $date $time" #Create a log file
$file = $dir+"\$filename" #Define the email attachment file
$EmailFrom = "[email protected]" #Your from e-mail address
$EmailTo = "[email protected]" #The e-mail the alert message will be sent to
$Subject = "Camera alert" #Define a subject
$Body = "Something moved at $time , $date. Check the live view. Recording done." #Define email text body
$SMTPServer = "smtp.gmail.com" #The SMTP server your host is using. Here we have used Gmails
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$SMTPMessage.Attachments.Add($file) #Attach the latest image
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) #The SMTP server port. Here we have used Gmails
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“[email protected]”, “your super secure password”); #careful, your making your password visible to anyone who can access this script
$SMTPClient.Send($SMTPMessage) #Send the email
2. Create another text file and save it as c:\ispy\ispyalertmail.bat. Here’s the code:
powershell -ExecutionPolicy bypass -Command "c:\ispy\ispyalertmail.ps1"
3. Open the iSpy application. Right-click the camera image and choose Edit.
4. Click the Alerts tab
5. The When pop-up should already be set to Alert. That’s what we want.
6. On the Select Action pop-up, select Execute file and then click Add.
7. Click the … next to the File field and navigate to the batch file you created. It should be here c:\ispy\ispyalertmail.bat
8. Click OK.
10. Click the Finish button and you’re done.
11. When motion is detected and an alert is triggered, your Powershell script will be executed. You should see a DOS window flash open and close. If you get too many alerts, try adjusting the Movement seconds by clicking the … just to the left of where it says Plugins. I have mine set to 2 seconds, which means there has to be movement for two continuous seconds before a alert is triggered.
So far this is working swimmingly. Hope it works for you. Kudos to h311m4n for the original script. I couldn’t have done this without him.