Compare commits

..

No commits in common. "53000fc60761d0d4d739f6afdfc4f677924dfba3" and "d68beee2b88b862dd809a4df200fae1241a41ce1" have entirely different histories.

5 changed files with 38 additions and 187 deletions

View File

@ -69,7 +69,7 @@ check_ip() {
check_ip || exit 1 # Beende das Skript, wenn das Ziel nicht erreichbar ist check_ip || exit 1 # Beende das Skript, wenn das Ziel nicht erreichbar ist
# Datei zum Speichern der geplanten Weckzeiten # Datei zum Speichern der geplanten Weckzeiten
weckzeit_datei="/root/iobroker_scripts/general/.weckzeiten.txt" weckzeit_datei="/root/iobroker_scripts/generel/.weckzeiten.txt"
# Ziel ist erreichbar, Alarmzeit über SSH abrufen # 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) 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)

View File

@ -1,73 +0,0 @@
#!/bin/sh
#######################################
# generate_mp3.sh - Generates MP3 files from text files in German and Spanish
#
# Author: Michael Haider
# Created on: 26.01.2024
# Description: This script creates MP3 files from text files in German and Spanish
# using gtts-cli (Google Text-to-Speech).
#######################################
# Export the path to the programs
export PATH=$PATH:/data/data/com.termux/files/usr/bin
# Array with the desired languages in order
lang_order=("es" "de" "es-l")
category_order=("date" "time")
# Directories
txt_dir="/data/scripts/.text"
mp3_dir="/data/scripts/.mp3"
# Function to create MP3 files
create_mp3_files() {
rm -f "$txt_dir"/*complete.txt
for file in "$txt_dir"/*.txt; do
text=$(cat "$file") # Read the content of the file
base_filename=$(basename "$file" .txt) # File name without path and extension
if [[ $file == *de.txt ]]; then
# If it's a German file, create a German MP3
/data/data/com.termux/files/usr/bin/gtts-cli -l de "$text" --output "$mp3_dir/$base_filename.mp3"
echo "$text" > "$txt_dir/de_complete.txt"
echo "German MP3 file created: $base_filename.mp3"
elif [[ $file != *de.txt ]]; then
# If it's a Spanish file, create a Spanish MP3 in slow mode
/data/data/com.termux/files/usr/bin/gtts-cli -l es -s "$text" --output "$mp3_dir/$base_filename.mp3"
echo "$text" > "$txt_dir/es_complete.txt"
echo "Spanish MP3 file created: $base_filename.mp3"
else
echo "File $file was not processed"
fi
done
}
# Call the function to create the MP3 files
create_mp3_files
# Set media volume
cmd media_session volume --set 10 --stream 9
# Loop through categories and languages
for category in "${category_order[@]}"; do
echo "All categories: ${category_order[@]}"
echo "Actual category: $category"
for language in "${lang_order[@]}"; do
echo "All languages: ${lang_order[@]}"
echo "Actual language: $language"
echo "Actual file: ${category}_${language}.mp3"
# Check if the language indicates slower playback
if [[ $language == *"-l"* ]]; then
# If "-l" is present in lang_order, play the file at half speed
lang_without_l="${language/-l/}" # Remove "-l" from the language
mpv --speed=0.8 "$mp3_dir/${category}_${lang_without_l}.mp3"
else
# Otherwise, play the file at normal speed
mpv "$mp3_dir/${category}_${language}.mp3"
fi
done
done

View File

@ -1,70 +0,0 @@
#!/bin/bash
#######################################
# generate_text.sh - Create text files (German and Spanish)
#
# Author: Michael Haider
# Created on: 26.01.2024
# Description: This script generates various text files with information such as date, time, news, and weather in German and Spanish.
#######################################
text_dir="/root/iobroker_scripts/general/.text"
# Function to get the IP address of Lisa's iPhone
check_ip() {
mac_address="e4:cd:d1" # Replace this with the MAC address
attempts=10
interval=5
for ((i = 1; i <= $attempts; i++)); do
A72_ip=$(arp-scan -r 3 -v --localnet | grep "$mac_address" | awk '{print $1}')
if [ -n "$A72_ip" ]; then
echo "Found IP: $A72_ip"
return 0 # Success: IP address found
fi
if [ $i -lt $attempts ]; then
echo "Wait $interval seconds before the next attempt."
sleep $interval
fi
done
# All attempts unsuccessful
echo "The target could not be reached after $attempts attempts."
return 1 # Error: IP address not found
}
# Execute the check_ip function.
check_ip
# Function to generate the text files
generate_text() {
# German
date_de=$(date '+Heute ist %A, der %d. %B %Y.')
echo $date_de > $text_dir/date_de.txt
time_de=$(date '+Es ist %H:%M Uhr.')
echo $time_de > $text_dir/time_de.txt
# Spanish
date_es=$(trans -b :de :es "$date_de")
echo $date_es > $text_dir/date_es.txt
time_es=$(trans -b :de :es "$time_de")
echo $time_es > $text_dir/time_es.txt
}
# Call the generate_text function
generate_text
# Transfer files to A72
scp -r -i /root/.ssh/A72 $text_dir root@$A72_ip:/data/scripts/
# Start generate_mp3.sh on A72
ssh -i /root/.ssh/A72 -f root@$A72_ip '/data/scripts/generate_mp3.sh' > /root/generate_mp3.log &
# Output the generated texts
echo "German Output:"
echo "$date_de $time_de"
echo "Spanish Output:"
echo "$date_es $time_es"

View File

@ -1,51 +1,50 @@
#!/bin/sh #!/bin/sh
# #
# Alarm Control Script # Wecker-Steuerungsskript
# #
# This script controls the alarm on the Android device. # Dieses Skript steuert den Wecker auf dem Android-Gerät.
# It turns off Bluetooth, increases the volume, and checks if the alarm has been dismissed. # Es schaltet Bluetooth aus, erhöht die Lautstärke und überprüft, ob der Wecker beendet wurde.
# After the alarm is dismissed, it plays the alarm sound. # Nach dem Beenden des Weckers wird der Weckersound abgespielt.
echo "Script executed at: $(date)" > /data/scripts/morning-alarm.log echo "Script ausgeführt um: $(date)" > /data/scripts/morning-alarm.log
# Function to turn off Bluetooth # Funktion zum Ausschalten von Bluetooth
turn_off_bluetooth() { turn_off_bluetooth() {
echo "Turning off Bluetooth." svc bluetooth disable
svc bluetooth disable || { echo "Error turning off Bluetooth." ; exit 1; }
} }
# Function to increase the volume # Funktion zum Erhöhen der Lautstärke
increase_volume() { increase_volume() {
echo "Increasing volume." cmd media_session volume --set 15 --stream 9
cmd media_session volume --set 15 --stream 9 || { echo "Error increasing volume." ; exit 1; }
} }
# Function to check the alarm notification # Funktion zum Überprüfen der Weckerbenachrichtigung
check_notification() { check_notification() {
# Run the dumpsys command within a timeout # Führe den dumpsys-befehl innerhalb eines Timeout aus
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 # Überprüfe, ob das Ergebnis nicht leer ist und den Wecker enthält
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 "Wecker noch nicht beendet."
else else
date && echo "Alarm dismissed."
killall mpv killall mpv
date && echo "Wecker beendet."
echo "$output" echo "$output"
exit exit
fi fi
} }
# Main program # Hauptprogramm
# Turn off Bluetooth # Ausschalten von Bluetooth
turn_off_bluetooth turn_off_bluetooth
# Play alarm sound # Weckersound abspielen
/data/data/com.termux/files/usr/bin/mpv --replaygain=track --loop=inf /data/scripts/your-new-morning-alarm.ogg & /data/data/com.termux/files/usr/bin/mpv --replaygain=track --loop=inf /data/scripts/your-new-morning-alarm.ogg &
# Increase volume and check notification # Lautstärke erhöhen und Benachrichtigung überprüfen
while true; do while true; do
increase_volume increase_volume
check_notification check_notification
done done

View File

@ -9,20 +9,18 @@
# After 15 minutes, a color change is triggered. # After 15 minutes, a color change is triggered.
# Customizable settings: # Customizable settings:
# - Adjust ioBroker brightness and color temperature commands # - Adjust ioBroker brightness and color temperature commands
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
# Debug # Debug
debug=false DEBUG=false
ssh_executed=false # Variable to track SSH command status SSH_EXECUTED=false # Variable to track SSH command status
while getopts ":d" opt; do while getopts ":d" opt; do
case $opt in case $opt in
d) d)
debug=true DEBUG=true
;; ;;
\ß) \?)
echo "Invalid option: -$OPTARG" >&2 echo "Invalid option: -$OPTARG" >&2
exit 1 exit 1
;; ;;
@ -77,8 +75,8 @@ check_ip() {
if [ $i -lt $attempts ]; then if [ $i -lt $attempts ]; then
echo "Wait $interval seconds before the next attempt." echo "Wait $interval seconds before the next attempt."
if [ "$debug" = true ]; then if [ "$DEBUG" = true ]; then
echo "DEBUG: Skipping pause" echo "Debug: Skipping pause"
else else
sleep $interval sleep $interval
fi fi
@ -116,26 +114,25 @@ check_notification() {
# Execute the SSH command within a timeout # Execute the SSH command within a timeout
check_ip # Get IP check_ip # Get IP
if [ "$debug" = true ]; then if [ "$DEBUG" = true ]; then
echo "DEBUG: Bypassing check_notification." echo "DEBUG: Bypassing 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 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 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
return # Exit the function without terminating the entire script return # Exit the function without terminating the entire script
else else
# Phone unreachable # Phone unreachable
@ -163,14 +160,13 @@ end_colortemp=0 # Cool white (0)
# Duration of adjustment in seconds (15 minutes) # Duration of adjustment in seconds (15 minutes)
# Change every 30 seconds # Change every 30 seconds
change_interval_seconds=30 if [ "$DEBUG" = true ]; then
if [ "$debug" = true ]; then
duration_seconds=60 duration_seconds=60
steps=5 steps=5
echo "DEBUG: Set steps to $steps; and duration to $duration_seconds sec." echo "DEBUG: Set steps to $steps; and duration to $duration_seconds sec."
else else
duration_seconds=900 duration_seconds=900
steps=$((duration_seconds / change_interval_seconds)) steps=30 # Change every 30 (27) seconds
fi fi
# Calculate steps for brightness and color temperature per step # Calculate steps for brightness and color temperature per step
@ -204,7 +200,7 @@ for ((i = 1; i <= $steps; i++)); do
set_brightness "$current_brightness" set_brightness "$current_brightness"
set_colortemp "$current_colortemp" set_colortemp "$current_colortemp"
if [ "$debug" = true ]; then if [ "$DEBUG" = true ]; then
sleep 12 sleep 12
echo "DEBUG: Wait 12 sec. between steps." echo "DEBUG: Wait 12 sec. between steps."
else else
@ -229,15 +225,15 @@ echo "current_colortemp: $current_colortemp end_colortemp: $end_colortemp"
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 & 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.
} }
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 # Change colors for more concentration
while :; do while :; do
# Start the alarm script on the phone if the SSH command has not been executed yet. # Start the alarm script on the phone if the SSH command has not been executed yet.
if [ "$ssh_executed" = false ]; then if [ "$SSH_EXECUTED" = false ]; then
if [ "$debug" = true ]; then if [ "$DEBUG" = true ]; then
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
@ -254,4 +250,3 @@ if [ $current_brightness -eq $end_brightness ] && [ $current_colortemp -eq $end_
fi fi
done done
fi fi