Bash Script Hyperion (Ambilight) HDMI-CEC Steuerung

stinger2k

Lieutenant
Registriert
Feb. 2016
Beiträge
616
Hier ein Script um Hyperion Ambilight auf dem Raspberry und OpenElec mittels dem HDMI-CEC Status zu steuern.
Könnte auch für andere Prozesse zum starten oder beenden verwendet werden. Vielleicht hilft es jemanden ;)
Bash:
#!/bin/bash

######################################################################################
#Script Name    : hdmi-cec_check.sh
#Description    : Control any Process (hyperiond in this example) over HDMI-CEC States
#Args           :
#Author         : stinger2k
#EMail          : stinger2k@msn.com
######################################################################################
(
flock -n 9 || exit


while :; do
        echo -n "Checking CEC-State of TV(0)"
        wait_time="10"
        process="hyperiond"
        grep_proc=$(ps | pgrep -nl $process | sed 's/\// /g' | awk '{print $5 " "}' | sed 's/\ //g')
        status=$(echo "pow 0" | cec-client -s -d 1 | grep 'power status:' | (awk '{print $3 " "}') | sed 's/ //g')
        echo "Device is in State: $status"

        if [ "$status" == "standby" ] || [ "$status" == "in" ]; then
            echo "Device in 'standby' - nothing to do..."
            if  [ "$grep_proc" == "$process" ]; then
                echo "$process present"
                echo "Killing $process..."
                killall $process
            fi

            if ! [ "$grep_proc" == "$process" ]; then
                echo "Process '$process' not found..."
            fi
        fi

        if [ "$status" == "on" ]; then
            if ! [ "$grep_proc" == "$process" ]; then
                echo "$process not present..."
                echo "Starting $process..."
                . /storage/.config/autostart.sh
            fi
    
            if  [ "$grep_proc" == "$process" ]; then
                echo "$process running and Device is $status - System running normally..."
            fi
        fi

        for i in $(seq 1 1 $wait_time); do
            echo -en "\015\033[K Waiting $i from $wait_time seconds"
            sleep 1
        done
done
) 9>/tmp/cec.lck
 
Zuletzt bearbeitet:
  • Gefällt mir
Reaktionen: bart0rn, cruse und pumuck|
Danke fuer das Script, ich hatte mir auch mal eines gebastelt, allerdings fuer eine Multimedia Tastatur.

Darin enthalten sind die Funktionen:
  1. Ein/Aus
  2. Helligkeitssteuerung (50/65/85 & 100%)
  3. Switch von Externen Grabber auf Internen Grabber (nutze den Raspi mit Kodi)

Bei Gelenheit kann ich das ja mal mit rein hauen. 😊
 
  • Gefällt mir
Reaktionen: stinger2k
Zurück
Oben