# Denon AVR get volume state zone 2

**URL:** <https://community.homey.app/t/denon-avr-get-volume-state-zone-2/126448>\
**Category:** Apps\
**Created:** [January 3, 2025, 10:20pm UTC](https://community.homey.app/t/denon-avr-get-volume-state-zone-2/126448 "2025-01-03T22:20:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Monninkhof](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/brian_monninkhof/32/59307_2.png) [@Brian\_Monninkhof](https://community.homey.app/u/Brian_Monninkhof)\
**Post date:** [January 3, 2025, 10:20pm UTC](https://community.homey.app/t/denon-avr-get-volume-state-zone-2/126448/1 "2025-01-03T22:20:01Z")

</div>

I am using the Homey Denon AVR [Denon AVR App voor Homey | Homey](https://homey.app/nl-nl/app/com.moz.denon/Denon-AVR/) app and the Denon HEOS [Denon HEOS App voor Homey | Homey](https://homey.app/nl-nl/app/com.denon.heos/Denon-HEOS/) 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](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](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](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.

---

<div class="post-metadata">

**Author:** ![Brian\_Monninkhof](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/brian_monninkhof/32/59307_2.png) [@Brian\_Monninkhof](https://community.homey.app/u/Brian_Monninkhof)\
**Post date:** [January 3, 2025, 10:25pm UTC](https://community.homey.app/t/denon-avr-get-volume-state-zone-2/126448/2 "2025-01-03T22:25:31Z")

</div>

This is my script that me and ChatGPT came up with:

```auto
// 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.

---

<div class="post-metadata">

**Author:** ![Brian\_Monninkhof](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/brian_monninkhof/32/59307_2.png) [@Brian\_Monninkhof](https://community.homey.app/u/Brian_Monninkhof)\
**Post date:** [January 3, 2025, 11:13pm UTC](https://community.homey.app/t/denon-avr-get-volume-state-zone-2/126448/3 "2025-01-03T23:13:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brian\_Monninkhof](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/brian_monninkhof/32/59307_2.png) [@Brian\_Monninkhof](https://community.homey.app/u/Brian_Monninkhof)\
**Post date:** [January 4, 2025, 3:43pm UTC](https://community.homey.app/t/denon-avr-get-volume-state-zone-2/126448/6 "2025-01-04T15:43:06Z")

</div>

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](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’?

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [January 4, 2025, 5:13pm UTC](https://community.homey.app/t/denon-avr-get-volume-state-zone-2/126448/7 "2025-01-04T17:13:26Z")

</div>

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:

```auto
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;
}

```

---

<div class="post-metadata">

**Author:** ![Brian\_Monninkhof](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/brian_monninkhof/32/59307_2.png) [@Brian\_Monninkhof](https://community.homey.app/u/Brian_Monninkhof)\
**Post date:** [January 4, 2025, 8:59pm UTC](https://community.homey.app/t/denon-avr-get-volume-state-zone-2/126448/8 "2025-01-04T20:59:13Z")

</div>

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.
