Page 1 of 2
IP Camera motion detection
Posted: Wednesday 21 May 2014 13:11
by Mince Inside
I've had an Axis 221 since they 1st came out and remembered it has motion detection. Now, the options I have is FTP or HTTP that will put a snapshot in location X or TCP to send a message to and IP and port.
As a test I ran
on my pi and on my camera I set the message to be /json.htm?type=command¶m=switchlight&idx=57&switchcmd=Off&level=0, my Pi on the test port 8081 it came in 100%. Next I thought I'd try 8080 but it was a longshot and the sensor on IDX57 did not change.
What would the collective recommend to toggle my sensor? A script constantly listening on an arbitrary port to trigger the sensor to then grab a pic OR use the camera to upload the pic and have a script that waits for a pic to arrive and use that as a trigger?
I'm leaning towards the latter as the pic will be more likely to contain the 'trigger' ie no delay.
Thoughts?
TIA
M
Re: IP Camera motion detection
Posted: Saturday 07 June 2014 13:53
by safi78
If you don't mine diving into an extra piece of software, check out:
http://www.domoticz.com/wiki/Camera_Set ... ion_sensor
A page I wrote to use your ip-cams as a motion sensor and even saving the snapshots / camstreams as files without losing functionality in domoticz.
Works brilliantly for me
Re: IP Camera motion detection
Posted: Saturday 07 June 2014 18:58
by Mince Inside
Thank you - will have a look, my initial concern was the load on the raspi
Re: IP Camera motion detection
Posted: Sunday 23 November 2014 17:07
by Raspberry Piet
Don't have an Axis camera but a Foscam (FI8910W).
Found out how to command a dummy switch set as motion sensor in Domoticz by this Foscam camera when it detects motion.
Code: Select all
curl "http://192.168.1.24:8080/set_alarm.cgi?user=Username&pwd=SecretPassword&http=1&http_url=http://192.168.1.17:8080/json.htm?type=command%26param=switchlight%26idx=183%26switchcmd=On%26level=0"
You might change the ampersands to
%26 in the JSON url!
Set motion detection active:
Code: Select all
curl "http://192.168.1.24:8080/set_alarm.cgi?motion_armed=1&user=Username&pwd=SecretPassword"
Change motion sensitivity:
Code: Select all
curl "http://192.168.1.24:8080/set_alarm.cgi?motion_sensitivity=2&user=Username&pwd=SecretPassword"
Check if Foscam settings are ok:
http://192.168.1.24:8080/get_params.cgi
Edit: Just found out this was
already posted on this forum.
Forget about mine.
Re: IP Camera motion detection
Posted: Sunday 07 December 2014 19:03
by sincze
Raspberry Piet wrote:Don't have an Axis camera but a Foscam (FI8910W).
Found out how to command a dummy switch set as motion sensor in Domoticz by this Foscam camera when it detects motion.
Code: Select all
curl "http://192.168.1.24:8080/set_alarm.cgi?user=Username&pwd=SecretPassword&http=1&http_url=http://192.168.1.17:8080/json.htm?type=command%26param=switchlight%26idx=183%26switchcmd=On%26level=0"
You might change the ampersands to
%26 in the JSON url!
Edit: Just found out this was
already posted on this forum.
Forget about mine.
MMM, Unfortunately this is not supported anymore in the 9821W v1 / v2 devices.
I have to somehow parse the result from:
Code: Select all
http://<IP_OF_CAM:PORT/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=USERNAME&pwd=PASSWORD
Code: Select all
<CGI_Result>
<result>0</result>
<IOAlarm>0</IOAlarm>
<motionDetectAlarm>1</motionDetectAlarm>
<soundAlarm>0</soundAlarm>
<record>0</record>
<sdState>0</sdState>
<sdFreeSpace>0k</sdFreeSpace>
<sdTotalSpace>0k</sdTotalSpace>
<ntpState>2</ntpState>
<ddnsState>2</ddnsState>
<url>http://ba2210.myfoscam.org:30</url>
<upnpState>0</upnpState>
<isWifiConnected>0</isWifiConnected>
<wifiConnectedAP></wifiConnectedAP>
<infraLedState>1</infraLedState>
</CGI_Result>
The only interesting one is if:
<motionDetectAlarm>1</motionDetectAlarm> = 2
According to official FOSCAM documentation this means: Detect alarm
http://foscam.us/forum/cgi-sdk-for-hd-camera-t6045.html
Scripting Suggestions are welcome.
Re: IP Camera motion detection
Posted: Monday 18 May 2015 15:36
by Skorpion
sincze wrote:MMM, Unfortunately this is not supported anymore in the 9821W v1 / v2 devices.
I have to somehow parse the result from:
Code: Select all
http://<IP_OF_CAM:PORT/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=USERNAME&pwd=PASSWORD
Code: Select all
<CGI_Result>
<result>0</result>
<IOAlarm>0</IOAlarm>
<motionDetectAlarm>1</motionDetectAlarm>
<soundAlarm>0</soundAlarm>
<record>0</record>
<sdState>0</sdState>
<sdFreeSpace>0k</sdFreeSpace>
<sdTotalSpace>0k</sdTotalSpace>
<ntpState>2</ntpState>
<ddnsState>2</ddnsState>
<url>http://ba2210.myfoscam.org:30</url>
<upnpState>0</upnpState>
<isWifiConnected>0</isWifiConnected>
<wifiConnectedAP></wifiConnectedAP>
<infraLedState>1</infraLedState>
</CGI_Result>
The only interesting one is if:
<motionDetectAlarm>1</motionDetectAlarm> = 2
According to official FOSCAM documentation this means: Detect alarm
http://foscam.us/forum/cgi-sdk-for-hd-camera-t6045.html
Scripting Suggestions are welcome.
I wrote a script myself to switch a dummy switch in Domoticz when my Foscam FI9831P detects motion. I am not really a programmer so the code may be written a bit sloppy, but it works.
Code: Select all
#!/bin/bash
# Settings - Edit to your situation
FOSCAMIP="XXXXX" # FOSCAM IP Address
FOSCAM_PORT="88" # FOSCAM Port
DOMO_IP="XXXXX" # Domoticz IP Address
DOMO_PORT="8080" # Domoticz Port
FOSCAM_STATUS_IDX="XXXXX" # FOSCAM status IDX
#----------- End of settings -----------------
#Check if FOSCAM is on/online
if ping -c 1 $FOSCAMIP &> /dev/null
then
# If true, FOSCAM is on and the following code will be executed.
echo 'FOSCAM staat aan'
# Get data from status.txt and place text status.txt in new file named FOSCAM.txt
curl "http://$FOSCAMIP:$FOSCAM_PORT/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=YOURUSRNAMEHERE&pwd=YOURPASSWORDHERE" > Foscam.txt
# FOSCAM Status
FOSCAMStatus=`grep -oP '(?<=<motionDetectAlarm>).*(?=<\/motionDetectAlarm>)' Foscam.txt`
echo $FOSCAMStatus
if [[ $FOSCAMStatus = "0" ]] || [[ $FOSCAMStatus = "1" ]];
then
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=switchlight&idx=$FOSCAM_STATUS_IDX&switchcmd=Off&level=0"
echo 'Er is geen beweging.'
elif [ $FOSCAMStatus = "2" ];
then
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=switchlight&idx=$FOSCAM_STATUS_IDX&switchcmd=On&level=0"
echo 'Er is beweging!'
elif [ $FOSCAMStatus = "\-1" ];
then
echo 'Er is een fout opgetreden'
fi
else
echo 'Foscam staat uit'
fi
The downside is that I don't know how I can run the script real time, so I run it every minute via a crontab. In this case the actual status has a maximum delay of 1 minute.
Re: IP Camera motion detection
Posted: Monday 18 May 2015 15:53
by sincze
Nicely Done.
Indeed 'realtime' can be achieved in a 60 second while loop polling the camera multiple times within your crontjob.
After 60 seconds the while loop ends and the cronjob will kick in again for the next minute and so on and so on.
However I think the webserver of the Foscam will crash if you ask it so many times.
Waiting 1 minute before lights switch on is a bit long however as long as the camera detects motion it will keep my lights on
Re: IP Camera motion detection
Posted: Friday 29 May 2015 21:56
by Hansd
What is Foscam status idx?
En ik krijg een foutmelding met dit script in regel 46
Re: IP Camera motion detection
Posted: Sunday 31 May 2015 1:55
by Skorpion
The IDX number of the virtual switch has to be filled in there. The virtual switch has to be created so that you can see the status in Domoticz.
I adjusted the script by the way. Now the motion status will only be updated when there has been a change of status. I am at work now, so I will post this script later.
Nederlands:
Daar moet het IDX nummer ingevuld worden van de virtuele switch die aangemaakt moet worden zodat je de status kunt zien in Domoticz.
Ik heb het script trouwens nog iets aangepast, waardoor de status in Domoticz nu alleen geupdate wordt zodra deze veranderd is. Ik ben nu op werk, dus ik zal deze op een later moment nog even posten.
Re: IP Camera motion detection
Posted: Monday 01 June 2015 23:27
by Hansd
Ok thanks. I found out why the scrip gave an error message. At the end of the line with the first if statement a semicolon is missing. So now I will check the idx.
Re: IP Camera motion detection
Posted: Sunday 07 June 2015 0:30
by Hansd
It works now, so I have a motion switch which switches on when there is motion and off when there is no motion. Next job will be to make a switch which can switch on and off the storing of pictures on my ftp-server.
Re: IP Camera motion detection (Synology Action Rule)
Posted: Thursday 10 September 2015 13:10
by sincze
Hi.
Surveillance Station offers some nice features since version 7.0
https://www.synology.com/en-global/surveillance/7.0
If you don't know where to look you will miss all the fun.
It enables you to have your IP camera as a motion detection sensor (finally
).
In this scenario if motion is detected by an IP camera (voordeur). Surveilance station will switch a virtual device in domoticz and the rest can be done in Domoticz ofcourse.
(Switch on front door light for example)
Re: IP Camera motion detection
Posted: Thursday 10 September 2015 15:25
by G3rard
@sincze, the motion detection feature linked to Domoticz is very nice. Thanks for sharing!
Re: IP Camera motion detection
Posted: Thursday 10 September 2015 17:39
by sincze
G3rard wrote:@sincze, the motion detection feature linked to Domoticz is very nice. Thanks for sharing!
A sorry.
It was not complete
Motion Detection On:
http://<domoticz-ip>:<domoticz-port>/json.htm?type=command¶m=switchlight&idx=ID_OF_SWITCH&switchcmd=On&level=0
Most of it came directly from the great domoticz wiki ofcourse.
Motion Detection OFF (or reset of the switch can be done by domoticz after for example 60 seconds)
Re: IP Camera motion detection
Posted: Tuesday 03 November 2015 20:55
by markiemajax
Does anyone know if it can also be used the other way around?
Set camera to record, when external event is set on?
I would like to start my camera (on my surveillance station), to start recording when motion is detected and when my alarm is set on.
Greatings,
Mark
Re: IP Camera motion detection
Posted: Thursday 05 November 2015 23:35
by safi78
G3rard wrote:@sincze, the motion detection feature linked to Domoticz is very nice. Thanks for sharing!
The wiki page I linked does exactly the same, but that would also work for people without a Synology
Re: IP Camera motion detection
Posted: Wednesday 09 December 2015 1:06
by safi78
Hi,
I recently bought the Foscam C1 which has SOUND detection as well, thought I'd modify your script a bit and share it here:
Code: Select all
#!/bin/bash
FOSCAMIP="xxx.xxx.xxx.xxx"
FOSCAM_PORT="88"
FOSCAM_USER="xxxx"
FOSCAM_PASS="xxxx"
DOMO_IP="xxx.xxx.xxx.xxx"
DOMO_PORT="8080"
DOMO_USER="xxxx"
DOMO_PASS="xxxx"
FOSCAM_STATUS_IDX="xxx"
#foscam sound detection loop is 5s by default. 5s * 12 = 1 minute (for cron can only schedule every minute)
for i in {1..12}
do
if ping -c 1 $FOSCAMIP &> /dev/null
then
curl "http://$FOSCAMIP:$FOSCAM_PORT/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=$FOSCAM_USER&pwd=$FOSCAM_PASS" > Foscam.txt
# use motionDetectAlarm instead of soundAlarm for motion and change foscam detection loop and sleep multiplier accordingly :)
FOSCAMStatus=`grep -oP '(?<=<soundAlarm>).*(?=<\/soundAlarm>)' Foscam.txt`
if [ $FOSCAMStatus = "2" ];
then
curl -s -i -H "Accept: application/json" "http://$DOMO_USER:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=switchlight&idx=$FOSCAM_STATUS_IDX&switchcmd=On&level=0"
fi
fi
sleep 5
done
I decided just to create a fake motion detector which turns off after 5s (don't need script for that
)
And, even more awesome, when there's SOUND detected at the cam it sends a snapshot to my Telegram! (Some additional scripting required of-course
)
- Screen Shot 2015-12-09 at 01.14.33.png (120.75 KiB) Viewed 19086 times
Thanks for the script & inspiration, it works brilliantly!
Kind regards,
Sander
Re: IP Camera motion detection
Posted: Sunday 06 March 2016 11:58
by Pierryck
sincze wrote:G3rard wrote:@sincze, the motion detection feature linked to Domoticz is very nice. Thanks for sharing!
A sorry.
It was not complete
Motion Detection On:
http://<domoticz-ip>:<domoticz-port>/json.htm?type=command¶m=switchlight&idx=ID_OF_SWITCH&switchcmd=On&level=0
Most of it came directly from the great domoticz wiki ofcourse.
Motion Detection OFF (or reset of the switch can be done by domoticz after for example 60 seconds)
How do you set the Motion Dectection to OFF with Domoticz ? Once it's on ON, I didn't succeed to reset it after 1mn.
What I did in Domoticz:
I click on Timers on my virtual light device
I have defined:
Enabled: YES
Type: On Time
Time: 00:01
Randomness: NO
Command: Off
When: Everyday
IP Camera motion detection
Posted: Sunday 06 March 2016 22:42
by G3rard
Don't use the timer for this. Remove the timer you have added.
Then choose the Edit button of the switch and set the Off delay to 60 sec.
Re: IP Camera motion detection
Posted: Monday 07 March 2016 20:12
by sincze
I did it in the following way
- Off-Delay.JPG (14.97 KiB) Viewed 17975 times