Possible to control TV volume from usb remote connected to rpi?

  • Hi all,

    I've a rpi4 directly connected to a TV (LG C1) trough HDMI with lib-cec enabled.

    I've an usb remote plugged in kodi and it works great within kodi.

    It has volup/voldown/mute buttons, and they behave as anyone would expect managing kodi's own volume.

    Desired behavior is to route those buttons to control TV volume instead of being captured and processed within kodi.

    While using my TV's remote, the up/down/left/right/OK/red/green/yellow/blue buttons are sent from TV and captured on rpi/kodi.

    Volume buttons on tv remote are processed in TV which is fine.

    Can I somehow configure it so that volume related buttons on rpi/kodi remote are sent and processed at the TV?

    Kind regards,

  • I've playing around and found a shell command to achieve it:

    LibreELEC:~ # /usr/bin/cec-ctl --user-control-pressed ui-cmd=volume-down --to=0

    Driver Info:

    Driver Name : vc4_hdmi

    Adapter Name : vc4

    Capabilities : 0x0000010e

    Logical Addresses

    Transmit

    Passthrough

    Connector Info

    Driver version : 5.10.110

    Available Logical Addresses: 1

    DRM Connector Info : card 0, connector 32

    Physical Address : 1.0.0.0

    Logical Address Mask : 0x0002

    CEC Version : 1.4

    Vendor ID : 0x001582 (Pulse-Eight)

    OSD Name : ''

    Logical Addresses : 1 (Allow Fallback to Unregistered)

    Logical Address : 1 (Recording Device 1)

    Primary Device Type : Record

    Logical Address Type : Record


    Transmit from Recording Device 1 to TV (1 to 0):

    USER_CONTROL_PRESSED (0x44):

    ui-cmd: volume-down (0x42)

    Sequence: 86 Tx Timestamp: 255.072s


    Now, if i map my remote's volup/voldown/mute buttons to execute the same in Kodi, i'm getting the following error:

    2022-11-29 00:04:24.626 T:1251 DEBUG <general>: HandleKey: volume_up (0xf0b9) pressed, action is System.Exec("/usr/bin/cec-ctl --user-control-pressed ui-cmd=volume-up --to=0")

    2022-11-29 00:04:24.691 T:1634 DEBUG <general>: Thread Timer 3531285120 terminating

    2022-11-29 00:04:24.904 T:1256 INFO <general>: CAESinkALSA - Unable to open device "default" for playback

    2022-11-29 00:04:24.946 T:1256 INFO <general>: CAESinkALSA - Unable to open device "sysdefault" for playback

    2022-11-29 00:04:24.948 T:1256 INFO <general>: CAESinkALSA - Unable to open device "sysdefault:CARD=vc4hdmi0" for playback

    2022-11-29 00:04:24.949 T:1256 INFO <general>: CAESinkALSA - Unable to open device "hdmi:CARD=vc4hdmi0,DEV=0" for playback

    2022-11-29 00:04:24.951 T:1256 INFO <general>: CAESinkALSA - Unable to open device "sysdefault:CARD=vc4hdmi1" for playback

    2022-11-29 00:04:24.952 T:1256 INFO <general>: CAESinkALSA - Unable to open device "hdmi:CARD=vc4hdmi1,DEV=0" for playback

    2022-11-29 00:04:24.957 T:1256 DEBUG <general>: PulseAudio: Context authorizing

    2022-11-29 00:04:24.959 T:1256 DEBUG <general>: PulseAudio: Context setting name

    2022-11-29 00:04:24.959 T:1256 DEBUG <general>: PulseAudio: Context ready

    2022-11-29 00:04:24.961 T:1256 WARNING <general>: Pulseaudio module module-allow-passthrough not loaded - opening PT devices might fail

    2022-11-29 00:04:24.962 T:1256 INFO <general>: Found 1 Lists of Devices

    2022-11-29 00:04:24.962 T:1256 INFO <general>: Enumerated PULSE devices:

    2022-11-29 00:04:24.962 T:1256 INFO <general>: Device 1

    2022-11-29 00:04:24.962 T:1256 INFO <general>: m_deviceName : Default

    2022-11-29 00:04:24.962 T:1256 INFO <general>: m_displayName : Default

    2022-11-29 00:04:24.962 T:1256 INFO <general>: m_displayNameExtra: Bluetooth Audio (PULSEAUDIO)

    2022-11-29 00:04:24.962 T:1256 INFO <general>: m_deviceType : AE_DEVTYPE_PCM

    2022-11-29 00:04:24.962 T:1256 INFO <general>: m_channels : FL, FR

    2022-11-29 00:04:24.962 T:1256 INFO <general>: m_sampleRates : 5512,8000,11025,16000,22050,32000,44100,48000,64000,88200,96000,176400,192000,384000

    2022-11-29 00:04:24.962 T:1256 INFO <general>: m_dataFormats : AE_FMT_U8,AE_FMT_S16NE,AE_FMT_S24NE3,AE_FMT_S24NE4,AE_FMT_S32NE,AE_FMT_FLOAT

    2022-11-29 00:04:24.963 T:1256 INFO <general>: m_streamTypes : No passthrough capabilities

    2022-11-29 00:04:24.964 T:1257 INFO <general>: CActiveAESink::OpenSink - initialize sink

    2022-11-29 00:04:24.965 T:1257 DEBUG <general>: CActiveAESink::OpenSink - trying to open device ALSA:hdmi:CARD=vc4hdmi0,DEV=0

    2022-11-29 00:04:24.965 T:1257 INFO <general>: CAESinkALSA::Initialize - Attempting to open device "hdmi:CARD=vc4hdmi0,DEV=0"

    2022-11-29 00:04:24.973 T:1257 INFO <general>: CAESinkALSA - Unable to open device "hdmi:CARD=vc4hdmi0,DEV=0,AES0=0x04,AES1=0x82,AES2=0x00,AES3=0x00" for playback

    2022-11-29 00:04:24.974 T:1257 INFO <general>: CAESinkALSA - Unable to open device "hdmi:CARD=vc4hdmi0,DEV=0" for playback

    2022-11-29 00:04:24.974 T:1257 ERROR <general>: CAESinkALSA::Initialize - failed to initialize device "hdmi:CARD=vc4hdmi0,DEV=0"

    2022-11-29 00:04:24.975 T:1257 DEBUG <general>: CActiveAESink::OpenSink - trying to open device PULSE:Default

    2022-11-29 00:04:24.977 T:1257 DEBUG <general>: PulseAudio: Context authorizing

    2022-11-29 00:04:24.978 T:1257 DEBUG <general>: PulseAudio: Context setting name

    2022-11-29 00:04:24.979 T:1257 DEBUG <general>: PulseAudio: Context ready

    2022-11-29 00:04:24.982 T:1257 DEBUG <general>: PulseAudio: Stream ready

    2022-11-29 00:04:24.982 T:1257 INFO <general>: PulseAudio: Opened device Default in pcm mode with Buffersize 300 ms Periodsize 100 ms

    2022-11-29 00:04:24.982 T:1254 DEBUG <general>: Sink changed

    2022-11-29 00:04:24.983 T:1257 INFO <general>: Skipped 1 duplicate messages..

    2022-11-29 00:04:24.983 T:1257 DEBUG <general>: CActiveAESink::OpenSink - PULSE Initialized:

    2022-11-29 00:04:24.983 T:1257 DEBUG <general>: Output Device : Default

    2022-11-29 00:04:24.983 T:1257 DEBUG <general>: Sample Rate : 44100

    2022-11-29 00:04:24.983 T:1257 DEBUG <general>: Sample Format : AE_FMT_FLOAT

    2022-11-29 00:04:24.983 T:1257 DEBUG <general>: Channel Count : 2

    2022-11-29 00:04:24.983 T:1257 DEBUG <general>: Channel Layout: FL, FR

    2022-11-29 00:04:24.983 T:1257 DEBUG <general>: Frames : 4410

    2022-11-29 00:04:24.983 T:1257 DEBUG <general>: Frame Size : 8

    2022-11-29 00:04:24.986 T:1256 DEBUG <general>: CActiveAE::ClearDiscardedBuffers - buffer pool deleted

    2022-11-29 00:04:24.986 T:1254 DEBUG <general>: Sink changed

    2022-11-29 00:04:24.986 T:1256 DEBUG <general>: CActiveAE::ClearDiscardedBuffers - buffer pool deleted

    2022-11-29 00:04:24.988 T:1251 DEBUG <general>: Keyboard: scancode: 0x73, sym: 0x00af, unicode: 0x0000, modifier: 0x0

    2022-11-29 00:04:25.299 T:1257 ERROR <general>: Sink Timer expired for more than buffer time: 300l

    And then kodi crashes :-\

    Any tips on reason why i'm getting this error and how to overcome it?

    Kind regards,

  • Just in case this could help to someone else, i've achieved it by building a custom addon and executing the commands in the following way:

    In keymap XML file:

    Code
    ...
    <key id="61625">RunScript(script.custom-cec-commands, volup)</key>
    <key id="61624">RunScript(script.custom-cec-commands, voldown)</key>
    <key id="61623">RunScript(script.custom-cec-commands, volmute)</key>
    ...

    In addon's script:

    Kind regards,