#!/bin/bash # ------------------------------------------- # Script: Dynamic Light Adjustment # Author: Michael # Created: 2025-01-02 # Purpose: Adjust light color temperature and brightness dynamically while ioBroker state is true. # Usage: ./dynamic_light_adjustment.sh # ------------------------------------------- # Konfiguration STATE_ID="zigbee.0.04cd15fffee03198.state" BRIGHTNESS_ID="zigbee.0.04cd15fffee03198.brightness" COLORTEMP_ID="zigbee.0.04cd15fffee03198.colortemp" BRIGHTNESS_MIN=0 BRIGHTNESS_MAX=100 COLORTEMP_MIN=0 COLORTEMP_MAX=1600 STEP_BRIGHTNESS=5 STEP_COLORTEMP=80 # Funktion: State abrufen get_state() { # Hole den JSON-Wert und prüfe, ob "val" true ist state_value=$(iobroker state get "$STATE_ID" | grep -oP '"val":\s*\K(true|false)') [[ "$state_value" == "true" ]] } # Funktion: Brightness setzen set_brightness() { /usr/bin/iobroker state set "$BRIGHTNESS_ID" "$1" echo "Set brightness to $1" } # Funktion: Colortemp setzen set_colortemp() { /usr/bin/iobroker state set "$COLORTEMP_ID" "$1" echo "Set colortemp to $1" } # Initialwerte current_brightness=$BRIGHTNESS_MIN current_colortemp=$COLORTEMP_MAX brightness_increasing=true colortemp_increasing=false # Licht einmal einschalten, falls der State aktiv ist set_brightness $BRIGHTNESS_MIN set_colortemp $COLORTEMP_MAX /usr/bin/iobroker state set "$STATE_ID" true echo "Initial light settings applied." # Hauptschleife while get_state; do # Helligkeit anpassen if $brightness_increasing; then current_brightness=$((current_brightness + STEP_BRIGHTNESS)) if [ $current_brightness -ge $BRIGHTNESS_MAX ]; then brightness_increasing=false fi else current_brightness=$((current_brightness - STEP_BRIGHTNESS)) if [ $current_brightness -le $BRIGHTNESS_MIN ]; then brightness_increasing=true fi fi set_brightness $current_brightness # Farbtemperatur anpassen if $colortemp_increasing; then current_colortemp=$((current_colortemp - STEP_COLORTEMP)) if [ $current_colortemp -le $COLORTEMP_MIN ]; then colortemp_increasing=false fi else current_colortemp=$((current_colortemp + STEP_COLORTEMP)) if [ $current_colortemp -ge $COLORTEMP_MAX ]; then colortemp_increasing=true fi fi set_colortemp $current_colortemp # Wartezeit für sanfte Übergänge sleep 1 done # Beenden echo "State is false. Exiting script."