Denon&Marantz binding ZONE4 operation

Hello Everyone!
I’m new to openhub and I have an issue with Denon&Marantz binding configuration. My Marantz model supports 4 zones and in my configuration I use only main and 4th zone. There is no possibility to change the way devices are connected. Binding supports 1-3 zones, so I can’t operate on zone 4 but commands are simmilar to zones. For example command “PWZ2” could be changed to “PWZ4” and I would have Zone 4 operational instead of zone 2. How can I modify this binding? I am using openhab 2.5.2 via PaperUI.

Best regards!

Welcome to the Community!

Check the github link below for more info on binding development:

@H102 Thank you for your reply!

Now I see that I need to edit .jar file but which one? :wink: I have found a lot of files for “marantz” keyword. Can you help me which one is a full denon/marantz binding? I would like to use this code but change zone2 into zone4 and compile it without any other changes.

Hello once again,

I would like to edit only one class DenonMarantzConnector.java
Here is correct code for me. I changed it to send for zone4 instead of zone3. Can somebody help to compile it?

Find fileCopy path

/**

  • Copyright © 2010-2020 Contributors to the openHAB project
  • See the NOTICE file(s) distributed with this work for additional
  • information.
  • This program and the accompanying materials are made available under the
  • terms of the Eclipse Public License 2.0 which is available at
  • http://www.eclipse.org/legal/epl-2.0
  • SPDX-License-Identifier: EPL-2.0
    */
    package org.openhab.binding.denonmarantz.internal.connector;

import static org.openhab.binding.denonmarantz.internal.DenonMarantzBindingConstants.DB_OFFSET;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.concurrent.ScheduledExecutorService;

import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.IncreaseDecreaseType;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.PercentType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.RefreshType;
import org.openhab.binding.denonmarantz.internal.DenonMarantzState;
import org.openhab.binding.denonmarantz.internal.UnsupportedCommandTypeException;
import org.openhab.binding.denonmarantz.internal.config.DenonMarantzConfiguration;

/**

  • Abstract class containing common functionality for the connectors.

  • @author Jan-Willem Veldhuis - Initial contribution
    */
    public abstract class DenonMarantzConnector {

    private static final BigDecimal POINTFIVE = new BigDecimal(“0.5”);
    protected ScheduledExecutorService scheduler;
    protected DenonMarantzState state;
    protected DenonMarantzConfiguration config;

    public abstract void connect();

    public abstract void dispose();

    protected abstract void internalSendCommand(String command);

    public void sendCustomCommand(Command command) throws UnsupportedCommandTypeException {
    String cmd;
    if (command instanceof StringType) {
    cmd = command.toString();
    } else {
    throw new UnsupportedCommandTypeException();
    }
    internalSendCommand(cmd);
    }

    public void sendInputCommand(Command command, int zone) throws UnsupportedCommandTypeException {
    String zonePrefix;
    switch (zone) {
    case 1:
    zonePrefix = “SI”;
    break;
    case 2:
    case 3:
    zonePrefix = “Z4”;
    break;
    default:
    throw new UnsupportedCommandTypeException("Zone must be in range [1-3], zone: " + zone);
    }
    String cmd = zonePrefix;
    if (command instanceof StringType) {
    cmd += command.toString();
    } else if (command instanceof RefreshType) {
    cmd += “?”;
    } else {
    throw new UnsupportedCommandTypeException();
    }
    internalSendCommand(cmd);
    }

    public void sendSurroundProgramCommand(Command command) throws UnsupportedCommandTypeException {
    String cmd = “MS”;
    if (command instanceof RefreshType) {
    cmd += “?”;
    } else {
    throw new UnsupportedCommandTypeException();
    }
    internalSendCommand(cmd);
    }

    public void sendMuteCommand(Command command, int zone) throws UnsupportedCommandTypeException {
    if (zone < 1 || zone > 3) {
    throw new UnsupportedCommandTypeException("Zone must be in range [1-3], zone: " + zone);
    }
    StringBuilder sb = new StringBuilder();
    if (zone != 1) {
    sb.append(“Z”).append(zone);
    }
    sb.append(“MU”);
    String cmd = sb.toString();
    if (command == OnOffType.ON) {
    cmd += “ON”;
    } else if (command == OnOffType.OFF) {
    cmd += “OFF”;
    } else if (command instanceof RefreshType) {
    cmd += “?”;
    } else {
    throw new UnsupportedCommandTypeException();
    }
    internalSendCommand(cmd);
    }

    public void sendPowerCommand(Command command, int zone) throws UnsupportedCommandTypeException {
    String zonePrefix;
    switch (zone) {
    case 0:
    zonePrefix = “PW”;
    break;
    case 1:
    zonePrefix = “ZM”;
    break;
    case 2:
    case 3:
    zonePrefix = “Z4”;
    break;
    default:
    throw new UnsupportedCommandTypeException("Zone must be in range [0-3], zone: " + zone);
    }
    String cmd = zonePrefix;
    if (command == OnOffType.ON) {
    cmd += “ON”;
    } else if (command == OnOffType.OFF) {
    cmd += (zone == 0) ? “STANDBY” : “OFF”;
    } else if (command instanceof RefreshType) {
    cmd += “?”;
    } else {
    throw new UnsupportedCommandTypeException();
    }
    internalSendCommand(cmd);
    }

    public void sendVolumeCommand(Command command, int zone) throws UnsupportedCommandTypeException {
    String zonePrefix;
    switch (zone) {
    case 1:
    zonePrefix = “MV”;
    break;
    case 2:
    case 3:
    zonePrefix = “Z4”;
    break;
    default:
    throw new UnsupportedCommandTypeException("Zone must be in range [1-3], zone: " + zone);
    }
    String cmd = zonePrefix;
    if (command instanceof RefreshType) {
    cmd += “?”;
    } else if (command == IncreaseDecreaseType.INCREASE) {
    cmd += “UP”;
    } else if (command == IncreaseDecreaseType.DECREASE) {
    cmd += “DOWN”;
    } else if (command instanceof DecimalType) {
    cmd += toDenonValue(((DecimalType) command));
    } else if (command instanceof PercentType) {
    cmd += percentToDenonValue(((PercentType) command).toBigDecimal());
    } else {
    throw new UnsupportedCommandTypeException();
    }
    internalSendCommand(cmd);
    }

    public void sendVolumeDbCommand(Command command, int zone) throws UnsupportedCommandTypeException {
    Command dbCommand = command;
    if (dbCommand instanceof PercentType) {
    throw new UnsupportedCommandTypeException();
    } else if (dbCommand instanceof DecimalType) {
    // convert dB to ‘normal’ volume by adding the offset of 80
    dbCommand = new DecimalType(((DecimalType) command).toBigDecimal().add(DB_OFFSET));
    }
    sendVolumeCommand(dbCommand, zone);
    }

    protected String toDenonValue(DecimalType number) {
    String dbString = String.valueOf(number.intValue());
    BigDecimal num = number.toBigDecimal();
    if (num.compareTo(BigDecimal.TEN) == -1) {
    dbString = “0” + dbString;
    }
    if (num.remainder(BigDecimal.ONE).equals(POINTFIVE)) {
    dbString = dbString + “5”;
    }
    return dbString;
    }

    protected String percentToDenonValue(BigDecimal pct) {
    // Round to nearest number divisible by 0.5
    BigDecimal percent = pct.divide(POINTFIVE).setScale(0, RoundingMode.UP).multiply(POINTFIVE)
    .min(config.getMainVolumeMax()).max(BigDecimal.ZERO);

     return toDenonValue(new DecimalType(percent));
    

    }
    }

Hi Pawel. I will create an updated binding with official support for Zone 4 soon. I created this issue to track: https://github.com/openhab/openhab-addons/issues/7197
Follow the issue for updates, will get back to you to test as I do not own a receiver with 4 zones :wink:

Thank you! I look forward to it and I will do the tests with plessure :wink:

Hi Pawel, please test the following: https://openhab.jfrog.io/openhab/libs-pullrequest-local/org/openhab/addons/bundles/org.openhab.binding.denonmarantz/2.5.4-SNAPSHOT/org.openhab.binding.denonmarantz-2.5.4-SNAPSHOT.jar
Uninstall the current and put this in your addons folder.
I don’t have a device with 4 zones myself.

Hi!
First of all once again many many thanks for helping me!

Little change that needs to be made is label under zone count:

UPDATE:

Another label:

Channels “Power (zone)” and " Input Source" works perfectly in both ways (AV recieves commands and changes done manually on AV updates in PaperUI).

Channels Volume and Mute are not supported on my AV. Volume of zone 4 is controlled by zone 4 reciever. I’m not sure if it is the same on other Denon/Marantz models. Here is how official zone 4 http control looks like:

47l

We can assume that job is done! I hope I will be able to help somehow in revange :slight_smile:
Best regards!

1 Like

Thanks for testing this immediately Paweł! I’ll fix the descriptions.