Explanations see comments in code. Note: minimum version v3.4.0 required - otherwise some compontents need to be replaces (see posts below by justin) and taphold does not work.
The following DSL rule gets executed on door bell button press:
rule "Door Bell"
when
Item DoorBell_Status1Input changed from "OFF" to "ON" or
Item DoorBell_Status1Input changed from "ON" to "OFF"
then
var unread = vUnread.state as Number + 1
//this item is being used by the widget to display how many photos haven't been seen since the last reset:
vUnread.sendCommand(unread)
//result of this bash script is an updated list of files names in the photo directory:
val csvFiles = executeCommandLine(Duration.ofSeconds(1),"/etc/openhab/scripts/updateHistory.sh")
//convert list of file names to a json string containing description and file name for the widget:
var jsonPhotos = csvFiles.split('\n').map[e | "{ \"caption\": \"" + e.split(".jpg").get(0).replace("~",", ").replace("-",":") + " Uhr\", \"url\": " + "\"/static/photos/" + e + "\"}"]
//store json string in this item:
vFilenames.sendCommand(jsonPhotos.toString())
end
For easiness some of the code was shifted to a bash script updateHistory.sh:
folder="/etc/openhab/html/Photos" #this is where the photos are stored
# This string is used for the file name and description in the widget
now="$(LC_ALL=de_DE.utf8 date +"%A~%d.%m.~%H-%M-%S")" # Results in german notation Samstag~18.02.~20-22-01.
#for english weekday names use: now="$(date +"%A~%d.%m.~%H-%M-%S")"
#Download picture from camera and save it in the folder:
wget http://192.168.178.69/record/current.jpg -q -O $folder/$now.jpg
cd $folder
#for cleanup. This line deletes all old pictures and keeps the 20 latest ones.
ls -tp | tail -n +21 | xargs -I {} rm -- {} #ATTENTION: make 100% sure that you are in the correct folder. Otherwise all files in this folder will be deleted!
#create a string containing all pictures
ls $folder -1t
Widget:
when tapping a popup opens where you can slide through the photos. By intention I did not use f7-swiper because you cannot pinch to zoom.
On taphold action the number of unread photos is reset to 0
Thanks for sharing, will have to check it out soon.
Can you make this easier to configure and then add to the marketplace?
I wrote a mp4 recording history widget which is found in the marketplace so feel free to copy any code from it or how it is setup to grab the items from a single equipment selection. Been meaning to create a version of it that does mjpeg Instead of the HLS for the live feed.
Thanks for sharing this great widget and code. I have added the rule and script and this seem to work nicely now. the items are updated, but the widget looks blank. I have copy/pasted the widget code from above, not changed anything. Am I missing something?
ok. step by step.
your widget is missing the icon, label text and f7-chip. did you delete them? If you deleted too much of slot components the widget will not work.
could you post your widget?
how do you trigger the rule? It is not triggered by the widget but by item linked to your door bell
Thank you @JustinG , this helped already and the window with the pictures appears now, but indeed @Oliver2 the icon, label text and f7-chip are not showing and the taphold_action is not working with the widget. The rule for the doorbell is working well and the vUnread item is increasing with each ring, also the new pictures are stored as they should.
I have not deleted any code from your widget, this is my current version, only adjusted with the two changes @JustinG advised.
My guess is that there are additional components in that only work post 3.4.0. M1.
Sorry, you’re right I should have caught the other piece the first time.
The html tags as components was added at the same time as the @ shortcuts, so those will not be working in your version. You can also (mostly) fix those.
Any place where there is -component: [some html tag], change the component to an f7-row instead and add to the component’s config the tag property with the name of the html tag you want.
This is not a 100% perfect change. The new structure will be the same, but the rows will have the f7 row class applied to them which may result in some slightly different styling.
I will nevertheless use this opportunity to update from my current version to benefit from the added stuff post 3.4.0 M1. The taphold_action feature is one example that is still missing, so the counter is not resettable right now. So far 3.4.0M1 was running very well and stable so I was reluctant to change anything like never change a running system.
@Oliver2 thanks for sharing this widget. It inspired me to create my version of the photo history widget. My goal was to avoid bash scripts and manipulating images on the file system
Here is my widget implementation
Items:
Image doorbell_ftp_image - item is linked to FTP Upload channel
String doorbell_camera_history - items
You’ll see a photo gallery with history images by clicking on the history counter in the top right corner. Also, it will clear the history item
WARNING: This implementation has a downside, it stores all history images content in one string item and performance is not good when you have more than 100 unseen images. To fix it I’m working on API extension to put only URLs in history instead of image itself