[Plugin Dev Question] Intercept Volume change?

Hi Folks,

is there any possibility to intercept a volume change via plugin?
I would like to trigger an event in a plugin everytime the volume changed.

Thanks a lot & best regards!

I expect this question comes from turning off you DAC and not your rPi?

You can experiment using Volumio CLi commands or using the Socket.io .
Using the socket.io, you can trigger this only when playing.

volumio status

and monitor the tags:

"volume": 100,
"disableVolumeControl": true,

Set some guards on them like:

if volume > 20 then
volumio stop 

But then you run into other issues if you want to increase the volume by hand.

Hi Wheaten,

the problem with turning off the DAC has been solved with a little plugin.
My next goal is to find a solution to control the volume of the DAC via Volumio.
As the ADI-2 DAC cannot be controlled via USB, one possible way could be to control its volume via IR. But to accomplish that, I need a possibility to trigger some actions with a volume change in Volumio…

Thanks a lot!

I could check the volume every X seconds via socket.io, but that may not be very performant.
Thats why I am looking for a kind of trigger or event.
As I am very new to Volumio Plugins, I am not aware if this is possible.

To my understanding you’re only interested in this when Volumio is playing.
So monitoring Volumio via status change, limits the amount of processing time, as Volumio calls instead of polling. See:

1 Like

In FusionDsp, Loudness is adjusted when volume changes. It uses socket.io for this.
Check the code…

1 Like

If you just want volume control, via IR, there is already a plugin for that.
Which can be controlled by almost every IR you have.
(If it’s not in the list yet you need to create your own lircd.conf and lircrc.)

prog = irexec
button = Volume-Up
config = /usr/local/bin/volumio volume plus

prog = irexec
button = Volume-Down
config = /usr/local/bin/volumio volume minus

Well, I would want it the other way round.
So if a volume change on Volumio happens → send an IR-Command out to the DAC. So it may be possible to remote-control the volume of the DAC an keep Volumio and DAC volume in sync.
So basically, I need an IR-Sender to be controlled via Plugin.

That can also be done via lirc, but that need to be programmed.
Not fully understand the “why?” to control the volume on 2 places.
I would simply let Volumio control the volume and leave the DAC full open.

What your saying is I set Volumio to 10, set the dac to 10 leaving the final signal to 1?
( (Device A * Device B) / 100)

My DAC does not support hardware volume control and I am trying to find a solution to use the possibility of the hardware mixer (which is supported by the RME ADI-2 DAC) without losing the possibility to control the volume via Volumio…

When I set volume control to “Hardware” in Volumio, I still can adjust the volume, but is has no effect. So my goal is to send IR-Commands to the DAC to control the volume when the volume in Volumio has changed.

Just a stupid idea, but maybe it could work…

Aha, I get it.
Missed the part that Volumio lowers the volume, but the DAC is not responding.
So the volume output of Volumio is steady at 100 received by the DAC.

Then this “stupid” idea, might do the trick.

1 Like

Have a look at my repo: https://github.com/charliesjc/denonavrvolume

I began working on something to update the volume on my Denon Receiver a while back. It does work but it’s a bit messy and I haven’t looked at it again. You may find what you need in there.

1 Like

It worked :wink:
But despite my first thoughts, I used a little Arduino Nano to control the IR-Signals, so I do not have to mess around with LIRC and it helps to keep the overhead in Volumio as small as possible.
So now, the Nano is connected to the Pi via USB and my Plugin tells the Nano to send IR-Signals to control the volume of the RME Adi DAC-2 everytime a change in Volume is pushed out. Would say, it is a quite “dirty” solution, but it works.
This should also work for all kind of DACs which support IR-Control.

1 Like

Hi @MichaelE

Thanks for giving the feedback.
Good to hear you have a working solution for your issue!


Hello @MichaelE,

I have somehow a similar project, let me explain :
I have a Raspberry PI 4 running Volumio connected via USB to an amp Cambridge CXA81.
Currently I use Volumio Software Mixer for volume control, but I would like to be able to control the amp volume directly from Volumio.
To achieve that goal my plan is to add a IR transmitter to my PI (with a pHAT probably) and write a Volumio Plugin.
But my main concern is this : the volume of my amp can be control only with “+” or “-” commands, there is no feedback of the actual value and there is no way to send a specific value. I can just send “+” or “-” via IR signals.
So my question is : is it possible to adapt the Volumio GUI (via pluggin or via volumio source code) so that GUI enables only to change the volume via “+” or “-” without possibility to select a value with the cursor or whatsoever.

Currently my Volumio instance proposes only “None” or “Software” mixer. No Hardware as it’s not supported by my amp.
So I guess I need to implement a new dedicated Mixer and adapt the GUI that goes along with it, but I don’t think this is possible via pluggin only. Is it ?
If not, can someone give me a few pointers as starting point to edit Volumio code ?

@MichaelE : could you also share your sources ?

Thanks in advance !

1 Like

Hi @steiner ,

your situation is the same mine was, also my amp only supports + and -.
My solution was, that I defined a standard-volume value, lets say 50.
When changing the volume in Volumio via Slider or whatever, my plugin checks the difference between the new value and the standard value. For example, when the new value is 55, my plugin sends 5x “+” via IR to the amp. Afterwards, the volume in Volumio is resetted to 50.
So it does not matter how the volume is changed in Volumio.

I can share my sources, but be aware of these things:

  • I am a very untalented coder
  • I wrote this code for my own purposes, so it will need adjustments to make it work for you
  • this was my very first Volumio plugin and I have no deeper knowledge about what is the best way to create a plugin

Hope this helps.

volume_guard.zip (5.6 KB)

Best regards!

@MichaelE thanks a lot for your quick reply :slight_smile: and for sharing your code.
Your approach seems interesting, I’ll just change the logic :
“when the new value is 55, my plugin sends 5x “+””
"when the new value is 55, my plugin sends 1x “+”
Indeed as we are playing with the amp volume there is a risk of damaging the amp and/or the loudspeaker if we set the volume too high by mistake (especially with my amp as one push on “+” on the remote as a significant change on the volume)

Do you know by any chance if, with you implementation, the volume of your amp is adjusted if you listen via Tidal Connect on your smartphone and change the volume using your smartphone’s buttons ?
I think it should work as, when I does it currently, the volume is adjusted in Volumio.

I didn’t checked your sources yet but:

  • I guess you are using the Software Mixer option (otherwise sound control would be completely disabled), correct ?
  • Is there something in your code that “disables” the effect of that SW Mixer ? My intend is that it’s always the full signal (no reduction) that is send from Volumio to the Amp.

Thanks in advance !

Hi @steiner ,

I do not use Tidal at all, so unfortunately I have no answer to that. For my understanding, this is also not a question addressing the plugin, but the Volumio-App itself. If your smartphone’s buttons change the volume in Volumio, the plugin will intercept that change.

In my special case, my DAC allows me to choose Hardware as mixer type, but the volume control does not work, it simply has no effect. I think somewhere was a discussion/hack about a kind of virtual mixer which just does nothing but shows the volume control.

I didn’t saw the notif of your reply sorry.
Thanks for the answers !

I’ll try to find that virtual mixer you are talking about, it seems promising.

Found it: