Compare commits
6 Commits
d68beee2b8
...
53000fc607
| Author | SHA1 | Date | |
|---|---|---|---|
| 53000fc607 | |||
| 122fdc6669 | |||
| e2b06dab34 | |||
| 6d5ce74f08 | |||
| fe66c936c4 | |||
| 4bb7048638 |
@ -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/generel/.weckzeiten.txt"
|
weckzeit_datei="/root/iobroker_scripts/general/.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)
|
||||||
|
|||||||
73
generate_mp3.sh
Normal file
73
generate_mp3.sh
Normal 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
70
generate_text.sh
Executable 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"
|
||||||
@ -1,50 +1,51 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# Wecker-Steuerungsskript
|
# Alarm Control Script
|
||||||
#
|
#
|
||||||
# Dieses Skript steuert den Wecker auf dem Android-Gerät.
|
# This script controls the alarm on the Android device.
|
||||||
# Es schaltet Bluetooth aus, erhöht die Lautstärke und überprüft, ob der Wecker beendet wurde.
|
# It turns off Bluetooth, increases the volume, and checks if the alarm has been dismissed.
|
||||||
# Nach dem Beenden des Weckers wird der Weckersound abgespielt.
|
# 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() {
|
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() {
|
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() {
|
check_notification() {
|
||||||
# Führe den dumpsys-befehl innerhalb eines Timeout aus
|
# Run the dumpsys command within a timeout
|
||||||
output=$(dumpsys activity processes | grep "com.urbandroid.sleep/")
|
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
|
if [ -n "$output" ] && echo "$output" | grep -q "AlarmKlaxon"; then
|
||||||
date && echo "Wecker noch nicht beendet."
|
date && echo "Alarm not dismissed yet."
|
||||||
else
|
else
|
||||||
|
date && echo "Alarm dismissed."
|
||||||
killall mpv
|
killall mpv
|
||||||
date && echo "Wecker beendet."
|
|
||||||
echo "$output"
|
echo "$output"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Hauptprogramm
|
# Main program
|
||||||
|
|
||||||
# Ausschalten von Bluetooth
|
# Turn off 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 &
|
/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
|
while true; do
|
||||||
increase_volume
|
increase_volume
|
||||||
check_notification
|
check_notification
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
39
wecker.sh
39
wecker.sh
@ -9,18 +9,20 @@
|
|||||||
# 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 -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
|
||||||
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
|
||||||
;;
|
;;
|
||||||
@ -75,8 +77,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
|
||||||
@ -114,25 +116,26 @@ 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
|
||||||
@ -160,13 +163,14 @@ 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
|
||||||
if [ "$DEBUG" = true ]; then
|
change_interval_seconds=30
|
||||||
|
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=30 # Change every 30 (27) seconds
|
steps=$((duration_seconds / change_interval_seconds))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Calculate steps for brightness and color temperature per step
|
# 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_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
|
||||||
@ -225,15 +229,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
|
||||||
@ -250,3 +254,4 @@ if [ $current_brightness -eq $end_brightness ] && [ $current_colortemp -eq $end_
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user