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

  • 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.



    Have fun!

  • Hallo
    Klingt interessant, aber habe von der Materie keine Ahnung.
    Der Raspberry ist am TV angeschlossen, somit also auch Cec möglich.
    Wo müsste ich die Datei einfügen?


    I don't speak German so I'm going to answer in English.


    First, you need to copy the script on the raspberry, you've got at least 2 ways to do it. Copy/paste the text in a new file via SSH (with Putty) or you could copy the file via SFTP (Winscp or Filezilla can do that).

  • [QUOTE = "RaPiiDe, post: 30626, member: 5271"]


    Dies erfordert Sie das Skript auf die Himbeere kopieren. Sie haben mindestens zwei mögliche, stirbt zu tun. Kopieren Sie den Text in einer neuen Datei über SSH (mit Putty) oder Steuern Sie ihn über SFTP ein (Winscp oder Filezilla können das). [/ QUOTE]
    Hallo danke für die Rückmeldung.
    Wo muss denn die Datei genau hin, habe das Image Raspbian jes. Installiert.
    Benutze kein Kodi auf dem Himbeere, nur extern.


    Thank you for your answer
    I don't know where to insert the script? In which folder or path do I have to paste the script

  • Hi,
    I've had to fight a bit with it too before getting it to work !!


    First, I'm on windows and created the xxx.sh file with notepad++
    Thing is, windows uses CRLF instead of LF for line feeds...
    That's why it didn't work in the first place.
    If you use notepadd++ too, just double click on the "windows CRLF" text in the bottom-right of the window and choose "convert to UNIX LF" and save.
    Next problem was that I'm on Hyperbian, and it looks like the CEC package was not installed.
    So I ran this command in SSH :
    sudo apt-get install cec-utils


    After this, a simple reboot and it started to work !!!
    Very nice replacement for the signal detection.

  • Hi there
    Thanks for the information.
    I had installed the cec package and inserted the file with wincp
    But maybe I'm doing something wrong.


    I don't understand that at all:
    # 4 - So that it will at startup, you will crontab @reboot /your/path/yourscriptname.sh

  • Ok.
    First, how did you "create" the .sh file ?
    if it is on windows, you'll have the line feed problem as I mentioned, and you need to fix this otherwise it won't work.
    Second, the crontab part is mandatory.
    SSH to your pi (with putty) and then execute this command :
    crontab -e


    This will open a file editor with lot of comments.
    Add this line at the end of the file :
    @reboot /path/to/your/script.sh
    and save.


    Then reboot the Pi and you're good to go.

  • Hi
    There is the script, where do I have to change that? With remotePath = "PathToYourHyperion-remote" I have to enter the correct path?


    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 fu


    Can you show me your Skript please

    • Offizieller Beitrag

    Normally, there is no need to send Black when you disable a Led device.
    Depending on the Led type, the LEDs are set to black while switching off.
    Other led types, eg the network ones, the device is switched off via API.


    Writing black is only a solution for a subset of devices....

  • Normally, there is no need to send Black when you disable a Led device.
    Depending on the Led type, the LEDs are set to black while switching off.
    Other led types, eg the network ones, the device is switched off via API.


    Writing black is only a solution for a subset of devices....


    Thanks for the info.
    So what should we change the commands to enable/disable the led device according to CEC state instead of setting it to black ?
    Thanks in advance.


    EDIT: I mean instead of this command :
    eval "$remotePath --priority 0 --color black"

    • Offizieller Beitrag

    @NeeeeB Please check, if the following works with you:


    Code
    ./hyperion-remote --disable LEDDEVICE
    
    
    ./hyperion-remote --enable LEDDEVICE


    The behavior is as you would disable/enable the LED-Device via the Remote-Control in the UI

  • @NeeeeB Please check, if the following works with you:


    Code
    ./hyperion-remote --disable LEDDEVICE
    
    
    ./hyperion-remote --enable LEDDEVICE


    The behavior is as you would disable/enable the LED-Device via the Remote-Control in the UI


    Ah great !!
    Much better than setting it to black ofc.
    Do I have to replace "LEDDEVICE" with something (e.g name of the instance) or will it work as is ?

    • Offizieller Beitrag

    Sorry, if you using multiple instances, you can provide the instance via "--instance instancename" as an additional parameter:
    If you leave it out the default instance is used.


    Code
    ./hyperion-remote --instance 'Nanoleaf' --disable LEDDEVICE


    To see all capabilities of hyperion-remote, just do a


    Code
    ./hyperion-remote --help


    This might give you additional ideas, too ... :)

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!