Change Volume

(Jack ) #1

Hey Guys,

i need your help: i want to change the volume on the RPi throw the openhab Interface. But it still not changing.

Selection item=Sender icon=“radio” mappings=[0=“off”, 1="…", 2="…", 3="…"]
Slider item=Volume icon=“soundvolume”

Number Sender “Radio”
Dimmer Volume “Volume [%.1f %%]”

rule "Volume"
Item Volume received command
if (receivedCommand instanceof PercentType) {
} else {
if (receivedCommand == INCREASE) increaseMasterVolume(20)
if (receivedCommand == DECREASE) decreaseMasterVolume(20)

Where is the error?


(Mihai Badea) #2

I’m changing the volume on my RPi using:

executeCommandLine("amixer set PCM " + NotificationVolume.state.toString +"%")

(Jack ) #3


I changed my rules now in:

rule “Change Pi Volume"
Item Volume changed
executeCommandLine(“amixer set PCM " + NotificationVolume.state.toString +”%”)

But nothing happen. Can you send me your rules please?

I tried with
executeCommandLine("amixer set Headphone " + Volume.state.toString())
But the changes are very small


(Mihai Badea) #4

First, my item is NotificationVolume and I see that yours is Volume. So you should change the executeCommandLine accordingly. I see that your second example uses the right item, but the first one didn’t.
Second, as you can see, the volume is set in percent, so, if you Volume has states of 1, 2 and so on you can multiply the value by 10 or change the mappings to 10, 20, etc.

(Jack ) #5

Now it works! Great, thank you!

One question:
The slider is at the moment in the middle, but the alsamixer shows -53,44db and 11. It should be by 50 or not?

(Mihai Badea) #6

Not sure about that.
Running amixer on my Pi shows:

Simple mixer control 'PCM',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 17152
  Front Left: Playback 1201 [7%] [4.69dB] [on]
  Front Right: Playback 1201 [7%] [4.69dB] [on]

And, if you do the math, 1201 is 7% from 17152 (max value).
As I’m not quite expert on Pi & sound I cannot explain you further.

(Jack ) #7

do you use a separate soundcard?

Can you send me your config for alsa?

(Lucky) #8

Try listing the controls your Pi has:

amixer scontrols 

Then use the info you got from that command to issue this command. Example:

amixer sset 'Master' 50%

So your rule will now be

executeCommandLine("amixer sset 'Master' " + Volume.state.toString() + "%")

don’t forget the percent sign

(Jack ) #9

i have tried this. This is the result:

root@raspberrypi:/home/pi# amixer scontrols
Simple mixer control ‘PCM’,0
root@raspberrypi:/home/pi# amixer sset ‘PCM’ 100%
Simple mixer control ‘PCM’,0
Capabilities: pvolume pvolume-joined pswitch pswitch-joined
Playback channels: Mono
Limits: Playback -10239 - 400
Mono: Playback 400 [100%] [4.00dB] [on]

I think nothing changed

(Lucky) #10

I see it’s on 100% already

(Jack ) #11

But the screenshot from Mihai looks different.
I’m using a RPi 3 B