It’s actually the floodlight cam.
Now, I am happy to post the code, but I want to be clear what’s actually going on…
The picture is just an image file. Creating the image and posting it somewhere available externally is the hard part.
/
/ Camera /
/*/
/ Author : Jlorentzen /
/ Created : 12/14/2017, 12:49:54 PM /
/ Modified : 12/17/2017, 9:24:15 AM /
/ Build : 37 /
/ UI version : v0.2.100.20171211 */
/**************************************************************/
settings
disable automatic piston state;
end settings;
execute
Set piston tile #1 title to “[img wide=1 refresh=120 src=http://xx.xx.xx.xx:99/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=dfdfv&user=username&password=password|]”, text to “”, footer to “”, and colors to Black over White;
Set piston tile #2 title to “[img wide=1 refresh=120 src=https://drive.google.com/uc?id=1Vb6I6UoZw9tBYAs1tfJIpMTxNzXCaP5p|]”, text to “”, footer to “”, and colors to Black over White;
Set piston state to “”;
end execute;
The hard part: I have a python script that runs every 5 minutes.
- uses the ring connection python module to connect to Ring (reverse engineered the API)
- gets the last event for the camera
- compares it to the datetime of the previous event
- if it’s different, then download the mp4 file
- call a command line utility to grab a screen print from 5 seconds and add overlay for the datetime
- upload the image and overwrite an existing image file on my Google drive with the new one. Since it overwrites, the existing URL continues to work. (Pain in the rear. Put it somewhere else if you have publically available image repository!)
It’s actually a pretty short Python script.
from ring_doorbell import Ring
from datetime import datetime
import pytz
import os
import cPickle as pickle
local = pytz.timezone (“US/Eastern”)
pickle_filepath = ‘/home/pi/Documents/ring.pickle’
#connect to Ring
myring = Ring(‘email’, ‘password’)
#only 1 Ring stickup camera, so call it by id 0
doorbell = myring.stickup_cams[0]
print(doorbell.name)
#loop through last n events - in this case only care about last one
for event in doorbell.history(limit=1):
datetime_obj = event[‘created_at’]
builttime = datetime_obj.astimezone (local)
#print local datetime of last event
print('Last event: ’ + str(builttime))
#if a pickle store doesn’t exist, create it
#to store the latest video timestamp
if not os.path.exists(pickle_filepath):
with open(pickle_filepath, ‘w’) as pickle_handle:
pickle.dump(builttime, pickle_handle)
else:
with open(pickle_filepath) as pickle_handle:
storedlast = pickle.load(pickle_handle)
#if the last activity time is not the same as the stored value
#then grab the latest video, download, and create a snapshot
#then update the pickle file with latest datetime
if not storedlast == builttime:
print(doorbell.recording_url(doorbell.last_recording_id))
doorbell.recording_download(
doorbell.history(limit=1)[0][‘id’],
filename=’/home/pi/Documents/’ + doorbell.name + ‘_last_ding.mp4’,
override=True)
os.system(‘avconv -i /home/pi/Documents/Driveway_last_ding.mp4 -vf "drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf:text=\’’ + str(builttime) + ‘\’:fontsize=48:[email protected]:x=25:y=950" -vframes 1 -ss 00:00:05 /home/pi/Documents/GDrive/snap00001.jpg’)
with open(pickle_filepath, ‘w’) as pickle_handle:
pickle.dump(builttime, pickle_handle)
os.chdir(’/home/pi/Documents/GDrive’)
#os.system(‘mogrify -resize 50% /home/pi/Documents/GDrive/snap00001.jpg’)
os.system(’/usr/local/bin/drive push -ignore-conflict -no-prompt -quiet’)
print('Stored event: ’ + str(storedlast))
#https://github.com/odeke-em/drive/
#https://github.com/tchellomello/python-ring-doorbell
Not bad for a guy that doesn’t know Python…
milhouse