Increase or decrase Volume via Http API?

Does anybody know how to increase or decerase volume by step via api?
If I use http://beosound2300.local:3001/roonAPI/change_volume?volume=20&outputId=170103394b4dd26c4842b8197e22a1e0dd9b it set volume to 20, wich is work perfectly, so i decide to write linux script and change 20 to variable $VOLUME so command look: curl ‘http://beosound2300.local:3001/roonAPI/change_volume?volume=$VOLUME&outputId=170103394b4dd26c4842b8197e22a1e0dd9b
but nothing is happen. How I correctly put variable into curl command?
Or maybe should I use another command or method?

Hi @Zarko_Vargovic

Try using double quote instead of single quote (as far as I know single quote does not do variables).

Here’s my working bash script

#!/bin/sh

MY_VOLUME=10
echo $MY_VOLUME

curl "http://localhost:3001/roonApi/change_volume?outputId=1701aa4e166fe64eae164bfae7c5e928181e&volume=$MY_VOLUME"

Hope this helps

Hi @St0g1e and @Zarko_Vargovic

thanks for sharing this

im on a mac but have some linux CLI experience (but not much :)), is there a guide on how to set this up? do i need to install stuff on my roon core for this to work?
do i need to change the outputted per device?

my roon core is on 192.168.0.2 so i tried naively to issue this via the command line

curl http://192.168.0.2.local:3001/roonAPI/change_volume?volume=20&outputId=170103394b4dd26c4842b8197e22a1e0dd9b

but that did nothing

any tips or guidance would be super helpful!

best

Z

I use mqtt extensions, because http api dont work. So command should look like:
mosquitto_pub -h mediaserver.local -p 1883 -t roon/BeoSnd/outputs/BeoSnd/volume/set -m -60

where is mediaserver.local is my mqtt broker and roon/BeoSnd/outputs/BeoSnd is my zone.

After research http api works. If you like below is instructions for install extension (linux):

Install API ekstension (volume control version)

cd ~/.RoonExtensions/lib/node_modules
git clone https://github.com/st0g1e/roon-extension-http-api.git
cd roon-extension-http-api
npm install
node .
cd /
cd /etc/systemd/system

Creating service for api:
sudo nano roon-remote-http-api.service

Inside nano editor paste code below:
[Unit]
Description=http-API control for Roon
Wants=network-online.target
[Service]
WorkingDirectory=/home/pi/.RoonExtensions/lib/node_modules/roon-extension-http-api
ExecStart=/usr/bin/node /home/pi/.RoonExtensions/lib/node_modules/roon-extension-http-api/server.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=Http-API-control
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target

sudo systemctl enable roon-remote-http-api.service
sudo systemctl start roon-remote-http-api.service
sudo reboot

For setting volume natively follow instructions on github.

Hi,

The url should point to where you have the service running.
If you install it on your Mac, and running it on the same Mac, you can use localhost or its ip.

Also, to get the zone that you want to change, you can call the listZones and use the zoneid.

Hope it helps.
Let me know if you need more information.

1 Like

thx @St0g1e !!

i think i missing something:

The url should point to where you have the service running.

is that a service that comes with roon or i need to manually install it?

appreciate your kind help!

Z

No problem.

May I know if you have installed the extension?
If you have not, you can follow the step by step from This extension.

If you have it already, make sure you have run it by calling

npm install
node .

Only then you can call the services.

Also, May I ask what it is that you want to do at the end as there are 2 repositories that might interest you. The one I linked above and the websocket one.

Let me know if you need more info.

hi again

ok i knew i missed a step :slight_smile:

ok i will explore this now.

as for my base need: i want to use my mac keyboard to issue next/pause/vol+/- commands to the roon core installed on my qnap. so i would assign keyboard shortcuts per http call using a keybinding app (like Keyboard Maestro). Does that make sense?
so i assume i need to install it on the Qnap where i have roon core ("…Copy the downloaded zip to the desired folder")?

thx again

Z

You don’t have to install it where you have your core. As long as it’s within the same network it should work.

You can install it in your mac, for example.

For what you are doing, the http-api extension should be good.

Let me know if you need more info.

@St0g1e wow!

This is EPIC :slight_smile: !!

you srsly made my week, thx so much. I’ve been looking for weeks now for a solution and this is perfect! (i actually ordered a elgato stream XL basically just for this…oh well… :))

two last questions if you still don’t mind

  1. i assume i need to create a shell script or something along the line to launch the node process every reboot (no issue just confirming)

  2. im trying to follow what @Zarko_Vargovic suggested on the start of the thread to have a key to raise the volume as opposed to setting in to a fixed value

i have this so far

#!/bin/sh

MY_VOLUME=10
echo $MY_VOLUME

curl "http://localhost:3001/roonAPI/change_volume?outputId=1701951e0da7ecc2021c4bcf231f546d089d&volume=$MY_VOLUME"

but this sets the volume to 10 instead of raising it by 10 units. what did i miss again?

thx sooo much, much appreciated!

Z

Answer is very simple, just make script wich increase volume by wanted step (1 or 10 or whatever…)

#!/bin/sh
MY_VOLUME=10
MY_VOLUME=$((MY_VOLUME+1))
curl “http://localhost:3001/roonAPI/change_volume?outputId=1701951e0da7ecc2021c4bcf231f546d089d&volume=$MY_VOLUME

after that you can use triggerhappy service in example , when you press + key on keyboard to trigger this script, or you can use other event in system to trigger it, and raise volume by 1.

With this method I successfully use microsoft dialpad in conjuction with linux to control zone volume.

Thx so much @Zarko_Vargovic !

for some reason the script only work once. i assume its because each time you run it needs somehow to update the MY_VOLUME=10 part to the current volume?

thx!

z

Wohoooo!!!

For your first question I think you should google launch daemon on how to automatically run scripts on startup. I have not tried to do it.

For your second question, you can do either one below:

  1. As per Roon’s doc Here, on change_volume, there is a “how” variable. Now on the http-api repository, at

controllers/roonAPI.js

You can see at line 132 I have it as “absolute”. You can change it to “relative” or “relative-step” and see which one fits your use case best.

  1. Or you can create a new api call. You can copy from line 131 to 138 and name it something else. You have to update routes.js as well if you add a new call

Hope this helps.
Let me know how it goes.

You must write volume value to disk after you change value, also before you change volume you should read value from disk and change it. You should add lines for that in my example. This method is nessesarry , lets assume that you change volume with custom controller like keyboard or dialpad, and after that in volume control in roon sftware volime is nor updated by new changed volume.

thx! @Zarko_Vargovic!

since im not super technical do you have perhaps an example you made that write to disk i can use as a starting point?

best

Z

Sorry for late answer, but I have lot of other work to do, below I share scripts for controling volume.

mkdir /home/pi/configfiles
cd /home/pi/scripts
sudo nano volup.sh

#!/bin/bash

Checking if /home/pi/configfiles/vol.txt exist

VOL=/home/pi/configfiles/vol.txt

If exist

if test -f “$VOL”; then

Read value from server

mosquitto_sub -h 192.168.1.3 -t roon/BeoSnd/outputs/BeoSnd/volume/value -C 1 > /home/pi/configfiles/vol.txt
VOLVALUE=**tail** -1 /home/pi/configfiles/vol.txt

increase for 1 if volume less or equal to -1

if [ $VOLVALUE -le 0 ]
then
VOLVALUE=$((VOLVALUE+1))
mosquitto_pub -h mediaserver.local -p 1883 -t roon/BeoSnd/outputs/BeoSnd/volume/set -m $VOLVALUE -r
fi

Store volume value into /home/pi/configfiles/vol.txt

echo "$VOLVALUE"
else

Make file /home/pi/configfiles/vol.txt

touch /home/pi/configfiles/vol.txt

Read vol value from server

mosquitto_sub -h 192.168.1.3 -t roon/BeoSnd/outputs/BeoSnd/volume/value -C 1 > /home/pi/configfiles/vol.txt
VOLVALUE=**tail** -1 /home/pi/configfiles/vol.txt
mosquitto_pub -h mediaserver.local -p 1883 -t roon/BeoSnd/outputs/BeoSnd/volume/set -m $VOLVALUE -r
echo "$VOLVALUE"
fi

sudo nano voldown.sh

#!/bin/bash

Check if exist /home/pi/configfiles/vol.txt

VOL=/home/pi/configfiles/vol.txt

If exist

if test -f “$VOL”; then

Read vol value from server

mosquitto_sub -h 192.168.1.3 -t roon/BeoSnd/outputs/BeoSnd/volume/value -C 1 > /home/pi/configfiles/vol.txt
VOLVALUE=**tail** -1 /home/pi/configfiles/vol.txt

decrease vol by 1 ako je vol equal or greather than -79

if [ $VOLVALUE -ge -79 ]
then
VOLVALUE=$((VOLVALUE-1))
mosquitto_pub -h mediaserver.local -p 1883 -t roon/BeoSnd/outputs/BeoSnd/volume/set -m $VOLVALUE -r
fi
echo "$VOLVALUE"
else

make /home/pi/configfiles/vol.txt

touch /home/pi/configfiles/vol.txt

Read vol value from server

mosquitto_sub -h 192.168.1.3 -t roon/BeoSnd/outputs/BeoSnd/volume/value -C 1 > /home/pi/configfiles/vol.txt
VOLVALUE=**tail** -1 /home/pi/configfiles/vol.txt
mosquitto_pub -h mediaserver.local -p 1883 -t roon/BeoSnd/outputs/BeoSnd/volume/set -m $VOLVALUE -r
echo "$VOLVALUE"
fi

You can modify my scripts according to your need,
In this case I use mqtt extension, not http api, becouse I control roon with other devices in my apartment.

Also I m using linux (debian-buster) and everything is working on Rpi 4.
I make complete tutorial to setup Rpi4 as control device and wifi to mqtt and ir bridge, all remote controlers is supported, also imon ir knob, and microsoft surface dialpad, for visualisation neopixel strips is used.
Currently tutorial is in progress, and it will be finished soon, depend on my free time…

Best regards!

Thx @Zarko_Vargovic !

really appreciate the time you took and the much detailed response

i m very untechnical so this will take me a few good days to process :slight_smile:

I hope i succeed and will report back with the results

best again

Z

Are you trying to find out the value of volume for a zone?
You should use the getZone api.

localhost:[PORT]/roonAPI/getZone?zoneId=[ZONEID]

The volume information should be there.

On second thought, if you use “relative” or “relative-step” you should not need to know the current value.