Yeah, I just worked that one out a minute ago lol.
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
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
Thank you guys for trying to help me, really appreciate it!
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
Maybe it is time to build a workaround for that in Yamaha (YNCA) instead.