I am using the Homey Denon AVR Denon AVR App voor Homey | Homey app and the Denon HEOS Denon HEOS App voor Homey | Homey app in various Flows in Homey. The only feature I am missing is the ability to retrieve the volume of zone 2. I have tried a few things with Flows but couldn’t figure it out. That’s why I turned to scripts with the help of ChatGPT and the commands for Denon (https://assets.denon.com/documentmaster/uk/avr1713_avr1613_protocol_v860.pdf ). However, I’m still unable to make progress.
Using the URL below, I can set zone 2 to a value of 20 or any other volume level. This zone can also be turned on and off using Z2ON
or Z2OFF
.
http://192.168.0.14:8080/goform/formiPhoneAppDirect.xml?Z220
I found most of the information on this page: https://community.home-assistant.io/t/denon-avr-zone-controls-via-lovelace/336526 .
Using the command Z2?
, it should be possible to query the status of zone 2, but this doesn’t seem to work. The page remains empty.
This is my script that me and ChatGPT came up with:
// Instellingen
const denonIP = '192.168.0.14'; // IP-adres van je Denon-apparaat
const zone2VolumeCommand = 'Z2?'; // Commando om volume van zone 2 op te vragen
const url = `http://${denonIP}:8080/goform/formiPhoneAppDirect.xml?${zone2VolumeCommand}`;
// HTTP-aanroep maken
(async () => {
try {
let response = await fetch(url, {
method: 'GET'
});
if (!response.ok) {
throw new Error(`Fout bij ophalen van gegevens: ${response.statusText}`);
}
let data = await response.text();
// Output verwerken
let volumeMatch = data.match(/Z2(\d+)/); // Zoek naar de volumewaarde
if (volumeMatch) {
let zone2Volume = volumeMatch[1];
console.log(`Zone 2 volume: ${zone2Volume}`);
} else {
console.log('Kon het volume van zone 2 niet vinden in het antwoord.');
}
} catch (error) {
console.error(`Fout: ${error.message}`);
}
})();
Unfortunately, the command Z2?
does not work; no information about the set volume is returned.
I found a new URL that does give the information I need: 192.168.0.14:8080/goform/formZone2_Zone2XmlStatusLite.xml
It gives the following information
ON NET Absolute -54 off
In this case the Zone2 is in and it has a volume of -54.
Maybe one more question and some extra informatie:
This is the URL with the information of the volume in zone 2
http://192.168.0.14:8080/goform/formZone2_Zone2XmlStatusLite.xml
ON NET Absolute -57 off
Is there a simple solution to read the volume and update the valuable ‘DenonBadkamerVolume’?
Caseda
January 4, 2025, 5:13pm
7
So you went from “this is the working script”, to it doesn’t work? I don’t understand…
Not sure if HomeyScript is allowed to create logic variables, so I left that out:
const denonIP = '192.168.0.14'; // IP address of you Denon Receiver
const volumeVariable = 'DenonBadkamerVolume'; // The name of the variable you want to set
const url = `http://${denonIP}:8080/goform/formZone2_Zone2XmlStatusLite.xml`;
function extractValue(xmlString, tag) {
const regex = new RegExp(`<${tag}>[\s\S]*?<value>(.*?)</value>`, 'i');
const match = xmlString.match(regex);
return match ? match[1] : null;
};
const response = await fetch(url);
if (!response.ok) throw new Error(`Error: ${response.statusText}`);
const data = await response.text();
const zone2Volume = Number(extractValue(data, 'MasterVolume'));
if (zone2Volume) {
await Homey.logic.getVariables()
.then(async result => {
const findVariable = Object.values(result).find(obj => obj.name === volumeVariable);
variableID = findVariable ? findVariable.id : '';
if (variableID) {
await Homey.logic.updateVariable({ id: variableID, variable: { value: zone2Volume } })
.then(result => {
if (result) log(result.name + ' = ' + zone2Volume);
})
.catch(err => {
log('Error:', err);
});
} else {
log('Error: failed to find variable');
}
});
return zone2Volume;
}
1 Like
Thanks for the script, I will clean up this topic to ensure there’s no more confusion than strictly necessary
It works like a charm.