IP Camera motion detection

User avatar
Mince Inside
Posts: 146
Joined: Wednesday 02 April 2014 20:59
Target OS: Raspberry Pi
Domoticz version:
Location: Scotland
Contact:

IP Camera motion detection

Post by Mince Inside » Wednesday 21 May 2014 13:11

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

Code: Select all

nc -l -p 8081

on my pi and on my camera I set the message to be /json.htm?type=command&param=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
Domoticz V2.2259
Raspberry Pi (B) with PiFace
RFXtrx433 USB
LighwaveRF relays, dimmer bulbs and light switches
Siemens On/Off 13A adaptors
Marmitek MS13E Motion (and Dusk) sensors

User avatar
safi78
Posts: 454
Joined: Thursday 05 September 2013 15:39
Target OS: Linux
Domoticz version: LastBeta
Location: Alkmaar, NL
Contact:

Re: IP Camera motion detection

Post by safi78 » Saturday 07 June 2014 13:53

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 :)
I don't know if you noticed or not, but I'm an extremely arrogant man who tends to think all of his plans will work ...

https://safiweb.nl

homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz

User avatar
Mince Inside
Posts: 146
Joined: Wednesday 02 April 2014 20:59
Target OS: Raspberry Pi
Domoticz version:
Location: Scotland
Contact:

Re: IP Camera motion detection

Post by Mince Inside » Saturday 07 June 2014 18:58

Thank you - will have a look, my initial concern was the load on the raspi
Domoticz V2.2259
Raspberry Pi (B) with PiFace
RFXtrx433 USB
LighwaveRF relays, dimmer bulbs and light switches
Siemens On/Off 13A adaptors
Marmitek MS13E Motion (and Dusk) sensors

Raspberry Piet
Posts: 459
Joined: Saturday 11 January 2014 17:21
Target OS: Raspberry Pi
Domoticz version: Beta
Location: NL
Contact:

Re: IP Camera motion detection

Post by Raspberry Piet » Sunday 23 November 2014 18:07

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

Image

Edit: Just found out this was already posted on this forum. :oops: Forget about mine.

User avatar
sincze
Posts: 667
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.7546
Location: Netherlands
Contact:

Re: IP Camera motion detection

Post by sincze » Sunday 07 December 2014 20:03

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. :oops: 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.
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

Skorpion
Posts: 32
Joined: Thursday 15 January 2015 10:51
Target OS: Raspberry Pi
Domoticz version:
Location: The Netherlands
Contact:

Re: IP Camera motion detection

Post by Skorpion » Monday 18 May 2015 15:36

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&param=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&param=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.

User avatar
sincze
Posts: 667
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.7546
Location: Netherlands
Contact:

Re: IP Camera motion detection

Post by sincze » Monday 18 May 2015 15:53

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 ;-)
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

Hansd
Posts: 3
Joined: Wednesday 13 May 2015 23:26
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: IP Camera motion detection

Post by Hansd » Friday 29 May 2015 21:56

What is Foscam status idx?
En ik krijg een foutmelding met dit script in regel 46

Skorpion
Posts: 32
Joined: Thursday 15 January 2015 10:51
Target OS: Raspberry Pi
Domoticz version:
Location: The Netherlands
Contact:

Re: IP Camera motion detection

Post by Skorpion » Sunday 31 May 2015 1:55

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.

Hansd
Posts: 3
Joined: Wednesday 13 May 2015 23:26
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: IP Camera motion detection

Post by Hansd » Monday 01 June 2015 23:27

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.

Hansd
Posts: 3
Joined: Wednesday 13 May 2015 23:26
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: IP Camera motion detection

Post by Hansd » Sunday 07 June 2015 0:30

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.

User avatar
sincze
Posts: 667
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.7546
Location: Netherlands
Contact:

Re: IP Camera motion detection (Synology Action Rule)

Post by sincze » Thursday 10 September 2015 13:10

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 :D ).

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)
Attachments
Domoticz-Action-3.JPG
Action Rule - Call Domoticz virtual Switch
Domoticz-Action-3.JPG (39.13 KiB) Viewed 10085 times
Domoticz-Action-2.JPG
Action Rule - What to do and when
Domoticz-Action-2.JPG (21.77 KiB) Viewed 10085 times
Domoticz-Action-1.JPG
Action Rule
Domoticz-Action-1.JPG (21.83 KiB) Viewed 10085 times
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
G3rard
Posts: 791
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: IP Camera motion detection

Post by G3rard » Thursday 10 September 2015 15:25

@sincze, the motion detection feature linked to Domoticz is very nice. Thanks for sharing!
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

User avatar
sincze
Posts: 667
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.7546
Location: Netherlands
Contact:

Re: IP Camera motion detection

Post by sincze » Thursday 10 September 2015 17:39

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&param=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)
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

markiemajax
Posts: 22
Joined: Monday 18 May 2015 15:45
Target OS: Raspberry Pi
Domoticz version: 3.4834
Contact:

Re: IP Camera motion detection

Post by markiemajax » Tuesday 03 November 2015 21:55

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

User avatar
safi78
Posts: 454
Joined: Thursday 05 September 2013 15:39
Target OS: Linux
Domoticz version: LastBeta
Location: Alkmaar, NL
Contact:

Re: IP Camera motion detection

Post by safi78 » Friday 06 November 2015 0:35

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 ;)
I don't know if you noticed or not, but I'm an extremely arrogant man who tends to think all of his plans will work ...

https://safiweb.nl

homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz

User avatar
safi78
Posts: 454
Joined: Thursday 05 September 2013 15:39
Target OS: Linux
Domoticz version: LastBeta
Location: Alkmaar, NL
Contact:

Re: IP Camera motion detection

Post by safi78 » Wednesday 09 December 2015 2:06

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&param=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
Screen Shot 2015-12-09 at 01.14.33.png (120.75 KiB) Viewed 9307 times
Thanks for the script & inspiration, it works brilliantly!

Kind regards,

Sander
I don't know if you noticed or not, but I'm an extremely arrogant man who tends to think all of his plans will work ...

https://safiweb.nl

homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz

Pierryck
Posts: 28
Joined: Saturday 27 February 2016 21:39
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: IP Camera motion detection

Post by Pierryck » Sunday 06 March 2016 12:58

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&param=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

User avatar
G3rard
Posts: 791
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

IP Camera motion detection

Post by G3rard » Sunday 06 March 2016 23:42

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.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

User avatar
sincze
Posts: 667
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.7546
Location: Netherlands
Contact:

Re: IP Camera motion detection

Post by sincze » Monday 07 March 2016 21:12

I did it in the following way :D
Off-Delay.JPG
Off-Delay.JPG (14.97 KiB) Viewed 8196 times
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest