add phillips hue sync script
This commit is contained in:
parent
dc78f2307c
commit
63d7f1d6bf
1 changed files with 37 additions and 0 deletions
37
scripts/executable_phillips_hue-sync.sh
Normal file
37
scripts/executable_phillips_hue-sync.sh
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
# Konfiguration
|
||||||
|
screenshot_path="$HOME/Desktop/screenshot.png"
|
||||||
|
bridge_ip='192.168.1.115'
|
||||||
|
username='Jhw0h63UZOXZCkGsRUvMtAH7kbjWEe1YS1xh0yrl'
|
||||||
|
light_id='7'
|
||||||
|
|
||||||
|
# 1. Screenshot erstellen
|
||||||
|
spectacle -b -f -n -o $screenshot_path
|
||||||
|
|
||||||
|
# 2. Durchschnittliche Farbe des Screenshots berechnen und in Ganzzahlen konvertieren
|
||||||
|
average_color=$(convert $screenshot_path -resize 1x1\! -format "%[pixel:u]" info:- | tr -d ' ' | sed 's/.*[(]\(.*\)[)].*/\1/' | tr -d '%')
|
||||||
|
IFS=',' read r g b _ <<< "$average_color"
|
||||||
|
|
||||||
|
# Konvertiere Fließkommazahlen zu Ganzzahlen mit awk
|
||||||
|
r=$(echo $r | awk '{printf "%.0f", $1}')
|
||||||
|
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)
|
||||||
|
hue=$((r * 65535 / 255))
|
||||||
|
saturation=$((g * 254 / 255))
|
||||||
|
brightness=$((b * 254 / 255))
|
||||||
|
|
||||||
|
# 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!"
|
Loading…
Reference in a new issue