Skip to content

Commit

Permalink
Add possiblity to switch HDMI outputs on and off on Yamaha receivers
Browse files Browse the repository at this point in the history
  • Loading branch information
fragger42 committed Jul 27, 2021
1 parent fa699b8 commit 0d04867
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 1 deletion.
6 changes: 6 additions & 0 deletions bundles/org.openhab.binding.yamahareceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Zone control channels are:
| `zone_channels#surroundProgram` | `String` | Sets the surround mode. Examples: `2ch Stereo`, `7ch Stereo`, `Hall in Munic`, `Straight`, `Surround Decoder`. |
| `zone_channels#scene` | `String` | Sets the scene. Examples: `Scene 1`, `Scene 2`, `Scene 3`, `Scene 4`. Write only (state updates are not available). May not be supported on all models (e.g. RX-V3900). |
| `zone_channels#dialogueLevel` | `Number` | Sets the receivers dialogue level. May not be supported on all models. |
| `zone_channels#hdmi1Out` | `Number` | Switches the HDMI1 Output ON or OFF (channel in desc.xml is placed in Main_Zone but in fact it is more some kind of system parameter). May not be supported on all models. |
| `zone_channels#hdmi2Out` | `Number` | Switches the HDMI2 Output ON or OFF (channel is desc.xml is placed in Main_Zone but in fact it is more some kind of system parameter). May not be supported on all models. |
| `playback_channels#preset` | `Number` | Set a preset. Not supported by `Spotify` input. For `NET RADIO` input there is no way to get current preset (tested on RX-S601D, RX-V3900), so the preset is write only. For RX-V3900 the presets are alphanumeric `A1`,`A2`,`B1`,`B2` thus you need to use numbers grater than 100 that represent these presets as follows: 101, 102, 201, 202. |
| `playback_channels#playback` | `String` | Set a play mode or get the current play mode. Values supported: `Previous`, `Play`, `Pause`, `Stop`, `Next`. Applies for inputs which support playback (`Spotify`, `SERVER`, `NET RADIO`, `Bluetooth`). Note that some values may not be supported on certain input type and AVR model combination. For `Spotify` and `Bluetooth` all values work, but for `NET RADIO` input only `Play` and `Stop` are supported (tested on RX-S601D). |
| `playback_channels#playback_station` | `String` | Get the current played station (radio). Applies to `TUNER` and `NET RADIO` inputs only. |
Expand Down Expand Up @@ -134,6 +136,8 @@ String Yamaha_Input "Input [%s]" <video>
String Yamaha_Surround "Surround [%s]" <video> { channel="yamahareceiver:zone:96a40ba9:Main_Zone:zone_channels#surroundProgram" }
String Yamaha_Scene "Scene []" <video> { channel="yamahareceiver:zone:96a40ba9:Main_Zone:zone_channels#scene" }
Switch Yamaha_Dialogue_Level "Dialogue Level [%d]" <soundvolume> { channel="yamahareceiver:zone:96a40ba9:Main_Zone:zone_channels#dialogueLevel" }
Switch Yamaha_HDMI1_Output "HDMI1 Output [%s]" <switch> { channel="yamahareceiver:zone:96a40ba9:Main_Zone:zone_channels#hdmi1Out" }
Switch Yamaha_HDMI2_Output "HDMI2 Output [%s]" <switch> { channel="yamahareceiver:zone:96a40ba9:Main_Zone:zone_channels#hdmi2Out" }
Switch Yamaha_PartyMode "Party mode [%s]" <switch> { channel="yamahareceiver:yamahaAV:96a40ba9:party_mode" }
Switch Yamaha_PartyModeMute "Party mode mute [%s]" <soundvolume_mute> { channel="yamahareceiver:yamahaAV:96a40ba9:party_mode_mute" }
Expand All @@ -150,6 +154,8 @@ Selection item=Yamaha_Input mappings=[HDMI1="Kodi",HDMI2="PC",AUDIO
Selection item=Yamaha_Surround mappings=["2ch Stereo"="2ch Stereo","5ch Stereo"="5ch Stereo","Chamber"="Chamber","Sci-Fi"="Sci-Fi","Adventure"="Adventure"]
Switch item=Yamaha_Scene mappings=["Scene 1"="Kodi","Scene 2"="TV","Scene 3"="NET","Scene 4"="Radio"]
Setpoint item=Yamaha_Dialogue_Level minValue=0 maxValue=2 step=1
Switch item=Yamaha_HDMI1_Output
Switch item=Yamaha_HDMI2_Output
Switch item=Yamaha_PartyMode
Switch item=Yamaha_PartyModeMute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class YamahaReceiverBindingConstants {
public static final String CHANNEL_MUTE = "mute";
public static final String CHANNEL_SCENE = "scene";
public static final String CHANNEL_DIALOGUE_LEVEL = "dialogueLevel";
public static final String CHANNEL_HDMI1OUT = "hdmi1Out";
public static final String CHANNEL_HDMI2OUT = "hdmi2Out";

public static final String CHANNEL_PARTY_MODE = "party_mode";
public static final String CHANNEL_PARTY_MODE_MUTE = "party_mode_mute";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ public void handleCommand(ChannelUID channelUID, Command command) {
zoneControl.setDialogueLevel(((DecimalType) command).intValue());
break;

case CHANNEL_HDMI1OUT:
zoneControl.setHDMI1Out(((OnOffType) command) == OnOffType.ON);
break;

case CHANNEL_HDMI2OUT:
zoneControl.setHDMI2Out(((OnOffType) command) == OnOffType.ON);
break;

case CHANNEL_NAVIGATION_MENU:
if (inputWithNavigationControl == null) {
logger.warn("Channel {} not working with {} input!", id, zoneState.inputID);
Expand Down Expand Up @@ -491,6 +499,10 @@ private void refreshFromState(ChannelUID channelUID) {
// no state updates available
} else if (id.equals(grpZone(CHANNEL_DIALOGUE_LEVEL))) {
updateState(channelUID, new DecimalType(zoneState.dialogueLevel));
} else if (id.equals(grpZone(CHANNEL_HDMI1OUT))) {
updateState(channelUID, zoneState.hdmi1Out ? OnOffType.ON : OnOffType.OFF);
} else if (id.equals(grpZone(CHANNEL_HDMI2OUT))) {
updateState(channelUID, zoneState.hdmi2Out ? OnOffType.ON : OnOffType.OFF);

} else if (id.equals(grpPlayback(CHANNEL_PLAYBACK))) {
updateState(channelUID, new StringType(playInfoState.playbackMode));
Expand Down Expand Up @@ -536,6 +548,8 @@ public void zoneStateChanged(ZoneControlState msg) {
updateState(grpZone(CHANNEL_VOLUME), new PercentType((int) zoneConfig.getVolumePercentage(zoneState.volumeDB)));
updateState(grpZone(CHANNEL_MUTE), zoneState.mute ? OnOffType.ON : OnOffType.OFF);
updateState(grpZone(CHANNEL_DIALOGUE_LEVEL), new DecimalType(zoneState.dialogueLevel));
updateState(grpZone(CHANNEL_HDMI1OUT), zoneState.hdmi1Out ? OnOffType.ON : OnOffType.OFF);
updateState(grpZone(CHANNEL_HDMI2OUT), zoneState.hdmi2Out ? OnOffType.ON : OnOffType.OFF);

// If the input changed
if (inputChanged) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ public interface ZoneControl extends IStateUpdatable {

void setDialogueLevel(int level) throws IOException, ReceivedMessageParseException;

/**
* Switches the HDMI1 output on or off.
*
* @param on The new state
*
* @throws IOException
* @throws ReceivedMessageParseException
*/
void setHDMI1Out(boolean on) throws IOException, ReceivedMessageParseException;

/**
* Switches the HDMI2 output on or off.
*
* @param on The new state
*
* @throws IOException
* @throws ReceivedMessageParseException
*/
void setHDMI2Out(boolean on) throws IOException, ReceivedMessageParseException;

/**
* Sets the active scene for the zone.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConstants.*;
import static org.openhab.binding.yamahareceiver.internal.protocol.xml.XMLConstants.*;
import static org.openhab.binding.yamahareceiver.internal.protocol.xml.XMLConstants.Commands.*;
import static org.openhab.binding.yamahareceiver.internal.protocol.xml.XMLProtocolService.getZoneResponse;
import static org.openhab.binding.yamahareceiver.internal.protocol.xml.XMLProtocolService.*;
import static org.openhab.binding.yamahareceiver.internal.protocol.xml.XMLUtils.*;

import java.io.IOException;
Expand Down Expand Up @@ -77,7 +77,15 @@ public class ZoneControlXML implements ZoneControl {
protected CommandTemplate dialogueLevel = new CommandTemplate(
"<Sound_Video><Dialogue_Adjust><Dialogue_Lvl>%d</Dialogue_Lvl></Dialogue_Adjust></Sound_Video>",
"Sound_Video/Dialogue_Adjust/Dialogue_Lvl");
protected CommandTemplate hdmi1Out = new CommandTemplate(
"<System><Sound_Video><HDMI><Output><OUT_1>%s</OUT_1></Output></HDMI></Sound_Video></System>",
"System/Sound_Video/HDMI/Output/OUT_1");
protected CommandTemplate hdmi2Out = new CommandTemplate(
"<System><Sound_Video><HDMI><Output><OUT_2>%s</OUT_2></Output></HDMI></Sound_Video></System>",
"System/Sound_Video/HDMI/Output/OUT_2");
protected boolean dialogueLevelSupported = false;
protected boolean hdmi1OutSupported = false;
protected boolean hdmi2OutSupported = false;

public ZoneControlXML(AbstractConnection con, Zone zone, YamahaZoneConfig zoneSettings,
ZoneControlStateListener observer, DeviceInformationState deviceInformationState,
Expand Down Expand Up @@ -118,6 +126,12 @@ protected void applyModelVariations() {
logger.debug("Zone {} - the {} channel is not supported on your model", getZone(), CHANNEL_DIALOGUE_LEVEL);
}

hdmi1OutSupported = zoneDescriptor.hasCommandEnding("Sound_Video,HDMI,Output,OUT_1", () -> logger
.debug("Zone {} - the {} channel is not supported on your model", getZone(), CHANNEL_HDMI1OUT));

hdmi2OutSupported = zoneDescriptor.hasCommandEnding("Sound_Video,HDMI,Output,OUT_2", () -> logger
.debug("Zone {} - the {} channel is not supported on your model", getZone(), CHANNEL_HDMI2OUT));

// Note: Detection for RX-V3900, which uses <Vol> instead of <Volume>
if (zoneDescriptor.hasCommandEnding("Vol,Lvl")) {
volume = volume.replace("Volume", "Vol");
Expand Down Expand Up @@ -153,6 +167,10 @@ protected void sendCommand(String message) throws IOException {
comReference.get().send(XMLUtils.wrZone(zone, message));
}

protected void sendCommandWithoutZone(String message) throws IOException {
comReference.get().send(message);
}

/**
* Return the zone
*/
Expand Down Expand Up @@ -253,6 +271,24 @@ public void setDialogueLevel(int level) throws IOException, ReceivedMessageParse
update();
}

@Override
public void setHDMI1Out(boolean on) throws IOException, ReceivedMessageParseException {
if (!hdmi1OutSupported) {
return;
}
sendCommandWithoutZone(hdmi1Out.apply(on ? ON : OFF));
update();
}

@Override
public void setHDMI2Out(boolean on) throws IOException, ReceivedMessageParseException {
if (!hdmi2OutSupported) {
return;
}
sendCommandWithoutZone(hdmi2Out.apply(on ? ON : OFF));
update();
}

@Override
public void setScene(String scene) throws IOException, ReceivedMessageParseException {
if (!sceneSelSupported) {
Expand Down Expand Up @@ -290,6 +326,12 @@ public void update() throws IOException, ReceivedMessageParseException {
throw new ReceivedMessageParseException("Expected inputID. Failed to read Input/Input_Sel");
}

Node node = getResponse(comReference.get(), hdmi1Out.apply(GET_PARAM), hdmi1Out.getPath());
state.hdmi1Out = node != null && ON.equals(node.getTextContent());

node = getResponse(comReference.get(), hdmi2Out.apply(GET_PARAM), hdmi2Out.getPath());
state.hdmi2Out = node != null && ON.equals(node.getTextContent());

// Some receivers may use Src_Name instead?
value = getNodeContentOrEmpty(statusNode, inputSelNamePath);
state.inputName = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public class ZoneControlState {
public float volumeDB = 0.0f; // volume in dB
public boolean mute = false;
public int dialogueLevel = 0;
public boolean hdmi1Out = false;
public boolean hdmi2Out = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
<channel id="volume" typeId="volume"/>
<channel id="volumeDB" typeId="volumeDB"/>
<channel id="dialogueLevel" typeId="dialogueLevel"/>
<channel id="hdmi1Out" typeId="hdmi1Out"/>
<channel id="hdmi2Out" typeId="hdmi2Out"/>
<channel id="mute" typeId="mute"/>
<channel id="scene" typeId="scene"/>
</channels>
Expand Down Expand Up @@ -230,6 +232,20 @@
<category>SoundVolume</category>
<state min="0" max="2" step="1" pattern="%d"/>
</channel-type>

<channel-type id="hdmi1Out">
<item-type>Switch</item-type>
<label>HDMI1 Output</label>
<description>Switch the HDMI1 Output ON/OFF</description>
<category>switch</category>
</channel-type>

<channel-type id="hdmi2Out">
<item-type>Switch</item-type>
<label>HDMI2 Output</label>
<description>Switch the HDMI2 Output ON/OFF</description>
<category>switch</category>
</channel-type>

<channel-type id="scene">
<item-type>String</item-type>
Expand Down

0 comments on commit 0d04867

Please sign in to comment.