Yamaha Restful commands

Yeah, I just worked that one out a minute ago lol.

1 Like

The second part of my question regarded shuffling,

For shuffling, there’s no on|off command so you have to determine the current state and then use toggleShuffle if it’s off.

This puts the current shuffle state (of the receivers server mode) into sensor.shufflestate

In configuration.YAML:


sensor:

  - platform: rest
    name: shufflestate
    resource: Receiver_IP_address/YamahaExtendedControl/v1/netusb/getPlayInfo
    value_template: "{{ value_json.shuffle }}"
    scan_interval: 15
    json_attributes:
      - "shuffle”

This is the command to toggle shuffle in server mode, also in configuration.YAML


rest_command:
  toggle_shuffle:
    url: 'Receiver_IP_address/YamahaExtendedControl/v1/netusb/toggleShuffle'

And in scripts.YAML or automations.YAML, test the state and toggle if required.


toggle_shuffle:
alias: toggle_shuffle
 sequence:
  - if:
        condition: state
        entity_id: sensor.shufflestate
        state: "off"
    then:
        service: rest_command.toggle_shuffle

As of now I’m not sure if I can put a rest scan into a script and do it on demand, I’ll be refining this whole process anyway but it works for now

1 Like

In HA I can go to the control panel of my MusicCast device where I can select “browse media”. In the Library screen which now opens I can select “Presets”. And in the Presets screen I can now click on a preset which will start playing.

I now want to make a button with a shortcut to this Presets screen.

With PCAPdroid on my phone I figured out that {ip_address}/YamahaExtendedControl/v1/netusb/getPresetInfo is the place where I can find the presets.

But when I create a button in Lovelace with “Navigate” of “URL” I do not get the desired outcome.

After some googling I ended up here. It cost me two days before I had figured out the above, and with the information in this topic I have the feeling I am staring down yet another rabbit hole.

My programming / coding skills leave a lot to be desired. Some help with what I am trying to achieve would be greatly appreciated.

I don’t think it is possible to game a URL that goes directly to any of the browser media screens including the Presets one. If you don’t change your posts to often you can create buttons that will play desired preset by calling respective URL visa REST command directly on your Yamaha device.

Since you mention that you can browse the Presets from HA, maybe you can make an automation and trigger that from a button?

Just create an automation with just on action of the “Play media” type where you can select a mediaplayer and then browse the library. Then save it with a good name.

Now you can trigger it from a button by configuring the button with call-service action

This button works for me (and I created an automation called playmusic)

type: button
name: Trigger play music automation
tap_action:
  action: call-service
  service: automation.trigger
  data:
    skip_condition: true
  target:
    entity_id: automation.play_music

That is a good one, I’ve just noticed it is now explained in the documentation of musiccast integration how to play a preset:

service: media_player.play_media
target:
  entity_id: media_player.buro
data:
  media_content_id: "presets:1"
  media_content_type: "music"

https://www.home-assistant.io/integrations/yamaha_musiccast/#examples
I can get rid of my REST commands now :slight_smile:

Thank you guys for trying to help me, really appreciate it! :slight_smile:

I copied your code for the button and I made an automation called play music.

But when I create an action of the “play media” type with the visual editor I cannot just browse to the preset folder, I also must select a preset. So now I have a button that starts a preset instead of opening the presets screen.

This is the YAML code of the automation:

alias: play music
description: ""
trigger: []
condition: []
action:
  - service: media_player.play_media
    target:
      entity_id: media_player.bathroom
    data:
      media_content_id: presets:12
      media_content_type: track
    metadata:
      title: net_radio - VRT Studio Brussel (Brussels/Dutch)
      thumbnail: null
      media_class: track
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: directory
          media_content_id: presets
mode: single

How should I edit this to just open the presets screen?

It is not possible, as this screen does not have it’s own URL.

This seems like a simple ask to achieve but apparently not. So using the MusicCast or the Yamaha (YNCA) HACS integration I can easily add a button to my HA home screen to turn on/off the power to my Amps main or zone2.

However it seems impossible to assign this via an Automation, I want to use a real MQTT button to toggle the power on the Amp so non-techies can easily power on the device.

The home screen “button” code refs an ‘entity’ but when you try to perform an action on a ‘device’ the option to power on/off isn’t there.

show_name: true
show_icon: true
type: button
tap_action:
  action: toggle
entity: media_player.rx_v6a_zone2

Not sure if and how it will work on the multi zone device but it works ok on a musiccast device with a single zone. Anyway why don’t you just use individual entities? This is what works for me, so instead selecting a toggle action, chose the call service action with the media_player.toggle service:

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: media_player.toggle
  target:
    device_id: 2790086fb723e9bf713d0ae90890c06a
  data: {}
entity: media_player.szary_main

The code for the button card you posted works just fine for me, not sure what is not working for you.

Note that the media_player.toggle service does not work properly with some mediaplayers, it only turns on, not off depending on the state of the mediaplayer. This applies to mediaplayers that can have the state “idle”, for example the mediaplayers exposed by the Google Cast integration, the Yamaha (YNCA) integration which you mentioned and probably more.

I made a PR to get that fixed in Home Assistant, but it seems stuck :frowning:
Maybe it is time to build a workaround for that in Yamaha (YNCA) instead.

@adorobis - I need to do this for my RX-V3900 and have copied what you have done above, but more interested in volume control, on/off and zone control (and volume). Looking at the av-receiver-docs you posted I tried to do the volume control and ended up with this rest command:

yamaha_main_zone_vol:
  url: 'http://192.168.1.190/YamahaRemoteControl/ctrl'
  method: POST
  payload: '<?xml version="1.0" encoding="utf-8"?><YAMAHA_AV cmd="PUT"><Main_Zone><Volume><Lvl><Val>-34</Val></Lvl></Volume></Main_Zone></YAMAHA_AV>'

But when testing in developer tools, it gets an error 400

I have the Main zone on/off working

yamaha_main_zone_power_on:
  url: 'http://192.168.1.190/YamahaRemoteControl/ctrl'
  method: POST
  payload: '<?xml version="1.0" encoding="utf-8"?><YAMAHA_AV cmd="PUT"><Main_Zone><Power_Control><Power>On</Power></Power_Control></Main_Zone></YAMAHA_AV>'  

I get a 200 response

content: >-
  <YAMAHA_AV rsp="PUT"
  RC="0"><Main_Zone><Power_Control><Power></Power></Power_Control></Main_Zone></YAMAHA_AV>
status: 200

the XML for volume is:

<?xml version="1.0" encoding="utf-8"?>
 <YAMAHA_AV cmd="PUT">
  <Main_Zone>
   <Volume>
    <Lvl>
     <Val><!-- See values/volume.md --></Val>
     <Exp>1</Exp>
     <Unit>dB</Unit>
    </Lvl>
   </Volume>
  </Main_Zone>
 </YAMAHA_AV>

<!-- Receiver's answer: -->

<YAMAHA_AV rsp="PUT" RC="0">
 <Main_Zone>
  <Volume>
   <Lvl></Lvl>
  </Volume>
 </Main_Zone>
</YAMAHA_AV>

Any ideas what im doing wrong?

OK looks like my amp model is “special” and uses Vol where others use Volume. I think this is working - more testing to do:

yamaha_main_zone_vol:
  url: 'http://192.168.1.190/YamahaRemoteControl/ctrl'
  method: POST
  payload: '<?xml version="1.0" encoding="utf-8"?><YAMAHA_AV cmd="PUT"><Main_Zone><Vol><Lvl>-34</Lvl></Vol></Main_Zone></YAMAHA_AV>'

and Zone_2 in progress

yamaha_zone2_vol:
  url: 'http://192.168.1.190/YamahaRemoteControl/ctrl'
  method: POST
  payload: '<?xml version="1.0" encoding="utf-8"?><YAMAHA_AV cmd="PUT"><Zone_2><Vol>-34</Vol></Zone_2></YAMAHA_AV>' 

both are returning 200 now

Great to see you’ve found a solution :slight_smile: Basically for any feature that you can’t find documented XML you can use a network monitor tool (e.g. wireshark on a PC) and sniff the traffic from the web UI to the unit. Or alternative monitoring tool on a mobile phone and sniff the traffic from Yamaha AV controller app.

Actually it is in line with what has been discovered and documented in this repo:

Have you checked what’s already documented there?

Yep checked there and its missing quite a bit - no zone stuff. I found reference to more featuresd from the Openhab binding

Power on and off definately working but although im getting 200 responses the volume isnt increasing - so back to the testing with trial and error

In this case as suggested earlier just sniff the network traffic when executing those controls on the phone or on a pc with browser app (e.g. using wireshark application). You’ll be sure what exactly is being sent to the amp.

Ive done this and now have an xml response back

<YAMAHA_AV rsp="GET"
  RC="0"><Main_Zone><Basic_Status><Power_Control><Power>Standby</Power><Sleep>Off</Sleep></Power_Control><Vol><Lvl><Val>-390</Val><Exp>1</Exp><Unit>dB</Unit></Lvl><Mute>Off</Mute></Vol><Input><Input_Sel>DVD</Input_Sel><Input_Sel_Title>KODI</Input_Sel_Title></Input><Surr><Pgm_Sel><Straight>Off</Straight><Pgm>7ch
  Stereo</Pgm></Pgm_Sel></Surr></Basic_Status></Main_Zone></YAMAHA_AV>

I dont seem to be able to create a sensor that reads any of this

in configuration.yaml:

  - platform : rest
    resource: http://192.196.1.190/YamahaRemoteControl/ctrl
    method: POST
    payload: '<?xml version="1.0" encoding="utf-8"?><YAMAHA_AV cmd="GET"><Main_Zone><Basic_Status>GetParam</Basic_Status></Main_Zone></YAMAHA_AV>'
    scan_interval: 30
    name: Main_Zone_Power
    value_template: '{{ value_json.Main_Zone.Basic_Status.Power_Control.Sleep }}'   

Ive tried adding YAMAHA_AV to the json path like yours above with same result - no entity created for the sensor and a whole bunch of these in the log:

2024-11-06 15:19:04.207 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform rest is taking over 10 seconds.
2024-11-06 15:19:04.208 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform rest is taking over 10 seconds.
2024-11-06 15:19:04.211 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet; Retrying in background in 30 seconds
2024-11-06 15:19:04.211 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet; Retrying in background in 30 seconds

any ideas?

I don’t see anything wrong in your example. Have you tried running the curl from the HA to make sure that the receiver IP is accessible from there?
Here is the sample curl command: av-receiver-docs/curl_example.sh at 0c0289d73b175f5b1ead4e48712a2fdb7e994b05 · christianfl/av-receiver-docs · GitHub

Another hint: try to run the REST call from Postman app to verify that it actually works properly. I believe that the YAMAHA_AV is needed in the value_template as this is the top level tag in the XML returned.
Unfortunately I don’t have this receiver anymore so I can’t check if it still works.