Compare commits

..

No commits in common. "45955451d7db9dda6ebdcce18b6c74d76d7cc735" and "1bb6546100d78b82815f5debf2eba6ebc450debe" have entirely different histories.

5 changed files with 95 additions and 121 deletions

View File

@ -1,55 +1,47 @@
#!/bin/bash
#
# Automatic Wake-up Script
# Author: Michael Haider
# Date: October 31, 2023
# Automatisches Aufstehen-Skript
# Autor: Michael, Haider
# Datum: 31. Oktober 2023
#
# This script retrieves the next wake-up time from A72 and schedules
# turning on the lights using the "at" command.
# Dieses Skript ermittelt den nächsten Weckzeitpunkt von A72 und plant
# dann das Einschalten der Lichter.
# mit dem "at" Befehl.
echo "Executed at: "
echo "Ausgeführt um: "
date
# Check if old "at" jobs have expired and delete them
# Überprüfen, ob alte "at"-Aufträge abgelaufen sind und sie löschen
delete_expired_at_jobs() {
current_time=$(date +"%Y-%m-%d %H:%M:%S")
old_jobs=$(/usr/bin/atq | awk -v current_time="$current_time" '$3 < current_time { print $1 }')
if [ -n "$old_jobs" ]; then
echo "Deleting expired 'at' jobs:"
echo "Lösche überholte 'at'-Jobs:"
for job_id in $old_jobs; do
/usr/bin/atrm "$job_id"
echo "Deleted: $job_id"
echo "Gelöscht: $job_id"
done
else
echo "No expired 'at' jobs found."
echo "Keine überholten 'at'-Jobs gefunden."
fi
# Debug: List all 'at' jobs
echo "All 'at' jobs:"
/usr/bin/atq
# Keep only the earliest 'at' job and delete all other jobs
next_job_id=$(/usr/bin/atq | sort -k3,4 -k5,5 | awk 'NR==1 {print $1}')
if [ -n "$next_job_id" ]; then
echo "Next 'at' job to keep: $next_job_id"
/usr/bin/atrm $(/usr/bin/atq | awk -v next_job_id="$next_job_id" '$1 != next_job_id {print $1}')
echo "Only the next 'at' job remains: $next_job_id"
else
echo "No 'at' jobs found."
fi
# Debug: List remaining 'at' jobs after deletion
echo "Remaining 'at' jobs:"
/usr/bin/atq
## Behalte nur den nächsten 'at'-Job und lösche alle zukünftigen Jobs
#next_job_id=$(/usr/bin/atq | awk '{print $1}' | sort -n | head -n 1)
#if [ -n "$next_job_id" ]; then
#/usr/bin/atrm $(/usr/bin/atq | awk -v next_job_id="$next_job_id" '$1 > next_job_id {print $1}')
#echo "Nur der nächste 'at'-Job bleibt erhalten: $next_job_id"
#else
#echo "Keine 'at'-Jobs gefunden."
#fi
}
# Use the function to delete expired jobs
# Verwende die Funktion, um überholte Jobs zu löschen
delete_expired_at_jobs
# Get the IP address of Lisa's iPhone (without Ping test)
# Die IP-Adresse von Lisas-IPhone holen (ohne Ping-Test)
check_ip() {
mac_address="e4:cd:d1" # Replace this with the MAC address
mac_address="e4:cd:d1" # Ersetze dies durch die MAC-Adresse
attempts=10
interval=5
@ -57,64 +49,57 @@ check_ip() {
A72_ip=$(arp-scan -r 5 -v --localnet | grep "$mac_address" | awk '{print $1}')
if [ -n "$A72_ip" ]; then
echo "Found IP: $A72_ip"
return 0 # Success: IP address found
echo "Gefundene IP: $A72_ip"
return 0 # Erfolg: IP-Adresse gefunden
fi
if [ $i -lt $attempts ]; then
echo "Waiting $interval seconds before the next attempt."
echo "Warte $interval Sekunden, bevor der nächste Versuch gestartet wird."
sleep $interval
fi
done
# All attempts unsuccessful
echo "The target could not be reached after $attempts attempts."
# Alle Versuche erfolglos
echo "Das Ziel konnte nach $attempts Versuchen nicht erreicht werden."
iobroker state set zigbee.0.04cd15fffee03198.state false
return 1 # Error: IP address not found
return 1 # Fehler: IP-Adresse nicht gefunden
}
# Execute the check_ip function.
check_ip || exit 1 # Exit the script if the target is unreachable
# check_ip -Funktion ausführen.
check_ip || exit 1 # Beende das Skript, wenn das Ziel nicht erreichbar ist
# File to store scheduled wake-up times
# Datei zum Speichern der geplanten Weckzeiten
weckzeit_datei="/root/iobroker_scripts/general/.weckzeiten.txt"
# Target is reachable, retrieve alarm time over SSH
# Ziel ist erreichbar, Alarmzeit über SSH abrufen
alarmTime=$(ssh -i /root/.ssh/A72 root@$A72_ip dumpsys alarm | grep -A 6 ":com.urbandroid.sleep.alarmclock.ALARM_ALERT" | grep "type=RTC_WAKEUP origWhen=" | cut -d= -f3 | cut -c1-16 | uniq)
if [ -n "$alarmTime" ]; then
# Parse the date and time
date=$(echo "$alarmTime" | cut -d ' ' -f 1)
time=$(echo "$alarmTime" | cut -d ' ' -f 2)
# Zerlege das Datum und die Uhrzeit
datum=$(echo "$alarmTime" | cut -d ' ' -f 1)
uhrzeit=$(echo "$alarmTime" | cut -d ' ' -f 2)
# Format the date and time
new_format=$(date -d "$date $time" "+%H:%M %m/%d/%y")
# Formatiere das Datum und die Uhrzeit neu
neues_format=$(date -d "$datum $uhrzeit" "+%H:%M %m/%d/%y")
# Subtract 15 minutes from the time
lightsOn=$(date -d "$new_format - 15 minutes" "+%H:%M %m/%d/%y")
# Subtrahiere 15 Minuten von der Zeit
lightsOn=$(date -d "$neues_format - 15 minutes" "+%H:%M %m/%d/%y")
echo "Next Alarm: $new_format"
echo "Turning on lights at: $lightsOn"
echo "Nächster Wecker: $neues_format"
echo "Lichter einschalten um: $lightsOn"
# Check if the wake-up time is already scheduled
if grep -Fxq "$lightsOn" "$weckzeit_datei"; then
echo "Wake-up time already scheduled for: $lightsOn"
else
echo "Schedule wake-up time and save to file: $lightsOn"
echo "$lightsOn" > "$weckzeit_datei"
# Remove all existing 'at' Jobs
/usr/bin/atrm $(/usr/bin/atq | awk '{print $1}')
# Add the new 'at' Job
echo "/root/iobroker_scripts/schlafzimmer/wecker.sh > /root/wecker.log" | at "$lightsOn"
curl -u "Michaelis:u5ptufUFuDL6q4yEcSN3iqas5gtXNkN77Lx3cy3oX8UoSgFWdifYy9FVopv2Zwtu" -H "Icon:https://static.vecteezy.com/system/resources/previews/018/931/118/original/alarm-clock-icon-png.png" -d "Alarm set at: $new_format" https://ntfy.michaelis.digital/$HOSTNAME
fi
# Überprüfen, ob die Weckzeit bereits geplant ist
if grep -Fxq "$lightsOn" "$weckzeit_datei"; then
echo "Weckzeit ist bereits geplant für: $lightsOn"
else
echo "No alarm set. Deleting scheduled wake-up times."
#curl -u "Michaelis:u5ptufUFuDL6q4yEcSN3iqas5gtXNkN77Lx3cy3oX8UoSgFWdifYy9FVopv2Zwtu" -H "Icon:https://static.vecteezy.com/system/resources/previews/018/931/118/original/alarm-clock-icon-png.png" -H "Priority:High" -d "Alarm deleted" https://ntfy.michaelis.digital/$HOSTNAME
echo "Weckzeit planen und in Datei speichern: $lightsOn"
echo "$lightsOn" > "$weckzeit_datei"
echo "/root/iobroker_scripts/schlafzimmer/wecker.sh > /root/wecker.log" | at "$lightsOn"
curl -u "Michaelis:u5ptufUFuDL6q4yEcSN3iqas5gtXNkN77Lx3cy3oX8UoSgFWdifYy9FVopv2Zwtu" -H "Icon:https://static.vecteezy.com/system/resources/previews/018/931/118/original/alarm-clock-icon-png.png" -d "Alarm gestellt um: $neues_format" https://ntfy.michaelis.digital/$HOSTNAME
fi
else
echo "Kein Wecker gestellt. Lösche geplante Weckzeiten."
#curl -u "Michaelis:u5ptufUFuDL6q4yEcSN3iqas5gtXNkN77Lx3cy3oX8UoSgFWdifYy9FVopv2Zwtu" -H "Icon:https://static.vecteezy.com/system/resources/previews/018/931/118/original/alarm-clock-icon-png.png" -H "Priority:High" -d "Alarm gelöscht" https://ntfy.michaelis.digital/$HOSTNAME
rm "$weckzeit_datei"
fi

View File

@ -23,9 +23,6 @@ mp3_dir="/data/scripts/.mp3"
# remove old files
rm -f "$txt_dir"/*complete.txt
# open handout.md file
am start --user 0 -a android.intent.action.VIEW -d file:///data/local/tmp/file.txt -t text/plain
# Function to create MP3 files
create_mp3_files() {

View File

@ -9,7 +9,7 @@
#######################################
text_dir="/root/iobroker_scripts/general/.text"
html_file="$text_dir/handout.html"
markdown_file="$text_dir/handout.md"
all=("date" "time") # Add more elements as needed
@ -62,46 +62,41 @@ generate_text() {
# Call the generate_text function
generate_text
# Create HTML file
echo "<!DOCTYPE html>" > "$html_file"
echo "<html>" >> "$html_file"
echo "<head>" >> "$html_file"
echo "<title>Handout</title>" >> "$html_file"
echo "<style>" >> "$html_file"
echo "table {" >> "$html_file"
echo " border-collapse: collapse;" >> "$html_file"
echo " width: 50%;" >> "$html_file"
echo " margin: auto;" >> "$html_file"
echo "}" >> "$html_file"
echo "th, td {" >> "$html_file"
echo " border: 1px solid black;" >> "$html_file"
echo " padding: 8px;" >> "$html_file"
echo " text-align: left;" >> "$html_file"
echo "}" >> "$html_file"
echo "th {" >> "$html_file"
echo " background-color: #f2f2f2;" >> "$html_file"
echo "}" >> "$html_file"
echo "</style>" >> "$html_file"
echo "</head>" >> "$html_file"
echo "<body>" >> "$html_file"
echo "<h2>Handout:</h2>" >> "$html_file"
echo "<table>" >> "$html_file"
echo "<tr><th>Deutsch</th><th>Español</th></tr>" >> "$html_file"
# Create Markdown file
echo "## Handout:" > $markdown_file
echo "| Deutsch | Español |" >> $markdown_file
echo "| ------- | ------- |" >> $markdown_file
for component in "${all[@]}"; do
echo "processing: $component"
german_output=$(cat "$text_dir/${component}_de.txt")
spanish_output=$(cat "$text_dir/${component}_es.txt")
echo "<tr><td>$german_output</td><td>$spanish_output</td></tr>" >> "$html_file"
german_output=$(cat $text_dir/${component}_de.txt)
spanish_output=$(cat $text_dir/${component}_es.txt)
echo "| $german_output | $spanish_output |" >> $markdown_file
done
echo "</table>" >> "$html_file"
echo "</body>" >> "$html_file"
echo "</html>" >> "$html_file"
# Transfer files to A72
scp -r -i /root/.ssh/A72 "$text_dir" root@$A72_ip:/data/scripts/
# Send Notification to A72 with handout.md file
curl_command="curl -u 'Michaelis:u5ptufUFuDL6q4yEcSN3iqas5gtXNkN77Lx3cy3oX8UoSgFWdifYy9FVopv2Zwtu' \
-H 'Priority:High' \
-T $markdown_file \
-H 'Filename: handout.md' \
-d $'notification_date: Heute ist Dienstag, der 30. Januar 2024.\n"
for component in "${all[@]}"; do
curl_command+="${component}:\n"
curl_command+="$(cat $text_dir/${component}_de.txt)\n"
curl_command+="$(cat $text_dir/${component}_es.txt)\n"
done
curl_command="${curl_command%\\n}" # Remove the trailing newline
curl_command+="\n'"
curl_command+=" https://ntfy.michaelis.digital/ioBroker"
echo "curl_command: $curl_command"
eval "$curl_command" # Execute the constructed curl command
# Display Markdown file content
cat $markdown_file

View File

@ -31,8 +31,6 @@ check_notification() {
else
date && echo "Alarm dismissed."
killall mpv
break
#killall /data/data/com.termux/files/usr/bin/mpv
echo "$output"
exit
fi
@ -53,6 +51,5 @@ done &
for ((volume = 20; volume <= 100; volume += 10)); do
echo "Actual volume: $volume"
/data/data/com.termux/files/usr/bin/mpv --replaygain=track --volume="$volume" /data/scripts/your-new-morning-alarm.ogg
#check_notification &
done

View File

@ -136,7 +136,7 @@ check_notification() {
echo $output
iobroker state set zigbee.0.04cd15fffee03198.state false
/root/iobroker_scripts/general/generate_text.sh > /dev/null
exit # Beende das Skript, wenn der Alarm ausgeschaltet wurde
return # Exit the function without terminating the entire script
else
# Phone unreachable
echo "Phone unreachable. Waiting $wait_time seconds before the next attempt."
@ -147,9 +147,9 @@ check_notification() {
# Phone could not be reached.
echo "Phone could not be reached after $max_attempts attempts."
date && echo "Alarm turned off."
iobroker state set zigbee.0.04cd15fffee03198.state false
exit # Beende das Skript, wenn das Telefon nicht erreicht werden konnte
date && echo "Alarm turned off."
iobroker state set zigbee.0.04cd15fffee03198.state false
return
}
# Define starting values for brightness and color temperature
@ -181,7 +181,7 @@ echo "Reached final brightness: $((brightness_step * steps + start_brightness))
colortemp_step=$(( start_colortemp / steps ))
echo "Color temperature difference per step: $colortemp_step"
echo "Reached final colortemp: $((start_colortemp - colortemp_step * steps)) from $end_colortemp"
sleep_duration=$((duration_seconds / steps - 3))
sleep_duration=$((duration_seconds / steps))
# Gradual adjustment of brightness and color temperature
for ((i = 1; i <= $steps; i++)); do
@ -241,7 +241,7 @@ if [ $current_brightness -eq $end_brightness ] && [ $current_colortemp -eq $end_
echo "DEBUG: Alternative ssh command."
ssh_command "cmd media_session volume scripts/--set 5 --stream 9 && /data/data/com.termux/files/usr/bin/mpv /data/scripts/your-new-morning-alarm.ogg"
else
nohup ssh a72 '/data/scripts/morning-alarm.sh 2>&1 | /data/data/com.termux/files/usr/bin/tee /data/scripts/morning-alarm.log'
ssh_command "/data/scripts/morning-alarm.sh > /dev/null"
fi
else
check_external_light_status