1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Bash script to turn off/on LEDs with HDMI-CEC

Discussion in 'Hyperion General' started by RaPiiDe, 30 November 2019.

  1. RaPiiDe

    RaPiiDe New Member

    Messages:
    1
    Hardware:
    RPi3
    Hello guys!

    I've made a little script to turn off my LEDs when my AVR turns off and vice versa. It uses the CEC-Client, so it should work with everyone as long as your devices are HDMI-CEC compliant.

    The instructions to install it are included in the top part of the script. It's a pretty simple script so it shouldn't be a big deal to make it work.

    PHP:
    #!/bin/bash

    # Script for hyperion which allows you to turn off your LEDs when your AVR is off and vice versa.
    # Tested with Raspian on an RPi3
    # 1 - Plug your RPi with an HDMI cable on your AVR
    # 2 - Copy the script on your RPi
    # 3 - Run sudo chmod +x on the script
    # 4 - To make it run at startup, add   @reboot /your/path/yourscriptname.sh    to crontab -e
    # 5 - Enjoy

    # RaPiiDe

    remotePath="hyperion-remote"
    isOn=-1

    while :
    do
            
    # We get the CEC status
            
    status=$(echo pow 0 timeout 5 cec-client -d 1 -s)
            
    # If it's off and it wasn't already, let's turn off the LEDS
            
    if [[ "$status== *"power status: standby"* ]] && [[ "$isOn!= "0" ]]
            
    then
                    
    eval "$remotePath --priority 0 --color black"
                    
    isOn=0
            
    # If it's on and it wasn't already, let's turn on the LEDS
            
    elif [[ "$status== *"power status: on"* ]] && [[ "$isOn!= "1" ]]
            
    then
                    
    eval "$remotePath --clearall"
                    
    isOn=1
            fi

            sleep 2
    done
    Have fun!