add phillips hue sync script
This commit is contained in:
parent
63d7f1d6bf
commit
9c3c65387f
2 changed files with 48 additions and 27 deletions
|
@ -3,3 +3,5 @@
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
wl-paste -t text --watch clipman store &
|
wl-paste -t text --watch clipman store &
|
||||||
|
|
||||||
|
~/scripts/phillips_hue-sync.sh &
|
||||||
|
|
|
@ -1,37 +1,56 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -ex
|
#set -ex
|
||||||
|
|
||||||
# Konfiguration
|
while true; do
|
||||||
screenshot_path="$HOME/Desktop/screenshot.png"
|
|
||||||
bridge_ip='192.168.1.115'
|
|
||||||
username='Jhw0h63UZOXZCkGsRUvMtAH7kbjWEe1YS1xh0yrl'
|
|
||||||
light_id='7'
|
|
||||||
|
|
||||||
# 1. Screenshot erstellen
|
# Konfiguration
|
||||||
spectacle -b -f -n -o $screenshot_path
|
screenshot_path="$HOME/Desktop/screenshot.png"
|
||||||
|
bridge_ip='192.168.1.115'
|
||||||
|
username='Jhw0h63UZOXZCkGsRUvMtAH7kbjWEe1YS1xh0yrl'
|
||||||
|
light_id='7'
|
||||||
|
|
||||||
# 2. Durchschnittliche Farbe des Screenshots berechnen und in Ganzzahlen konvertieren
|
# Test, ob die Bridge erreichbar ist
|
||||||
average_color=$(convert $screenshot_path -resize 1x1\! -format "%[pixel:u]" info:- | tr -d ' ' | sed 's/.*[(]\(.*\)[)].*/\1/' | tr -d '%')
|
max_attempts=10
|
||||||
IFS=',' read r g b _ <<< "$average_color"
|
attempt=0
|
||||||
|
while ! ping -c 1 $bridge_ip &>/dev/null; do
|
||||||
|
attempt=$((attempt+1))
|
||||||
|
echo "Versuch $attempt von $max_attempts: Bridge nicht erreichbar, warte 10 Sekunden..."
|
||||||
|
if [ $attempt -ge $max_attempts ]; then
|
||||||
|
echo "Bridge nach $max_attempts Versuchen nicht erreichbar, breche Skript ab."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
|
||||||
# Konvertiere Fließkommazahlen zu Ganzzahlen mit awk
|
# 1. Screenshot erstellen
|
||||||
r=$(echo $r | awk '{printf "%.0f", $1}')
|
spectacle -b -f -n -o $screenshot_path
|
||||||
g=$(echo $g | awk '{printf "%.0f", $1}')
|
|
||||||
b=$(echo $b | awk '{printf "%.0f", $1}')
|
|
||||||
|
|
||||||
# Einfache Umrechnung der RGB-Werte für die Hue API (diese Werte sind stark angenähert)
|
# 2. Durchschnittliche Farbe des Screenshots berechnen und in Ganzzahlen konvertieren
|
||||||
hue=$((r * 65535 / 255))
|
average_color=$(convert $screenshot_path -resize 1x1\! -format "%[pixel:u]" info:- | tr -d ' ' | sed 's/.*[(]\(.*\)[)].*/\1/' | tr -d '%')
|
||||||
saturation=$((g * 254 / 255))
|
IFS=',' read r g b _ <<< "$average_color"
|
||||||
brightness=$((b * 254 / 255))
|
|
||||||
|
|
||||||
# 4. Farbe an Philips Hue Lampe senden
|
# Konvertiere Fließkommazahlen zu Ganzzahlen mit awk
|
||||||
echo "Senden der Farbe Hue: $hue, Saturation: $saturation, Brightness: $brightness an Lampe $light_id"
|
r=$(echo $r | awk '{printf "%.0f", $1}')
|
||||||
|
g=$(echo $g | awk '{printf "%.0f", $1}')
|
||||||
|
b=$(echo $b | awk '{printf "%.0f", $1}')
|
||||||
|
|
||||||
# Hier würde der tatsächliche Befehl zum Senden der Farbe stehen.
|
# Einfache Umrechnung der RGB-Werte für die Hue API (diese Werte sind stark angenähert)
|
||||||
url="http://${bridge_ip}/api/${username}/lights/${light_id}/state"
|
hue=$((r * 65535 / 255))
|
||||||
payload="{\"on\": true, \"sat\": $saturation, \"bri\": $brightness, \"hue\": $hue}"
|
saturation=$((g * 254 / 255))
|
||||||
response=$(curl --request PUT --data "$payload" $url)
|
brightness=$((b * 254 / 255))
|
||||||
echo $response
|
|
||||||
|
|
||||||
echo "Farbe erfolgreich gesendet!"
|
# 4. Farbe an Philips Hue Lampe senden
|
||||||
|
echo "Senden der Farbe Hue: $hue, Saturation: $saturation, Brightness: $brightness an Lampe $light_id"
|
||||||
|
|
||||||
|
# Hier würde der tatsächliche Befehl zum Senden der Farbe stehen.
|
||||||
|
url="http://${bridge_ip}/api/${username}/lights/${light_id}/state"
|
||||||
|
payload="{\"on\": true, \"sat\": $saturation, \"bri\": $brightness, \"hue\": $hue}"
|
||||||
|
response=$(curl --request PUT --data "$payload" $url)
|
||||||
|
echo $response
|
||||||
|
|
||||||
|
echo "Farbe erfolgreich gesendet!"
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
done
|
||||||
|
|
Loading…
Reference in a new issue