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.
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
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
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.
#!/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.
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
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
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.
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.
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.
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)
Attachments
Action Rule - Call Domoticz virtual Switch
Domoticz-Action-3.JPG (39.13 KiB) Viewed 19874 times
Action Rule - What to do and when
Domoticz-Action-2.JPG (21.77 KiB) Viewed 19874 times
Action Rule
Domoticz-Action-1.JPG (21.83 KiB) Viewed 19874 times
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
#!/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 19096 times
Thanks for the script & inspiration, it works brilliantly!
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