Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Title: ISS Fade Light Controller Script
- #
- # Abstract: This Bash script is designed for home automation systems and
- # controls a Philips Hue light to simulate the International Space Station
- # (ISS) passing overhead. The script prevents multiple instances from
- # running simultaneously. It sets up a logging system in a specified
- # directory, where it records the details of each operation. The script
- # contains key functions: 'iss_fade' for adjusting the light's brightness,
- # 'iss_color' for changing the light's color, and 'iss_start' for
- # initiating the light sequence. It takes two parameters: the duration of
- # the light effect and the start time, to align with the ISS's visible
- # pass. The script incrementally increases the light's brightness to
- # simulate the ISS's approach, changes the color to signify the ISS at its
- # brightest, and then gradually dims the light, emulating the ISS moving
- # away, finally turning the light off. This script provides a unique and
- # interactive way to experience ISS passes using home lighting systems.
- #
- # hue lights are controlled by
- # https://github.com/bahamas10/hue-cli
- # Wenn das Programm schon laeuft, dann direkt abbrechen. Kein Logfile beschreiben.
- current_pid=$$
- # Prüfen, ob das Programm bereits läuft (ohne die aktuelle Instanz)
- if pgrep -f "iss-fader.sh" | grep -qv "^$current_pid\$"; then
- echo "Programm wartet bereits auf einen Start. Abbruch."
- exit 1
- fi
- ## DEBUG
- # Der Basispfad, unter dem der neue Ordner erstellt werden soll
- base_path="/var/log/"
- # Generieren der aktuellen Epoch-Zeit
- epoch_time=$(date +%s)
- jetzt=$(date -d @"$epoch_time" '+%d.%m., %H:%M:%S Uhr')
- # Vollständiger Pfad für den neuen Ordner
- new_folder="${base_path}1/"
- # Erstellen des neuen Ordners
- #mkdir -p "$new_folder"
- echo "bash /volume1/web/iss-fader.sh" > "${new_folder}/script.log"
- echo "Debug iss-fader.sh" > "${new_folder}/output.log"
- ## DEBUG
- # Funktionen
- iss_fade() {
- echo "iss_fade($level)" >> "${new_folder}/output.log"
- level=$1
- if [[ $level -eq 0 ]]; then
- /usr/local/bin/hue -H 192.168.0.90 lights 3 off >> "${new_folder}/output.log" 2>&1
- else
- /usr/local/bin/hue -H 192.168.0.90 lights 3 =$level% >> "${new_folder}/output.log" 2>&1
- fi
- }
- iss_color() {
- echo "iss_color($color)" >> "${new_folder}/output.log"
- color=$1
- /usr/local/bin/hue -H 192.168.0.90 lights 3 $color >> "${new_folder}/output.log" 2>&1
- }
- iss_start() {
- echo "iss_start()" >> "${new_folder}/output.log"
- /usr/local/bin/hue -H 192.168.0.90 lights 3 on >> "${new_folder}/output.log" 2>&1
- /usr/local/bin/hue -H 192.168.0.90 lights 3 =1% >> "${new_folder}/output.log" 2>&1
- }
- # Funktionen
- # Parameter übernehmen
- dauer="$1"
- aufgang="$2"
- start=$(date -d @"$aufgang" '+%d.%m., %H:%M:%S Uhr')
- echo "ISS Fade mit $dauer Sekunden um $aufgang" >>"${new_folder}/output.log"
- # Warten bis zum ISS Aufgang
- echo "Aktuelle Zeit: $jetzt" >> "${new_folder}/output.log"
- echo "Schlafe bis: $start" >> "${new_folder}/output.log"
- echo "...zzz..." >> "${new_folder}/output.log"
- sleep $((aufgang - $(date +%s)))
- echo "Aufgewacht. $(date +%s)" >> "${new_folder}/output.log"
- stufen=20 # Anzahl Helligkeitsstufen
- dim=10 # Starthelligkeit
- dimstep=10 # Erhöhung pro Stufe in Prozent
- intervall=$((dauer / stufen))
- fade=false
- # Anfangs an und auf gelb
- iss_start
- sleep 1
- iss_color "00ffff"
- sleep 1
- for ((i=1; i<=stufen; i++)); do
- iss_fade $dim
- sleep $intervall
- # Volle Helligkeit erreicht, Farbe auf orange
- if [[ $dim -ge 100 ]]; then
- fade=true
- iss_color "ff8500"
- fi
- # Zunehmend oder abnehmend
- if [ "$fade" = false ]; then
- dim=$((dim + dimstep))
- else
- dim=$((dim - dimstep))
- fi
- done
- # Ende, Lampe aus
- iss_fade 0
- echo >> "${new_folder}/output.log"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement