Raspberry pi 2, Volume Control for Audio Jack

I have a Raspberry Pi 2 Connected to a Sony TV via HDMI.

The analog audio output from the TV does not match my amplified speakers well and I like the sound from the analog out on the Pi better.

I have changed System -> Audio output -> Audio Output device to Analouge in OSMC and it works well with my speakers.

The problem is that I cannot find any way to control the volume on the analog out jack of the raspberry pi 2.

The Sony TV remote works for everything else except the volume via CEC, ( It only adjusts the volume for the in built tv speakers, If I recollect correctly this used to work in raspbmc ) The keypress for the volume buttons does not even register in the logs in debug mode.

You won’t be able to control Kodi’s master volume setting with the volume buttons on your CEC remote because the TV will not pass those buttons through CEC.

The only way you would be able to do it is map a couple of unused buttons which are passed through (such as two of the colour buttons) to volume up and down using a remote.xml. Or find some other way than your TV remote to control the volume of Kodi.

Thanks!! I remapped the green and red buttons defined in /usr/share/kodi/system/keymaps/remote.xml and it works.

Can you advise if it’s possible to alter the set of CEC capabilities that the Pi ‘advertises’ to the TV so that the TV will send the volup, voldown and mute button presses?

My TV and its remote control supports CEC and I can control my Pi and my AVR, but it only sends volume control commands to the AVR. It would be great to have those buttons sent to the Pi for OSMC to act on.

It’s the TV that decides what buttons are sent through to the CEC device so the Pi can’t influence what buttons are sent, other than reporting itself as a recorder or player - but this does not affect volume buttons.

As far as I’m aware it is not possible to send a TV remotes volume buttons to Kodi via CEC from any TV.

Thanks for the reply, but what I’m hoping to find out the mechanism by which the TV ‘knows’ what CEC devices can receive what button presses. The TV / remote seems to have no problem sending volume information via CEC as it can control the volume of my CEC capable AVR, but the TV ‘chooses’ not to do so for the Pi, so I assume there is some determining factor the TV uses to say “I’ll send volume information to this device, but not that device”
Or, does it work the other way around that the TV / remote sends all the CEC commands it’s capable of, and the receiving CEC device ‘chooses’ which ones to act on?

You said the Pi “reports itself as a recorder or player” so maybe that definition doesn’t include advertising volume capability? I’ll dig more into CEC specs and see if the answer is there.

I got a copy of the CEC specs and can see how the Device Types are addressed. The two types Recording Device and Playback Device don’t support System Audio Control, that’s only for the Audio System device, which the Pi isn’t ‘advertising’ itself as being.

Bummer :frowning:

You are right there, If i run cec-client with the type set to Audio system Device then the TV passes the volume button presses to the device.

root@osmc:/# cec-client -t a
== using device type ‘audio system’
CEC Parser created - libCEC version 3.0.0
no serial port given. trying autodetect:
path: Raspberry Pi
com port: RPI

DEBUG: [ 9391] >> TV (0) -> Audio (5): user control pressed (44)
DEBUG: [ 9391] SetCurrentButton volume down (42) D:0ms cur:42
DEBUG: [ 9391] key pressed: volume down (42) current(42) duration(0)
DEBUG: [ 9391] key pressed: volume down (42, 0)
DEBUG: [ 9391] CheckKeypressTimeout T:425.856
DEBUG: [ 9392] Key volume down: idle (duration:0) (42) timeout:500ms (rel:500,rep:0,prs:2,rel:0)
TRAFFIC: [ 9505] >> 05:8b:42
DEBUG: [ 9506] key released: volume down (42) D:393ms

Any reason this has been set to “Recording Device” in OSMC?

This is probably only needed if the Pi is being used as a PVR client which IMHO is a rare case.

Can this be added as a changeable system setting in OSMC?

If you were to change it to audio device then you would lose your transport keys (play, pause, stop etc) which wouldn’t leave you with a working remote

I do not believe that is true, I checked with cec-client and those keys are being passed when set to “Audio System”, all of the control keys required to use OSMC are being passed along correctly.


I Edited /usr/share/kodi/system/peripherals.xml and changed the below lines from configurable = 0 to configurable = 1

<setting key="device_name" type="string" value="Kodi" configurable="1" />
<setting key="device_type" type="int" value="1" configurable="1" />

This allows me to change the device name and type from the UI : Settings -> System -> Input Devices -> Peripherals -> Cec Adapter

The following values work for device type, unfortunately there seems to be no option for the “Audio System” type programmed in. ( I haven’t tried beyond 6, it seems to repeat the sequence at 5 )

0 Recorder
1 Recorder
2 Recorder
3 Tuner
4 Player

The remote works fine in all 3 modes and I’m quite sure it should work in the Audio system mode too.

That’s an excellent solution, but the CEC specs say that only one device in the chain can take address 5 and be the audio system, so if the Pi takes that address on startup, any AVR on the chain will will be bumped up to the free address, 14, or vice-versa

In effect, the Pi would have to be on two addresses, one for being a recording device and one for being an audio system, but currently the peripherals.xml doesn’t support having two instances of the device_type key, so it can only be one or the other. The last resort would be to take address 15, but that is the broadcast address.

Try <setting key="device_type" type="int" value="15" configurable="0" /> Not sure if Kodi will do anything with the extra keystroke info, but it’s worth a try.

I think the value for device_type in the xml file refers to the device type OSMC/Kodi uses to identify itself to the TV and not the device address that you are referring to unless they are the same thing?? .

Anyways I tried 14 and 15 but they didn’t work, anything above 4 and it shows up as a recorder.

cec-client shows that LibCEC has 4 possible device types " -t --type {p|r|t|a} " Out of which 3 are implemented in osmc/kodi and the 4th has been left out for some reason.

Do you have any further inputs on this discussion??

About a year ago I had a chit-chat via e-mail with the pulse-eight support. They stated it would be definitely possible to send CEC volume commands from the TV to their CEC-USB-adaptor, but they wouldn’t implement it as it violates the standards.

Obviously announcing the RPi/P8-CEC-USB-adaptor as an AVR is the only way to go. I do not like AVRs but have a USB audio interface instead and would like to control it’s volume via TV-remote -> CEC -> USB -> Pulseaudio.

Are any solutions in KODI, yet?

I’m not one to necrobump usually, but I’ve just encountered this issue. It appears the problem lies here:

I’m going to raise an issue, so we’ll see where that leads.

I’m also looking in to this, as allowing volume to be adjusted via CEC would be quite useful. I believe it will only work if connected to an AV receiver.