Compare commits
5 Commits
45955451d7
...
59e5ffc91a
| Author | SHA1 | Date | |
|---|---|---|---|
| 59e5ffc91a | |||
| 4fe4ef7de7 | |||
| a5076ae046 | |||
| 41f3b3a4d2 | |||
| 0fb0ae1e48 |
@ -19,12 +19,11 @@ category_order=("date" "time")
|
|||||||
# Directories
|
# Directories
|
||||||
txt_dir="/data/scripts/.text"
|
txt_dir="/data/scripts/.text"
|
||||||
mp3_dir="/data/scripts/.mp3"
|
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
|
# open handout.md file
|
||||||
am start --user 0 -a android.intent.action.VIEW -d file:///data/local/tmp/file.txt -t text/plain
|
am start --user 0 -a android.intent.action.VIEW -d file:///sdcard/handout.html -t text
|
||||||
|
|
||||||
# Function to create MP3 files
|
# Function to create MP3 files
|
||||||
create_mp3_files() {
|
create_mp3_files() {
|
||||||
|
|||||||
@ -62,49 +62,33 @@ generate_text() {
|
|||||||
# Call the generate_text function
|
# Call the generate_text function
|
||||||
generate_text
|
generate_text
|
||||||
|
|
||||||
# Create HTML file
|
# Create Markdown content
|
||||||
echo "<!DOCTYPE html>" > "$html_file"
|
markdown_content="**Handout:**
|
||||||
echo "<html>" >> "$html_file"
|
\n
|
||||||
echo "<head>" >> "$html_file"
|
| Deutsch | Español |
|
||||||
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
|
||||||
echo "processing: $component"
|
|
||||||
german_output=$(cat "$text_dir/${component}_de.txt")
|
german_output=$(cat "$text_dir/${component}_de.txt")
|
||||||
spanish_output=$(cat "$text_dir/${component}_es.txt")
|
spanish_output=$(cat "$text_dir/${component}_es.txt")
|
||||||
echo "<tr><td>$german_output</td><td>$spanish_output</td></tr>" >> "$html_file"
|
markdown_content+="\n| $german_output | $spanish_output |"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "</table>" >> "$html_file"
|
# Send Notification to A72 with Markdown content
|
||||||
echo "</body>" >> "$html_file"
|
curl_command="curl -u 'Michaelis:u5ptufUFuDL6q4yEcSN3iqas5gtXNkN77Lx3cy3oX8UoSgFWdifYy9FVopv2Zwtu' \
|
||||||
echo "</html>" >> "$html_file"
|
-H 'Priority:High' \
|
||||||
|
-d \"$markdown_content\" \
|
||||||
|
-H 'Markdown: yes' \
|
||||||
|
https://ntfy.michaelis.digital/ioBroker"
|
||||||
|
|
||||||
|
echo "curl_command: $curl_command"
|
||||||
|
eval "$curl_command" # Execute the constructed curl command
|
||||||
|
|
||||||
# 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:/sdcard/
|
||||||
|
|
||||||
# Display Markdown file content
|
# Display Markdown content
|
||||||
cat $markdown_file
|
echo -e "$markdown_content"
|
||||||
|
|
||||||
# Start generate_mp3.sh on A72
|
# Start generate_mp3.sh on A72
|
||||||
nohup ssh -i /root/.ssh/A72 -f root@$A72_ip '/data/scripts/generate_mp3.sh' > /root/generate_mp3.log &
|
nohup ssh -i /root/.ssh/A72 -f root@$A72_ip '/data/scripts/generate_mp3.sh' > /root/generate_mp3.log &
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,12 @@
|
|||||||
# It turns off Bluetooth, increases the volume, and checks if the alarm has been dismissed.
|
# It turns off Bluetooth, increases the volume, and checks if the alarm has been dismissed.
|
||||||
# After the alarm is dismissed, it plays the alarm sound.
|
# After the alarm is dismissed, it plays the alarm sound.
|
||||||
|
|
||||||
echo "Script executed at: $(date)" > /data/scripts/morning-alarm.log
|
# clear logs
|
||||||
|
rm -rf /data/scripts/morning-alarm.log
|
||||||
|
echo "Script executed at: $(date)"
|
||||||
|
|
||||||
|
# Set a flag for the loop
|
||||||
|
alarm_dismissed=false
|
||||||
|
|
||||||
# Function to turn off Bluetooth
|
# Function to turn off Bluetooth
|
||||||
turn_off_bluetooth() {
|
turn_off_bluetooth() {
|
||||||
@ -23,18 +28,18 @@ increase_volume() {
|
|||||||
# Function to check the alarm notification
|
# Function to check the alarm notification
|
||||||
check_notification() {
|
check_notification() {
|
||||||
# Run the dumpsys command within a timeout
|
# Run the dumpsys command within a timeout
|
||||||
output=$(timeout 5s dumpsys activity processes | grep "com.urbandroid.sleep/")
|
output=$(dumpsys activity processes | grep "com.urbandroid.sleep")
|
||||||
|
|
||||||
# Check if the result is not empty and contains the alarm
|
# Check if the result is not empty and contains the alarm
|
||||||
if [ -n "$output" ] && echo "$output" | grep -q "AlarmKlaxon"; then
|
if [ -n "$output" ] && echo "$output" | grep -q "AlarmKlaxon"; then
|
||||||
date && echo "Alarm not dismissed yet."
|
date && echo "Alarm not dismissed yet."
|
||||||
|
sleep 5
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
date && echo "Alarm dismissed."
|
date && echo "Alarm dismissed."
|
||||||
killall mpv
|
alarm_dismissed=true
|
||||||
break
|
/system/bin/pkill play.sh
|
||||||
#killall /data/data/com.termux/files/usr/bin/mpv
|
/system/bin/pkill mpv
|
||||||
echo "$output"
|
|
||||||
exit
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,16 +48,20 @@ check_notification() {
|
|||||||
# Turn off Bluetooth
|
# Turn off Bluetooth
|
||||||
turn_off_bluetooth
|
turn_off_bluetooth
|
||||||
|
|
||||||
# Increase volume and check notification
|
# start play.sh script
|
||||||
|
/data/scripts/play.sh &
|
||||||
|
|
||||||
|
# Repeat the check_notification function
|
||||||
while true; do
|
while true; do
|
||||||
increase_volume
|
increase_volume
|
||||||
|
sleep 2
|
||||||
check_notification
|
check_notification
|
||||||
done &
|
|
||||||
|
|
||||||
## Play alarm sound
|
# Check if the alarm dismissed flag is set
|
||||||
for ((volume = 20; volume <= 100; volume += 10)); do
|
if [ "$alarm_dismissed" = true ]; then
|
||||||
echo "Actual volume: $volume"
|
/system/bin/pkill play.sh
|
||||||
/data/data/com.termux/files/usr/bin/mpv --replaygain=track --volume="$volume" /data/scripts/your-new-morning-alarm.ogg
|
/system/bin/pkill mpv
|
||||||
#check_notification &
|
exit 0 # Exit the script here
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
27
play.sh
Normal file
27
play.sh
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#!/data/data/com.termux/files/usr/bin/zsh
|
||||||
|
#
|
||||||
|
# Alarm Volume Increase Script
|
||||||
|
#
|
||||||
|
# This script plays an alarm sound with increasing volume using the mpv player.
|
||||||
|
# It iterates through different volume levels, starting from 20 and increasing by 10 until reaching 100.
|
||||||
|
|
||||||
|
# Header information
|
||||||
|
# Created: 06.02.2024
|
||||||
|
# Description: Script to play an alarm sound with increasing volume.
|
||||||
|
|
||||||
|
# Loop to play the alarm sound with increasing volume
|
||||||
|
for ((volume = 20; volume <= 100; volume += 10)); do
|
||||||
|
echo "Current volume: $volume"
|
||||||
|
|
||||||
|
# Terminate any previous mpv processes
|
||||||
|
/system/bin/pkill mpv
|
||||||
|
|
||||||
|
# Start the new mpv process with the specified volume
|
||||||
|
/data/data/com.termux/files/usr/bin/mpv --replaygain=track --volume="$volume" /data/scripts/your-new-morning-alarm.ogg &
|
||||||
|
|
||||||
|
# Wait for the completion of the current mpv process before starting the next one
|
||||||
|
wait
|
||||||
|
done
|
||||||
|
|
||||||
|
# End of the script
|
||||||
|
|
||||||
86
wecker.sh
86
wecker.sh
@ -13,6 +13,9 @@
|
|||||||
#set -e # Stop the script on errors
|
#set -e # Stop the script on errors
|
||||||
#set -x # Enable debugging # Uncomment for a more detailed log
|
#set -x # Enable debugging # Uncomment for a more detailed log
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
alarm_dismissed=false # Variable to track alarm status
|
||||||
|
|
||||||
# Debug
|
# Debug
|
||||||
debug=false
|
debug=false
|
||||||
ssh_executed=false # Variable to track SSH command status
|
ssh_executed=false # Variable to track SSH command status
|
||||||
@ -107,12 +110,12 @@ check_external_light_status() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if the alarm on the phone has been turned off
|
# Function to check the alarm notification
|
||||||
check_notification() {
|
check_notification() {
|
||||||
max_attempts=10
|
max_attempts=10
|
||||||
wait_time=5
|
wait_time=5
|
||||||
|
|
||||||
for ((i = 1; i <= $max_attempts; i++)); do
|
for ((i = 1; i <= $max_attempts;)); do
|
||||||
# Execute the SSH command within a timeout
|
# Execute the SSH command within a timeout
|
||||||
check_ip # Get IP
|
check_ip # Get IP
|
||||||
|
|
||||||
@ -121,26 +124,25 @@ check_notification() {
|
|||||||
output="com.urbandroid.sleep AlarmKlaxon"
|
output="com.urbandroid.sleep AlarmKlaxon"
|
||||||
else
|
else
|
||||||
output=$(ssh -i /root/.ssh/A72 root@$A72_ip 'dumpsys activity processes | grep com.urbandroid.sleep')
|
output=$(ssh -i /root/.ssh/A72 root@$A72_ip 'dumpsys activity processes | grep com.urbandroid.sleep')
|
||||||
echo $output
|
#echo $output
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the result contains the alarm
|
# Check if the result contains the alarm
|
||||||
if [[ $output == *"com.urbandroid.sleep"* && $output == *"AlarmKlaxon"* ]]; then
|
if [[ $output == *"com.urbandroid.sleep"* && $output == *"AlarmKlaxon"* ]]; then
|
||||||
# Alarm not turned off yet
|
# Alarm not turned off yet
|
||||||
date && echo "Alarm not turned off yet."
|
date && echo "Alarm not turned off yet."
|
||||||
echo $output
|
#echo $output
|
||||||
return
|
|
||||||
elif [[ $output == *"com.urbandroid.sleep"* && $output != *"AlarmKlaxon"* ]]; then
|
elif [[ $output == *"com.urbandroid.sleep"* && $output != *"AlarmKlaxon"* ]]; then
|
||||||
# Alarm turned off
|
# Alarm turned off
|
||||||
date && echo "Alarm turned off."
|
date && echo "Alarm turned off."
|
||||||
echo $output
|
ssh -i /root/.ssh/A72 root@$A72_ip 'killall mpv'
|
||||||
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
|
exit # Exit the script when the alarm is turned off
|
||||||
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."
|
||||||
check_ip # Get IP
|
check_ip # Get IP
|
||||||
|
i++
|
||||||
sleep $wait_time
|
sleep $wait_time
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -148,8 +150,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."
|
||||||
|
ssh -i /root/.ssh/A72 root@$A72_ip 'killall mpv'
|
||||||
iobroker state set zigbee.0.04cd15fffee03198.state false
|
iobroker state set zigbee.0.04cd15fffee03198.state false
|
||||||
exit # Beende das Skript, wenn das Telefon nicht erreicht werden konnte
|
exit # Exit the script when the phone is unreachable
|
||||||
}
|
}
|
||||||
|
|
||||||
# Define starting values for brightness and color temperature
|
# Define starting values for brightness and color temperature
|
||||||
@ -184,7 +187,7 @@ echo "Reached final colortemp: $((start_colortemp - colortemp_step * steps)) fro
|
|||||||
sleep_duration=$((duration_seconds / steps - 3))
|
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
|
||||||
current_brightness=$(printf "%.0f" $(bc <<< "$start_brightness + ($brightness_step * $i)"))
|
current_brightness=$(printf "%.0f" $(bc <<< "$start_brightness + ($brightness_step * $i)"))
|
||||||
current_colortemp=$(printf "%.0f" $(bc <<< "$start_colortemp - ($colortemp_step * $i)"))
|
current_colortemp=$(printf "%.0f" $(bc <<< "$start_colortemp - ($colortemp_step * $i)"))
|
||||||
|
|
||||||
@ -193,6 +196,7 @@ for ((i = 1; i <= $steps; i++)); do
|
|||||||
echo "current brightness= $current_brightness"
|
echo "current brightness= $current_brightness"
|
||||||
echo "current colortemp= $current_colortemp"
|
echo "current colortemp= $current_colortemp"
|
||||||
|
|
||||||
|
# Check if it's the first brightness change
|
||||||
if [ "$first_brightness_change" = true ]; then
|
if [ "$first_brightness_change" = true ]; then
|
||||||
echo "Variable first_brightness_change = true"
|
echo "Variable first_brightness_change = true"
|
||||||
check_external_light_status
|
check_external_light_status
|
||||||
@ -210,6 +214,11 @@ for ((i = 1; i <= $steps; i++)); do
|
|||||||
else
|
else
|
||||||
sleep $sleep_duration # Changes every 30 seconds
|
sleep $sleep_duration # Changes every 30 seconds
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check if the alarm is dismissed
|
||||||
|
if [ "$alarm_dismissed" = true ]; then
|
||||||
|
exit # Exit the script when the alarm is dismissed
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Set to end values.
|
# Set to end values.
|
||||||
@ -226,32 +235,53 @@ echo "$A72_ip"
|
|||||||
echo "current_brightness: $current_brightness end_brightness: $end_brightness"
|
echo "current_brightness: $current_brightness end_brightness: $end_brightness"
|
||||||
echo "current_colortemp: $current_colortemp end_colortemp: $end_colortemp"
|
echo "current_colortemp: $current_colortemp end_colortemp: $end_colortemp"
|
||||||
|
|
||||||
|
# Check if the alarm is dismissed
|
||||||
|
if [ "$alarm_dismissed" = true ]; then
|
||||||
|
exit # Exit the script when the alarm is dismissed
|
||||||
|
fi
|
||||||
|
|
||||||
ssh_command() { # Function to send a command to A72.
|
ssh_command() { # Function to send a command to A72.
|
||||||
local command=$1
|
local command=$1
|
||||||
nohup ssh -i /root/.ssh/A72 -f root@$A72_ip "$command" </dev/null &
|
|
||||||
ssh_executed=true # Mark that the SSH command has been executed.
|
ssh_executed=true # Mark that the SSH command has been executed.
|
||||||
|
|
||||||
|
# Start the SSH command in the background and store the PID.
|
||||||
|
nohup ssh -i /root/.ssh/A72 root@$A72_ip "$command" > /dev/null 2>&1 &
|
||||||
|
echo "$ssh_executed"
|
||||||
|
ssh_pid=$! # Store the PID of the SSH process.
|
||||||
|
echo "ssh_pid: $ssh_pid"+
|
||||||
|
|
||||||
|
# Wait briefly to ensure that the process has started.
|
||||||
|
sleep 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $current_brightness -eq $end_brightness ] && [ $current_colortemp -eq $end_colortemp ]; then
|
if [ $current_brightness -eq $end_brightness ] && [ $current_colortemp -eq $end_colortemp ]; then
|
||||||
# Change colors for more concentration
|
|
||||||
while :; do
|
# Continue with the color-changing loop
|
||||||
# Start the alarm script on the phone if the SSH command has not been executed yet.
|
while :; do
|
||||||
if [ "$ssh_executed" = false ]; then
|
# Start the alarm script on the phone if the SSH command has not been executed yet.
|
||||||
if [ "$debug" = true ]; then
|
if [ "$ssh_executed" = false ]; then
|
||||||
echo "DEBUG: Alternative ssh command."
|
if [ "$debug" = true ]; then
|
||||||
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"
|
echo "DEBUG: Alternative ssh command."
|
||||||
else
|
ssh_command "cmd media_session volume --set 5 --stream 9 && /data/data/com.termux/files/usr/bin/mpv /data/scripts/your-new-morning-alarm.ogg"
|
||||||
nohup ssh a72 '/data/scripts/morning-alarm.sh 2>&1 | /data/data/com.termux/files/usr/bin/tee /data/scripts/morning-alarm.log'
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
check_external_light_status
|
sleep 1
|
||||||
set_color "$green"
|
ssh_command "/data/scripts/morning-alarm.sh >> /data/scripts/morning-alarm.log" &
|
||||||
sleep 5
|
ssh_executed=true
|
||||||
set_color "$red"
|
|
||||||
sleep 5
|
|
||||||
set_color "$blue"
|
|
||||||
check_notification
|
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
check_external_light_status
|
||||||
|
set_color "$green"
|
||||||
|
sleep 5
|
||||||
|
set_color "$red"
|
||||||
|
sleep 5
|
||||||
|
set_color "$blue"
|
||||||
|
check_notification #&
|
||||||
|
fi
|
||||||
|
if [ "$alarm_dismissed" = true ]; then
|
||||||
|
echo "Alarm dismissed"
|
||||||
|
/root/iobroker_scripts/general/generate_text.sh # Call generate_text.sh script
|
||||||
|
exit # Exit the script when the alarm is dismissed
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user