Edit: Script not needed anymore for the TOP-201 mini camera. With a firmware update it now has a url that spits out a JPEG image.
See my blog for more information:
https://thinkpad.tweakblogs.net/blog/12 ... -stream%21
For other cameras that still only support (RTSP) stream, the script can be used.
Updated script:
snapshot.sh (i have it in /volume1/@appstore/domoticz/var/scripts/bash/doorbell/snapshot.sh)
Code: Select all
#!/bin/sh
today=`/bin/date '+%d-%m-%Y__%H-%M-%S'`; #Used to generate filename
IP="192.168.4.20" # IP address Camera
#Ping IP-address of camera to see if it's online, otherwise we don't have to grab a snapshot
if ping -c 1 $IP > /dev/null ; then
#Grab snapshot from RTSP-stream
/volume1/@appstore/MediaServer/bin/ffmpeg -rtsp_transport tcp -i 'rtsp://'$IP'/user=admin&password=&channel=1&stream=0.sdp' -f image2 -vframes 1 -pix_fmt yuvj420p /volume1/homes/admin/doorbellcam/Public/doorbell_snapshots/$today.jpeg
#Send pushnotification with URL to snapshot
sh /volume1/@appstore/domoticz/var/scripts/bash/doorbell/pushover.sh -u PUSHOVER_USERKEY -a PUSHOVER_APPKEY -q "Doorbell" -m "https://dl.dropboxusercontent.com/u/YOUR_DROPBOX_PUBLICFOLDER_ID/doorbell_snapshots/$today.jpeg"
#Delete previous taken snapshots older than 7 days
find /volume1/homes/admin/doorbellcam/Public/doorbell_snapshots/ -name '*.jpeg' -mtime +7 -delete
else
sh /volume1/@appstore/domoticz/var/scripts/bash/doorbell/pushover.sh -u PUSHOVER_USERKEY -a PUSHOVER_APPKEY -q "Doorbell" -m "Doorbell has just been pressed, but image is unavailable because camera is ofline"
fi
You can grab the pushover.sh here:
https://github.com/fschaefer/pushover.sh
According to 'kraades' on Tweakers, the package won't autostart at boot if you stop it manually. So if you don't have a suitable 'ffmpeg' on your Synology NAS, you can install the 'Media Server' package without even loading your CPU, because the package doesn't have to be running
The
snapshot.sh is triggered by a Lua script:
script_device_doorbell_singlepulse.lua (i have it in /volume1/@appstore/domoticz/var/scripts/lua/script_device_doorbell_singlepulse.lua)
Code: Select all
-- script_device_deurbel_singlepuls.lua
-- Script needs a Domoticz uservariable called 'DoorbellPreviousPress' of type 'String'
-- See http://domoticz.com/forum/viewtopic.php?f=23&t=7512 for more information
commandArray = {}
TimeBetweenPresses = 30 --time that needs to be between presses (in seconds), before os.execute line is ran again
function datetimedifferencenow(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
if (devicechanged['Doorbell'] == 'On') then
if (datetimedifferencenow(uservariables_lastupdate['DoorbellPreviousPress']) > TimeBetweenPresses ) then
print('<b style="color:Blue">Doorbell has been pressed: previous press was <b style="color:Green">MORE</b> than '..TimeBetweenPresses..' sec ago, send pushnotification</b>')
os.execute('/volume1/@appstore/domoticz/var/scripts/bash/doorbell/snapshot.sh')
commandArray['Variable:DoorbellPreviousPress']=tostring(os.time())
else
print('<b style="color:Blue">Doorbell: previous press was <b style="color:Red">LESS</b> than '..TimeBetweenPresses..' sec ago, ignore signal</b>')
end
end
return commandArray
The image is dropped into a folder that is being watched by the 'Cloud Sync' package from Synology. I have it linked to my Dropbox, and thus a image is put in my Dropbox, which i can access using the URL for the public folder. This wil NOT work for other folders, only for the public folder the URL stays always the same.
It is also important that you choose the 'Bidirectional' sync direction, otherwise the 'Public' folder will not appear on your NAS. You also need the 'Media Server' package, because it contains the updated 'ffmpeg' utility with support for RTSP. But you can stop the package, it is not needed that it is running.
It works really great now. Doorbell is pressed, the Lua script looks if the previous press was more than XX seconds ago
(otherwise multipe images and pushnotifications would be sent, which is annoying if the package delivery guy presses the button 3x), if so the Bash script is started. In the Bash script the camera is first pinged (otherwise we don't have to go through all the trouble of grabbing a snapshot), then a screenshot is grabbed, pushnotification is send, and at the end the script looks in the directory if there are images older than 7 days (i don't see any value in keeping them longer).
I am not active on this forum anymore.