Muss ich mal suchen, es gab eine bash Script welches die nächste Recordingzeit von TVH ausgelesen hat und dann den ACPI Timer im Bios des Rechners passen stellte damit der Rechner auch automatisch aufwacht.
Ich habe damals mir von OMV ein Script geschnappt und ein wenig angepasst, läuft seit Jahren nun problemlos als Custom-Script. Hier sind ein paar Telegram-Notifications drin welche man rauswerfen müsste wenn man es nicht nutzen will. Sicherlich nicht perfekt, aber es tut was es soll. Es weckt vor jeder Aufnahme und überprüft ob es im Zeitfenster bereits wach ist etc. das ganze lasse ich als Cron alle 7 Minuten laufen.
Bitte nicht steinigen, das lief als Service bei OMV und nun per Cron, daher sind da noch Altlasten drin welche nur auskommentiert wurden.
#!/bin/bash
#sleep 1m
# Default wake up time based on the day
sys_start_mo=17:00:00
sys_start_tu=17:00:00
sys_start_we=17:00:00
sys_start_th=17:00:00
sys_start_fr=17:00:00
sys_start_sa=8:00:00
sys_start_su=8:00:00
#check intervall
loop_sleep_timer=10m
#tv headend connection
tvh_url="http://<user>:<password>@192.168.X.X:9981"
#telegram integration
TELEGRAM_API_KEY=<KEY>
TELEGRAM_CHAT_ID=<ID>
telegram_exec=/boot/config/plugins/user.scripts/scripts/telegram_notification/script
_log()
{
[[ "$*" =~ ^([A-Za-z]*):(.*) ]] &&
{
PRIORITY=${BASH_REMATCH[1]}
LOGMESSAGE=${BASH_REMATCH[2]}
[[ "$(basename "$0")" =~ ^(.*)\. ]] &&
LOGMESSAGE="${BASH_REMATCH[1]}[$$]: $PRIORITY: '$LOGMESSAGE'";
}
logger -p $PRIORITY "$LOGMESSAGE"
}
get_default_wake(){
if [ "$today" = "1" ]; then
wake_today=$sys_start_mo
wake_tomorrow=$sys_start_tu
elif [ "$today" = "2" ]; then
wake_today=$sys_start_tu
wake_tomorrow=$sys_start_we
elif [ "$today" = "3" ]; then
wake_today=$sys_start_we
wake_tomorrow=$sys_start_th
elif [ "$today" = "4" ]; then
wake_today=$sys_start_th
wake_tomorrow=$sys_start_fr
elif [ "$today" = "5" ]; then
wake_today=$sys_start_fr
wake_tomorrow=$sys_start_sa
elif [ "$today" = "6" ]; then
wake_today=$sys_start_sa
wake_tomorrow=$sys_start_su
elif [ "$today" = "7" ]; then
wake_today=$sys_start_su
wake_tomorrow=$sys_start_mo
fi
# Check to see if the default wake up time for today is already in the past and set it for today or tomorrow
wake_today_seconds=$(date -d "today ${wake_today}" +%s)
wake_tomorrow_seconds=$(date -d "tomorrow ${wake_tomorrow}" +%s)
if [ "$current_time_seconds" -gt "$wake_today_seconds" ]; then
default_wake=$wake_tomorrow_seconds
else
default_wake=$wake_today_seconds
fi
default_wake_converted=$(date --date=@"$default_wake")
}
get_recordings(){
tvhcon=$(curl -s "$tvh_url"/api/dvr/entry/grid_upcoming)
recordings=$(echo "$tvhcon" | jq '.entries' | jq 'sort_by(.start_real)')
echo "$tvhcon"
echo "$recordings"
if ! [ "$recordings" == "[]" ]; then
found_recordings=true
else
found_recordings=false
fi
}
get_recording_time(){
# Check for valid recordings
unset channel
unset timestamp
unset title
unset subtitle
unset episode
for row in $(echo "${recordings}" | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1};
}
timestamp=$(_jq '.start_real')
recording=$(_jq '.total')
channel=$(_jq '.channelname')
title=$(_jq '.disp_title')
subtitle=$(_jq '.disp_subtitle')
episode=$(_jq '.episode_disp')
timestamp_converted=$(date -d @$timestamp)
timestamp_with_buffer=$((timestamp-180))
if [ "$current_time_seconds" -gt "$timestamp_with_buffer" ]; then
_log "INFO: TVH WakeUp: Found [$timestamp_converted - Timestamp $timestamp]"
_log "INFO: TVH WakeUp: Recording already in progress or in the past. Skip."
rtc_wake=$default_wake
else
_log "INFO: TVH WakeUp: Found [$timestamp_converted - Timestamp $timestamp]"
_log "INFO: TVH WakeUp: $channel - $subtitle - $title"
if [ "$default_wake" -lt "$timestamp_with_buffer" ]; then
rtc_wake=$default_wake
_log "INFO: TVH WakeUp: Recording starts after the server has been booted up. Use default waking time."
else
rtc_wake=$timestamp_with_buffer
_log "INFO: TVH WakeUp: Recording starts before the server has been booted up. Use it as waking time."
fi
break
fi
done
}
get_rtclock(){
rtc_wake_current_converted=$(rtcwake -l -m show | grep "alarm: on" | sed s/"alarm: on "//g)
}
set_rtclock(){
if [ -z "$rtc_wake_current_converted" ] ;then
_log "INFO: TVH WakeUp: No alarm set. Set default wake as fallback and proceed."
rtcwake -m no -t $default_wake
fi
get_rtclock
if ! [ -z "$rtc_wake_current_converted" ] ;then
rtc_wake_current=$(date -d "${rtc_wake_current_converted}" +%s)
rtc_wake_converted=$(date -d @$rtc_wake)
rtc_wake_difference=$(($rtc_wake_current-$rtc_wake))
if [ "$rtc_wake_difference" -gt "-60" ] && [ "$rtc_wake_difference" -lt "60" ]; then
_log "INFO: TVH WakeUp: Boot is already correctly scheduled at $rtc_wake_current_converted"
else
_log "INFO: TVH WakeUp: Current scheduled boot: $rtc_wake_current_converted"
_log "INFO: TVH WakeUp: Existing scheduled boot does not match. Set new waking time at $rtc_wake_converted"
rtcwake -m no -t $rtc_wake
if ! [ -z "$telegram_exec" ]; then
if ! [ -z "$channel" ]; then
/bin/bash $telegram_exec "<b>Aufnahme geplant</b>%0A%0A$timestamp_converted%0A$episode%0A$channel - $subtitle - $title"
fi
/bin/bash $telegram_exec "Nächster geplanter Boot:%0A $rtc_wake_converted"
fi
fi
fi
}
# Loop
get_rtclock
_log "INFO: Running TVH Recording Wake-Up Script"
#while true; do
_log "INFO: ### TVH WakeUp - Scan started ###"
# Update current time variables
today=$(date +'%u')
current_time_seconds=$(date +%s)
# Set the default wake up time based on the weekday
get_default_wake
_log "INFO: TVH WakeUp: Next default waking time is $default_wake_converted"
# Get next scheduled recording time
get_recordings
# Check if recordings are scheduled
_log "INFO: ### TVH WakeUp - Check for recordings ###"
if [ $found_recordings = true ]; then
get_recording_time
else
_log "INFO: TVH WakeUp: No recordings found. Use default waking time."
rtc_wake=$default_wake
fi
# Check the current set time and update it if required
_log "INFO: ### TVH WakeUp - Set wake up time ###"
set_rtclock
#Sleep
#_log "INFO: ### TVH WakeUp - Wait $loop_sleep_timer ###"
#sleep $loop_sleep_timer
#done
Alles anzeigen