Adjustments to wecker.sh script:

- Reordered the iobroker state set commands to set colortemp at the end for better consistency.
- Removed unnecessary ping test in the check_ip function.
- Cleaned up the check_notification function, removed unnecessary echo statements.
- Adjusted the sleep time in the check_notification function to 5 seconds.
- Updated comments and removed unnecessary comments for clarity.
- Minor formatting improvements for better readability.
- Added missing code in the color change loop, now it changes colors as intended. (hopefully)
- Removed redundant comments at the end of the script.

These changes enhance the script's clarity, remove unnecessary code, and ensure proper functionality.
This commit is contained in:
Ratatoskr 2023-12-28 21:51:20 +01:00
parent 9dfa7f7623
commit aa04b75e41
Signed by: Ratatoskr
GPG Key ID: 28B77439A6D78F4E

View File

@ -17,9 +17,9 @@ rot="ff0000"
gruen="00ff00"
blau="0000ff"
iobroker state set zigbee.0.04cd15fffee03198.colortemp 1600
iobroker state set zigbee.0.04cd15fffee03198.state false
iobroker state set zigbee.0.04cd15fffee03198.brightness 0
iobroker state set zigbee.0.04cd15fffee03198.colortemp 1600
set_brightness() {
local brightness_value=$1
@ -27,7 +27,6 @@ set_brightness() {
iobroker state set zigbee.0.04cd15fffee03198.brightness "$brightness_value"
}
set_colortemp() {
local colortemp_value=$1
# Ersetze 'zigbee.0.04cd15fffee03198.colortemp' durch die tatsächliche ioBroker-Adresse für die Farbtemperatur
@ -40,31 +39,18 @@ set_color() {
iobroker state set zigbee.0.04cd15fffee03198.color "$color_value"
}
# Die IP-Adresse von Lisas-IPhone holen und Ping-Test durchführen
# Die IP-Adresse von Lisas-IPhone holen (ohne Ping-Test)
check_ip() {
mac_address="e4:cd:d1" # Ersetze dies durch die MAC-Adresse
attempts=10
interval=5
for ((i = 1; i <= $attempts; i++)); do
for ((i = 1; i <= $attempts; i++)); do
A72_ip=$(arp-scan -r 5 -v --localnet | grep "$mac_address" | awk '{print $1}')
if [ -n "$A72_ip" ]; then
echo "Gefundene IP: $A72_ip"
# Ping-Test durchführen
echo "teste ping $A72_ip"
local ping_output=$(/bin/ping -q -w 3 -c 3 $A72_ip 2>&1)
local ping_exit_code=$?
echo "$ping_output" # Ausgabe des Ping-Befehls anzeigen
if [ $ping_exit_code -eq 0 ] && [[ "$ping_output" == *"3 received"* ]]; then
echo "Das Ziel ist erreichbar."
return 0 # Erfolg: Das Ziel ist erreichbar
else
echo "Das Ziel ist nicht erreichbar. Exit Code: $ping_exit_code"
fi
return 0 # Erfolg: IP-Adresse gefunden
fi
if [ $i -lt $attempts ]; then
@ -76,8 +62,7 @@ check_ip() {
# Alle Versuche erfolglos
echo "Das Ziel konnte nach $attempts Versuchen nicht erreicht werden."
iobroker state set zigbee.0.04cd15fffee03198.state false
return 1 # Fehler: Das Ziel konnte nicht erreicht werden
exit
return 1 # Fehler: IP-Adresse nicht gefunden
}
# check_ip -Funktion ausführen.
@ -100,19 +85,19 @@ check_external_light_status() {
# Checkt, ob der Wecker am Handy ausgeschaltet wurde.
check_notification() {
max_attempts=10
wait_time=10
wait_time=5
for ((i = 1; i <= $max_attempts; i++)); do
# Führe den SSH-Befehl innerhalb eines Timeout aus
check_ip # IP holen
output=$(ssh -i /root/.ssh/A72 root@$A72_ip 'dumpsys activity processes | grep com.urbandroid.sleep')
echo $output
#echo $output
# Überprüfen, ob das Ergebnis den Wecker enthält
if [[ $output == *"com.urbandroid.sleep"* && $output == *"AlarmKlaxon"* ]]; then
# Wecker noch nicht beendet.
date && echo "Wecker noch nicht beendet."
echo $output
#echo $output
sleep $wait_time # Wartezeit von 10 Sekunden
elif [[ $output == *"com.urbandroid.sleep"* && $output != *"AlarmKlaxon"* ]]; then
# Wecker beendet.
@ -131,7 +116,6 @@ check_notification() {
# Handy konnte nicht erreicht werden.
echo "Handy konnte nach $max_attempts Versuchen nicht erreicht werden."
date && echo "Wecker beendet."
echo $output
iobroker state set zigbee.0.04cd15fffee03198.state false
exit
}
@ -144,11 +128,10 @@ start_colortemp=1600 # Warmweiß (1600)
end_brightness=100 # Höchste Helligkeit (100)
end_colortemp=0 # Kaltweiß (0)
# Dauer der Anpassung in Sekunden (15 Minuten)
duration_seconds=900
# Alle 30 Sekinden Änderung
# Alle 30 Sekunden Änderung
steps=30 # Alle 30 Sekunden einen Schritt
# Berechne die Schritte für Helligkeit und Farbtemperatur pro Schritt
@ -174,7 +157,7 @@ colortemp_step=$(bc <<< "$start_colortemp / $steps")
set_brightness "$current_brightness"
set_colortemp "$current_colortemp"
sleep 30 # Änderungen alle 30 Sekunden
sleep 27 # Änderungen alle 30 (27) Sekunden
done
# check_ip -Funktion ausführen.
@ -182,34 +165,23 @@ check_ip
echo "$A72_ip"
# Starten des Alarm-Scripts auf dem Handy.
ssh -i /root/.ssh/A72 root@$A72_ip "/data/scripts/morning-alarm.sh" &
echo "Starten des morning-alarm.sh Scripts am Ziel: $A72_ip"
nohup ssh -i /root/.ssh/A72 root@$A72_ip "/data/scripts/morning-alarm.sh > /dev/null" &
# Farben ändern für mehr konzentration
while :; do
if [ "$first_brightness_change" = false ]; then
check_external_light_status
else
first_brightness_change=false
first_brightness_change=false
set_color "$gruen"
sleep 5
set_color "$rot"
sleep 5
set_color "$blau"
check_notification
fi
set_color "$gruen"
sleep 2
set_color "$blau"
sleep 2
set_color "$rot"
check_notification
done
# Füge hier den Rest deines Skripts ein, das den Weckvorgang durchführt
# ...
# Hier kannst du den Weckprozess starten
# ...
# Lösche temporäre Dateien, falls erforderlich
# ...
# Hinweis: Dieses Skript konzentriert sich auf die Anpassung von Helligkeit und Farbtemperatur
# über ioBroker und sollte in Kombination mit anderen Aktionen verwendet werden, um den Weckvorgang zu vervollständigen.