RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    SupaCEC - A utility to switch TV inputs when a controller is connected

    Scheduled Pinned Locked Moved Ideas and Development
    cecpackagespackagehdmi cechdmi
    29 Posts 8 Posters 6.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      psyke83 Global Moderator @Sano
      last edited by

      @Sano

      This should work:

      ACTION=="add", SUBSYSTEM=="input", RUN+="/bin/bash -c 'echo 'as' | cec-client -s -d 1'"

      I actually tested this (as someone else is using the tv):
      ACTION=="add", SUBSYSTEM=="input", RUN+="/bin/bash -c 'echo test | tee /dev/kmsg'"

      For some reason, "test" is echoed three times to the kernel log & I'm not certain precisely why...

      SanoS 1 Reply Last reply Reply Quote 1
      • SanoS
        Sano @psyke83
        last edited by Sano

        @psyke83 said in SupaCEC - A utility to switch TV inputs when a controller is connected:

        This should work:

        ACTION=="add", SUBSYSTEM=="input", RUN+="/bin/bash -c 'echo 'as' | cec-client -s -d 1'"

        Sorry, still no luck :(
        But thanks a lot for trying !

        For some reason, "test" is echoed three times to the kernel log & I'm not certain precisely why...

        That I know :)
        just run an sudo udevadm monitor -e before pluging anything
        It's just the kernel and udev adding the new device, link, driver,... (depends on the device)
        Easy to filter in the rules, if only the RUN primitive could work as intented...

        @mediamogul thanks for reading and answering anyway. Hope we'll find a clean solution. @psyke83 seems to be the man.

        P 1 Reply Last reply Reply Quote 1
        • P
          psyke83 Global Moderator @Sano
          last edited by psyke83

          @Sano said in SupaCEC - A utility to switch TV inputs when a controller is connected:

          ACTION=="add", SUBSYSTEM=="input", RUN+="/bin/bash -c 'echo 'as' | cec-client -s -d 1'"

          OK, I commandeered the TV to test and can confirm it didn't work ;). However, the pipe is working via the tee command, so the problem might be due to the cec-client being called three times in succession. Can you try refining the rule and testing? Also test "tee >/dev/kmsg" just to make sure there's no difference in configuration between our systems.

          Edit: also, try specifying the path of cec-client in the command just in case the PATH is not initialized properly.

          1 Reply Last reply Reply Quote 0
          • P
            psyke83 Global Moderator
            last edited by psyke83

            OK, this definitely works! ;)

            ACTION=="add", SUBSYSTEM=="input", RUN+="/bin/bash -c 'echo as | /usr/bin/cec-client -s -d 1'"

            The problem was either the nested apostrophes or missing PATH. I don't want to annoy the person watching the tv, so you'll need to test, but the above line worked for me. I assume it executed the command three times, however, so refining is a good idea.

            This filter works for my DS3 controller causing it to execute once:
            ACTION=="add", SUBSYSTEM=="input", KERNEL=="js[0-9]*", RUN+="/bin/bash -c 'echo as | /usr/bin/cec-client -s -d 1'"

            1 Reply Last reply Reply Quote 2
            • SanoS
              Sano
              last edited by Sano

              Ok finally found a simple solution working here, if anybody could test :

              First install cec-utils :
              sudo apt-get install cec-utils

              Create a /etc/udev/rules.d/10-cec.rules with this line:

              ACTION=="add", KERNEL=="js0", SUBSYSTEM=="input", RUN+="/bin/bash -c '/bin/echo as | /usr/bin/cec-client -s -d 1'"
              

              Note the rule will match only for the first controller (js0) and execute only once, and also note the full path to binaries.

              Reload udev rules :
              sudo udevadm control --reload-rules

              When you plug the first controller, the tv should switch to retropie.
              I tested it with (wireless) PS3 controller and USB arcade stick.

              @psyke83
              I was so concentrated testing things that I missed your post. Congrats, you found it first :)
              The good thing is we both came to the same conclusions.

              1 Reply Last reply Reply Quote 2
              • S
                superterran
                last edited by

                Awesome @Sano and @psyke83! I haven't had a chance to test this yet, but I like where this was headed and wanted to formalize something. I'll hopefully test it tonight, in the meantime if anyone wants to look it over https://github.com/superterran/SupaCEC/tree/refactoring-to-udev-rule

                P 1 Reply Last reply Reply Quote 1
                • P
                  psyke83 Global Moderator @superterran
                  last edited by psyke83

                  @superterran

                  The script seems to work fine* - except for unnecessary sudo invocations - on my DS3 controller. The previous test only switched to the Pi when the tv was off, but yours will also switch HDMI inputs when the tv is on.

                  • until you merge changes to the master branch, users need to specify the "refactoring-to-udev-rule" branch both in the curl instruction and manually appended to the gitPullOrClone line.

                  Edit: hmm, the first test worked, but second test after waiting for controller to timeout didn't switch inputs.

                  1 Reply Last reply Reply Quote 0
                  • P
                    psyke83 Global Moderator
                    last edited by psyke83

                    I've done further testing and come to the conclusion that cec-client only works reliably when a single command is invoked.

                    Your script appears to send the two commands simultaneously per line - the "pause" & switch source command, but both of your rules match my DualShock 3, which means it's 4 commands being sent at once.

                    The behaviour is unpredictable with your version; sometimes the tv will switch source and sometimes not. With my simpler version, it works more reliably, but it doesn't always work, especially after first boot. I have Kodi configured to start on boot, so it may be interfering somehow.

                    ACTION=="add", SUBSYSTEM=="input", KERNEL=="js[0-9]*", RUN+="/bin/bash -c 'echo as | /usr/bin/cec-client -s -d 1'"

                    1 Reply Last reply Reply Quote 0
                    • SanoS
                      Sano
                      last edited by

                      @meleu :
                      (Screaming like a movie character with fists toward the sky)
                      Nooooooo ! Whyyyyyyy ?

                      meleuM 1 Reply Last reply Reply Quote 0
                      • meleuM
                        meleu @Sano
                        last edited by

                        @Sano yo! Whats up doc?! :-)

                        • Useful topics
                        • joystick-selection tool
                        • rpie-art tool
                        • achievements I made
                        SanoS 1 Reply Last reply Reply Quote 0
                        • SanoS
                          Sano @meleu
                          last edited by Sano

                          @meleu It's my new (totally natural and not overacting) reaction to a downvote :)
                          I wish we had PM here...
                          Sorry !

                          meleuM 1 Reply Last reply Reply Quote 2
                          • meleuM
                            meleu @Sano
                            last edited by

                            @Sano OMG dude! Sorry! It was an accident (I was on the Android phone). You deserve an upvote!

                            I'm looking for a free time to join this conversation/development here. I'm interested!

                            • Useful topics
                            • joystick-selection tool
                            • rpie-art tool
                            • achievements I made
                            1 Reply Last reply Reply Quote 2
                            • meleuM
                              meleu
                              last edited by

                              Hello fellows.

                              I would like to say thanks! The cec-utils package is pretty handy. The udev rules are perfect!

                              The only addition I've made on my arcade build was adding a turn off monitor.sh script in RetroPie Menu.

                              #!/bin/bash
                              # turn off monitor.sh
                              #################
                              # Actually puts the monitor on stand by mode.
                              echo standby 0 | cec-utils -s -d 1
                              
                              • Useful topics
                              • joystick-selection tool
                              • rpie-art tool
                              • achievements I made
                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post

                              Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                              Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.