Advertisement
Halbheld

ISS Fade Light Controller Script

Feb 6th, 2024
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.86 KB | Science | 0 0
  1. #!/bin/bash
  2.  
  3. # Title: ISS Fade Light Controller Script
  4. #
  5. # Abstract: This Bash script is designed for home automation systems and
  6. # controls a Philips Hue light to simulate the International Space Station
  7. # (ISS) passing overhead. The script prevents multiple instances from
  8. # running simultaneously. It sets up a logging system in a specified
  9. # directory, where it records the details of each operation. The script
  10. # contains key functions: 'iss_fade' for adjusting the light's brightness,
  11. # 'iss_color' for changing the light's color, and 'iss_start' for
  12. # initiating the light sequence. It takes two parameters: the duration of
  13. # the light effect and the start time, to align with the ISS's visible
  14. # pass. The script incrementally increases the light's brightness to
  15. # simulate the ISS's approach, changes the color to signify the ISS at its
  16. # brightest, and then gradually dims the light, emulating the ISS moving
  17. # away, finally turning the light off. This script provides a unique and
  18. # interactive way to experience ISS passes using home lighting systems.
  19. #
  20. # hue lights are controlled by
  21. # https://github.com/bahamas10/hue-cli
  22.  
  23. # Wenn das Programm schon laeuft, dann direkt abbrechen. Kein Logfile beschreiben.
  24. current_pid=$$
  25. # Prüfen, ob das Programm bereits läuft (ohne die aktuelle Instanz)
  26. if pgrep -f "iss-fader.sh" | grep -qv "^$current_pid\$"; then
  27.     echo "Programm wartet bereits auf einen Start. Abbruch."
  28.     exit 1
  29. fi
  30.  
  31.  
  32.  
  33. ## DEBUG
  34. # Der Basispfad, unter dem der neue Ordner erstellt werden soll
  35. base_path="/var/log/"
  36.  
  37. # Generieren der aktuellen Epoch-Zeit
  38. epoch_time=$(date +%s)
  39. jetzt=$(date -d @"$epoch_time" '+%d.%m., %H:%M:%S Uhr')
  40.  
  41. # Vollständiger Pfad für den neuen Ordner
  42. new_folder="${base_path}1/"
  43.  
  44. # Erstellen des neuen Ordners
  45. #mkdir -p "$new_folder"
  46.  
  47. echo "bash /volume1/web/iss-fader.sh" > "${new_folder}/script.log"
  48. echo "Debug iss-fader.sh" > "${new_folder}/output.log"
  49. ## DEBUG
  50.  
  51.  
  52. # Funktionen
  53. iss_fade() {
  54.     echo "iss_fade($level)" >> "${new_folder}/output.log"
  55.     level=$1
  56.     if [[ $level -eq 0 ]]; then
  57.         /usr/local/bin/hue -H 192.168.0.90 lights 3 off >> "${new_folder}/output.log" 2>&1
  58.     else
  59.         /usr/local/bin/hue -H 192.168.0.90 lights 3 =$level% >> "${new_folder}/output.log" 2>&1
  60.     fi
  61. }
  62.  
  63. iss_color() {
  64.     echo "iss_color($color)" >> "${new_folder}/output.log"
  65.     color=$1
  66.     /usr/local/bin/hue -H 192.168.0.90 lights 3 $color >> "${new_folder}/output.log" 2>&1
  67. }
  68.  
  69. iss_start() {
  70.     echo "iss_start()" >> "${new_folder}/output.log"
  71.     /usr/local/bin/hue -H 192.168.0.90 lights 3 on >> "${new_folder}/output.log" 2>&1
  72.     /usr/local/bin/hue -H 192.168.0.90 lights 3 =1% >> "${new_folder}/output.log" 2>&1
  73. }
  74. # Funktionen
  75.  
  76.  
  77. # Parameter übernehmen
  78. dauer="$1"
  79. aufgang="$2"
  80. start=$(date -d @"$aufgang" '+%d.%m., %H:%M:%S Uhr')
  81.  
  82. echo "ISS Fade mit $dauer Sekunden um $aufgang" >>"${new_folder}/output.log"
  83.  
  84. # Warten bis zum ISS Aufgang
  85. echo "Aktuelle Zeit: $jetzt" >> "${new_folder}/output.log"
  86. echo "Schlafe bis:   $start"  >> "${new_folder}/output.log"
  87. echo "...zzz..."  >> "${new_folder}/output.log"
  88. sleep $((aufgang - $(date +%s)))
  89. echo "Aufgewacht. $(date +%s)" >> "${new_folder}/output.log"
  90.  
  91. stufen=20    # Anzahl Helligkeitsstufen
  92. dim=10       # Starthelligkeit
  93. dimstep=10   # Erhöhung pro Stufe in Prozent
  94.  
  95. intervall=$((dauer / stufen))
  96. fade=false
  97.  
  98. # Anfangs an und auf gelb
  99. iss_start
  100. sleep 1
  101. iss_color "00ffff"
  102. sleep 1
  103.  
  104. for ((i=1; i<=stufen; i++)); do
  105.     iss_fade $dim
  106.     sleep $intervall
  107.  
  108.     # Volle Helligkeit erreicht, Farbe auf orange
  109.     if [[ $dim -ge 100 ]]; then
  110.         fade=true
  111.         iss_color "ff8500"
  112.     fi
  113.  
  114.     # Zunehmend oder abnehmend
  115.     if [ "$fade" = false ]; then
  116.         dim=$((dim + dimstep))
  117.     else
  118.         dim=$((dim - dimstep))
  119.     fi
  120. done
  121.  
  122. # Ende, Lampe aus
  123. iss_fade 0
  124. echo >> "${new_folder}/output.log"
  125.  
Tags: iss hue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement