diff --git a/wecker.sh b/wecker.sh index f1df39f..be51b73 100755 --- a/wecker.sh +++ b/wecker.sh @@ -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 + # 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 ;; @@ -39,26 +41,6 @@ iobroker state set zigbee.0.04cd15fffee03198.brightness 1 iobroker state set zigbee.0.04cd15fffee03198.colortemp 1600 iobroker state set zigbee.0.04cd15fffee03198.state true -set_brightness() { - local brightness_value=$1 - # Replace 'zigbee.0.04cd15fffee03198.brightness' with the actual ioBroker address for brightness - iobroker state set zigbee.0.04cd15fffee03198.brightness "$brightness_value" - echo "Current brightness: $brightness_value" -} - -set_colortemp() { - local colortemp_value=$1 - # Replace 'zigbee.0.04cd15fffee03198.colortemp' with the actual ioBroker address for color temperature - iobroker state set zigbee.0.04cd15fffee03198.colortemp "$colortemp_value" - echo "Current Colortemp: $colortemp_value" -} - -set_color() { - local color_value=$1 - # Replace 'zigbee.0.04cd15fffee03198.color' with the actual ioBroker address for color - iobroker state set zigbee.0.04cd15fffee03198.color "$color_value" -} - # Get the IP address of Lisa's iPhone (without ping test) check_ip() { mac_address="e4:cd:d1" # Replace this with the MAC address @@ -75,8 +57,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 +96,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 +143,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 +184,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 +209,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"