Compare commits

..

6 Commits

Author SHA1 Message Date
53000fc607
Refactor wecker.sh script
- Commented out 'set -e' and 'set -x' to prevent stopping the script on errors and disable debugging by default.
- Introduced functions set_brightness, set_colortemp, and set_color for better code organization.
- Modified brightness and color temperature commands to use the new functions.
2024-01-27 00:21:00 +01:00
122fdc6669
Added generate_text.sh script:
- 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.
- The script includes functions to check the IP address of Lisa's iPhone, generate text files in German and Spanish, transfer files to the A72 device, and start generate_mp3.sh on the A72.
- The generated texts are outputted in both German and Spanish.
2024-01-26 23:50:24 +01:00
e2b06dab34
Initial commit
Added generate_mp3.sh script:
- Author: Michael Haider
- Created on: 26.01.2024
- Description: This script generates MP3 files from text files in German and Spanish using gtts-cli (Google Text-to-Speech).
- The script exports the path to the programs, defines language and category order, sets directories, and includes a function to create MP3 files.
- The generated MP3 files are created with gtts-cli in German or Spanish slow mode based on the file content.
- The script then sets the media volume and loops through categories and languages to play the generated MP3 files at normal or half speed, based on the language indication.
2024-01-26 23:49:50 +01:00
6d5ce74f08
Refactor wecker.sh script
Made the following changes to the wecker.sh script:
- Adjusted comments and translated the comments and script messages into English for better clarity.
- Introduced error handling for SSH commands, Bluetooth operations, and volume adjustments to ensure the script exits gracefully in case of failures.
- Updated variable names for consistency and improved overall readability of the script.
- Removed unnecessary debug-related code and streamlined the script structure.
- Addressed formatting issues for better code presentation.
2024-01-26 23:47:53 +01:00
fe66c936c4
Refactor morning-alarm.sh script
Adjusted comments and translated the comments and script messages into English for better clarity. The script now provides more informative output during its execution, including status messages for Bluetooth operations, volume adjustment, and alarm notification checks. Additionally, introduced error handling for Bluetooth and volume adjustment operations to ensure the script exits gracefully in case of failures.

The main program section and function names have been retained for continuity, but the script's overall readability and understandability have been improved through language translation and comments rephrasing.
2024-01-26 23:47:02 +01:00
4bb7048638
Fix weckzeit_datei path in A72_alarm_getter.sh
Corrected the path for the 'weckzeit_datei' variable in A72_alarm_getter.sh script. The original path was pointing to '/root/iobroker_scripts/generel/.weckzeiten.txt' and has been updated to the correct path '/root/iobroker_scripts/general/.weckzeiten.txt'.

This ensures that the script can accurately locate and utilize the 'weckzeit_datei' file, preventing potential issues related to the incorrect file path.
2024-01-26 23:45:34 +01:00
5 changed files with 187 additions and 38 deletions

View File

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

73
generate_mp3.sh Normal file
View File

@ -0,0 +1,73 @@
#!/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

70
generate_text.sh Executable file
View File

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

View File

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