Compare commits

...

5 Commits

Author SHA1 Message Date
45955451d7
Update wecker.sh script
The wecker.sh script has been modified with the following changes:

1. Modified the 'check_notification()' function to exit the entire script using 'exit' instead of 'return' when the alarm is turned off or the phone is unreachable. This ensures the script terminates completely in these scenarios.

2. Adjusted the 'sleep_duration' calculation to subtract 3 seconds, enhancing the script's timing accuracy during gradual adjustment of brightness and color temperature.

3. Changed the ssh command in the loop to use 'nohup' and 'tee' for logging the morning-alarm.sh output to a file named 'morning-alarm.log'. This modification improves logging and captures script output for later analysis.

These changes enhance the wecker.sh script by improving script termination logic, adjusting sleep duration for better timing accuracy, and enhancing logging during the execution of the morning-alarm.sh script.
2024-02-01 13:57:03 +01:00
62243df8ac
Update morning-alarm.sh script
The morning-alarm.sh script has been modified with the following changes:

- Added the 'break' statement after killing the mpv process to exit the loop when the alarm is dismissed. This prevents unnecessary iterations and improves script efficiency.
- Commented out the line 'killall /data/data/com.termux/files/usr/bin/mpv' since it seems to be redundant after the 'killall mpv' command. If this line is intended for different use, it may need further clarification or context.

These changes enhance the morning-alarm.sh script by optimizing the loop's termination when the alarm is dismissed, improving script efficiency and preventing unnecessary iterations. The redundant 'killall' line has been commented out for clarification.
2024-02-01 13:55:59 +01:00
313e9c8737
Update generate_text.sh script
The generate_text.sh script has been modified with the following changes:

- Updated the variable name 'markdown_file' to 'html_file' to reflect the change in the file format from Markdown to HTML.
- Modified the HTML structure to create a formatted table for the handout, enhancing readability and presentation.
- Added inline CSS styling to the HTML file to improve the table layout and appearance.

These changes improve the generate_text.sh script by switching from Markdown to HTML for better presentation and readability of the handout. Additionally, the HTML table is now more structured and visually appealing.

The commit also includes the removal of the previous notification-related code, which was commented out and not in use.

The goal is to enhance the script's functionality and improve the presentation of the generated handout in HTML format.
2024-02-01 13:54:36 +01:00
382e28c481
Update generate_mp3.sh script
The generate_mp3.sh script has been updated with the following changes:

- Added a comment to specify the directory for MP3 files.
- Implemented a command to open the handout.md file using the 'am start' command.
- The 'am start' command opens the file in VIEW mode with the 'text/plain' MIME type.
- This enhancement provides a convenient way to access the handout.md file directly.

The commit aims to improve the functionality and user experience of the generate_mp3.sh script by enabling easy access to the handout file.
2024-02-01 13:53:31 +01:00
a8a923d16b
Refactor A72_alarm_getter.sh script
The A72_alarm_getter.sh script has been refactored for improved readability and clarity. Changes include:

- Updated script header with standardized information.
- Changed German comments to English for consistency.
- Improved comments and added explanations for key sections.
- Reorganized code structure for better flow.
- Enhanced variable names for increased understanding.
- Added debug information for 'at' jobs.
- Modified output messages for better user understanding.
- Ensured consistent formatting throughout the script.
- Fixed indentation issues and removed unnecessary spaces.

The commit aims to make the script more maintainable and user-friendly, following best practices for scripting.
2024-02-01 13:51:24 +01:00
5 changed files with 121 additions and 95 deletions

View File

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

View File

@ -23,6 +23,9 @@ mp3_dir="/data/scripts/.mp3"
# remove old files # remove old files
rm -f "$txt_dir"/*complete.txt 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 # Function to create MP3 files
create_mp3_files() { create_mp3_files() {

View File

@ -9,7 +9,7 @@
####################################### #######################################
text_dir="/root/iobroker_scripts/general/.text" text_dir="/root/iobroker_scripts/general/.text"
markdown_file="$text_dir/handout.md" html_file="$text_dir/handout.html"
all=("date" "time") # Add more elements as needed all=("date" "time") # Add more elements as needed
@ -62,41 +62,46 @@ generate_text() {
# Call the generate_text function # Call the generate_text function
generate_text generate_text
# Create Markdown file # Create HTML file
echo "## Handout:" > $markdown_file echo "<!DOCTYPE html>" > "$html_file"
echo "| Deutsch | Español |" >> $markdown_file echo "<html>" >> "$html_file"
echo "| ------- | ------- |" >> $markdown_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"
for component in "${all[@]}"; do for component in "${all[@]}"; do
german_output=$(cat $text_dir/${component}_de.txt) echo "processing: $component"
spanish_output=$(cat $text_dir/${component}_es.txt) german_output=$(cat "$text_dir/${component}_de.txt")
echo "| $german_output | $spanish_output |" >> $markdown_file spanish_output=$(cat "$text_dir/${component}_es.txt")
echo "<tr><td>$german_output</td><td>$spanish_output</td></tr>" >> "$html_file"
done done
echo "</table>" >> "$html_file"
echo "</body>" >> "$html_file"
echo "</html>" >> "$html_file"
# Transfer files to A72 # Transfer files to A72
scp -r -i /root/.ssh/A72 "$text_dir" root@$A72_ip:/data/scripts/ 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 # Display Markdown file content
cat $markdown_file cat $markdown_file

View File

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

View File

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