Script to play Radio 2 on Marantz M-CR610 amplifier using LMS?

I have a Marantz M-CR610 which is recognised as a media_player by HA, courtesy of the DLNA/UPnP LMS plugin.
I have a Favourite set up in LMS to play Radio 2 Live - this is the URL that gets used if I click on this Favourite to play Radio 2 on the Marantz:

http://192.168.1.36:9000/plugins/Favorites/index.html?sess=1&index=2&player=bb%3Abb%3A8f%3A34%3Ae8%3Ac6player=bb:bb:8f:34:e8:c6

Can anyone advise on how this can be converted to an HA script to do the same thing?

I have previously used this type of script to play a favourite, but when I try this (with a Favourite called “Radio 2 LIVE”) the syntax is not accepted

sequence:
  - data:
      entity_id: media_player.marantz_m_cr610
      command: favorites
      parameters:
        - playlist
        - play
        - Radio 2 LIVE
    action: squeezebox.call_method

You can’t play favorites by name - you need to use their id.

action: squeezebox.call_method
data:
  command: favorites
  parameters:
    - playlist
    - play
    - item_id:0

You can get the item ids from

action: squeezebox.call_query
data:
  command: favorites
  parameters:
    - items
    - 0
    - 10

This will give you the first 10 favorites for example, or if you want, you can do

action: squeezebox.call_query
data:
  command: favorites
  parameters:
    - items
    - 0
    - 10
    - "search: classic fm"

to search for a particular one. The item id returned will be something like id: aa134ee3.0. You can use the whole thing, or just the bit after the .
item_id:aa134ee3.0 and item_id:0 are the same.

I’ve got a PR open to add simplified search and play actions which will make this easier Add simplified actions for searching and playing to Squeezebox by peteS-UK · Pull Request #129858 · home-assistant/core. No progress on it of late, but fingers crossed. Doc PR is Add search and play action documentation for squeezebox integration by peteS-UK · Pull Request #35613 · home-assistant/home-assistant.io is you’re interested.

Thanks for the code. When I try to run it I get a message telling me that I need to have a target defined. I’ve tried adding my media_player as a target (see below) but got this error:

This action requires a target, please define a target 'entity_id', 'device_id', or 'area_id' under 'target:' or 'data:'

Any ideas??

action: squeezebox.call_query
target: media_player.marantz_m_cr610_2
data:
  command: favorites
  parameters:
    - items
    - 0
    - 10
action: squeezebox.call_query
data:
  command: favorites
  parameters:
    - items
    - 0
    - 10
target:
  entity_id: media_player.bathroom

Easiest way to test that stuff is to use the Developer Tools / Actions and then you can test things through the UI and check the yaml

Thanks - yes that’s what I’ve been doing, That command was executed, but I don’t see where the output is being written??

As per the doc Squeezebox (Lyrion Music Server) - Home Assistant, call_query writes its results to the ‘query_result’ attribute of the player.

This is my list of favourites from the LMS UI:

If I run this:

action: squeezebox.call_method
data:
  command: favorites
  parameters:
    - playlist
    - play
    - item_id:2
target: 
  entity_id: media_player.marantz_m_cr610_2

Nothing gets played on the selected media player (or any other media player that I try).
I’m guessing that favourites should be numbered from 0 upwards, so I don’t understand why this command doesn’t work
???

What’s the result of the query? Have tried doing this from developer tools/actions. Does that list the marantz as available for call_method - I assume it must be else you’d be getting an error

Anything in the log? If not, turn on the debug log, run the command turn it off again - the log is very chatty so just look at the time you’re running the command and see if there’s anything there.

I enabled “Debug connection” in Debug tools, then ran this command:

action: squeezebox.call_method
data:
  command: favorites
  parameters:
    - playlist
    - play
    - item_id:2
target: 
  entity_id: media_player.marantz_m_cr610_2

There was no error, but nothing played on the media_player, and there was no entry in either the home assistant log or the squeezeboxserver log.

OK - as before, what’s in the query response. Also, when you say nothing in the HA log, there is surely lots of stuff in there - the integration is very chatty. Maybe no errors, but you should be seeing lots of messages

Sorry - where can I find the query response? I can’t see this anywhere in the Actions section of the Developer UI.

There is literally nothing in the HA log relating to the squeezebox command that I’m executing. Thousands of ZHA log entries, but nothing for squeezebox.

EDIT: Ooops sorry there was a single line:

WARNING (MainThread) [homeassistant.helpers.service] Referenced entities media_player.marantz_m_cr610 are missing or not currently available

I get the same message whichever media player I try

I’ve also just noticed that in the States page of the HA UI I can see the list of favourites for media_player.marantz_m_cr610:

group_members: 
query_result: 
title: Favorites
loop_loop:
  - id: 5ba5c646.0
    name: On mysqueezebox.com
    image: html/images/favorites.png
    isaudio: 0
    hasitems: 1
  - id: 5ba5c646.1
    name: Random songs
    type: audio
    image: plugins/RandomPlay/html/images/icon.png
    isaudio: 1
    hasitems: 0
  - id: 5ba5c646.2
    name: Radio 2 LIVE
    type: audio
    image: >-
      /imageproxy/https%3A%2F%2Fsounds.files.bbci.co.uk%2F3.5.0%2Fnetworks%2Fbbc_radio_two%2Fblocks-colour_600x600.png/image.png
    isaudio: 1
    hasitems: 0
  - id: 5ba5c646.3
    name: Songs - random
    type: audio
    image: plugins/DynamicPlaylists4/html/images/dpl_icon_svg.png
    isaudio: 1
    hasitems: 0
count: 4

…which seems to confirm that (a) the media player is known to HA, and (b) favourute #2 is valid

Aahh…I think I’ve stumbled upon the solution. I reloaded the LMS integration and that command now works on my media player. Must’ve been a glitch with the integration.
Many thanks for your help with this.

yes, it’s an attribute of the player - like any of the states - is it on or off, what’s it playing etc. So, States is an easy place to see it.

ok. good to know. it was defo something odd

Hmmm…maybe not quite…when I turn this into a script:

sequence:
  - action: squeezebox.call_method
    metadata: {}
    data:
      command: favorites
      parameters: playlist
        - playlist
        - play
        - item_id:2
    target:
      entity_id: media_player.marantz_m_cr610

It doesn’t work - I get this error in the HA log:

INFO (MainThread) [denonavr.input] No mapping for source Media Server found

no idea what that means - it’s from the denonavr integration i think.