Created
May 22, 2023 19:34
-
-
Save savikko/eb765bf99841f59c4def45e2d00272d3 to your computer and use it in GitHub Desktop.
Frigate / HA daily video
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias: Send daily videos | |
description: "" | |
trigger: | |
- platform: webhook | |
webhook_id: videokooste | |
condition: [] | |
action: | |
- service: notify.mobile_app_your_ios | |
data: | |
title: Daily video camera 1 | |
message: Open camera 1 daily video for {{ now().strftime('%d.%m.%Y') }} | |
data: | |
url: >- | |
https://YOUR_HA_INSTANCE/local/camera1-timelapse-{{ | |
now().strftime('%Y-%m-%d') }}.mp4 | |
- service: notify.mobile_app_your_android | |
data: | |
title: Daily video camera 2 | |
message: Open camera 1 daily video for {{ now().strftime('%d.%m.%Y') }} | |
data: | |
clickAction: >- | |
https://YOUR_HA_INSTANCE/local/camera1-timelapse-{{ | |
now().strftime('%Y-%m-%d') }}.mp4 | |
# delay to give time to check first video | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 20 | |
milliseconds: 0 | |
- service: notify.mobile_app_your_ios | |
data: | |
title: Daily video camera 2 | |
message: Open camera 2 daily video for {{ now().strftime('%d.%m.%Y') }} | |
data: | |
url: >- | |
https://YOUR_HA_INSTANCE/local/camera2-timelapse-{{ | |
now().strftime('%Y-%m-%d') }}.mp4 | |
- service: notify.mobile_app_your_android | |
data: | |
title: Daily video camera 2 | |
message: Open camera 2 daily video for {{ now().strftime('%d.%m.%Y') }} | |
data: | |
clickAction: >- | |
https://YOUR_HA_INSTANCE/local/camera2-timelapse-{{ | |
now().strftime('%Y-%m-%d') }}.mp4 | |
mode: single |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# exit if error | |
set -eu | |
if [ $# -eq 0 ]; then | |
>&2 echo "No arguments provided, needs two: camera name and date (yyyy-mm-dd)" | |
exit 1 | |
fi | |
date="$2" | |
# where to find files | |
directory="/opt/smarthome/frigate/media/recordings/$date" | |
# what do we find from directory | |
word="$1" | |
# final video location | |
output="/opt/smarthome/home-assistant/config/www/$word-timelapse-$date.mp4" | |
# concatenated video file, but results too long duration, which will be trimmed | |
tempvideo="./temp.mp4" | |
# speed; 1=realtime, 0.1=10x etc | |
multiply=0.005 | |
# holds filelist | |
tempfile=./list | |
# find and generate filelist | |
find "$directory" -type f | grep $word |grep mp4|sort > $tempfile | |
sed -i -e 's/^/file /' $tempfile | |
# generate timelapse (obs! -y overwrites file without asking) | |
ffmpeg -y -f concat -safe 0 -i $tempfile -vf "setpts=$multiply*PTS" -vcodec libx264 $tempvideo | |
# find out length of the file to prepare trimming | |
length=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $tempvideo) | |
# then find out final length | |
end=$(echo $length*$multiply|bc) | |
# trim to correct length | |
ffmpeg -y -i $tempvideo -ss 0 -to $end $output | |
# Remove temporary files | |
rm $tempfile | |
rm $tempvideo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 20 * * * /directory/timelapse_all.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
date=$(date '+%Y-%m-%d') | |
# create first camera timelapse | |
./create_timelapse.sh camera1 $date | |
# create second camera timelapse | |
./create_timelapse.sh camera2 $date | |
# notify HA to send notifications | |
curl -X POST https://YOUR_HA_INSTANCE/api/webhook/videokooste |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment