Logitech Squeezebox - examples of how to use the API in HA

Try this

entity_id: media_player.{{ states('input_select.chromecast_radio_station') }}
2 Likes

Hi guys.
Actually I try to map some functions of my squeezeboxes to zigee remotes. Works good so far, but i have one annoying problem.
I dont understand how to use the button command for volume_up / volume_down, to increase or decrease the volume.
Can someone give me an example of this function?


service: squeezebox.call_method
target:
  entity_id: media_player.{{states.input_select.lms_player.state}}
data:
  command: mixer
  parameters:
    - volume
    - "{{states.input_number.lms_volume.state}}"

3 Likes

Thanks a lot. Was a good Idea, solved my problem.

For those interested, this is how I call the random mix

service: squeezebox.call_query
data:
  command: randomplay
  parameters:
    - tracks
target:
  entity_id: media_player.name
2 Likes

Spent a while today trying to figure out how to play a specific album…took a bit of testing to figure out how to specify the parameters. The documentation for the CLI under “Playlist Commands and Queries” says

<playerid> playlist loadalbum <genre> <artist> <album>

The "playlist loadalbum" command puts songs matching the specified genre artist and album criteria on the playlist. Songs previously in the playlist are discarded.

Examples:

Request: "04:20:00:12:23:45 playlist loadalbum Rock Abba *<LF>"
Response: "04:20:00:12:23:45 playlist loadalbum Rock Abba *<LF>"

This is the format of the automation action that works for me:

action:
  - service: squeezebox.call_method
    data:
      entity_id: media_player.picoreplayer
      command: playlist
      parameters:
        - loadalbum
        - Rock # genre
        - Eagles # artist
        - 'The Very Best Of' # album
  - service: squeezebox.call_method
    data:
      entity_id: media_player.picoreplayer
      command: playlist
      parameters:
        - play
mode: single

The loadalbum command clears the queue and adds the album specified; there is also an addalbum command to append to the bottom of the queue without changing what is already there.

Hope that’s helpful to someone :slight_smile:

2 Likes

Hi everyone,

How can I query the status of the player?
Better said, I want to know which players are currently running.

1 Like

@Anwen Thank you so much for your examples. I finally managed to start a Spotify-playlist with the Spotty-plugin in LMS from Home Assistant. For me the media_content_id changed daily when I used media_player.play_media.

1 Like

Thanks for posting, the information has been very useful in terms of automating some of my audio.

Just wondering if anyone knows how to play a podcast episode via cli. I tried with a link but it plays one particular podcast episode where I want to play the latest episode only.

Thanks again for the info provided.

Here is an example: (it’s a dutch podcast)

 - platform: command_line
   name: Latest vroege vogels
   scan_interval: 7200
   command: curl -k -s https://podcast.npo.nl/feed/vroegevogels.xml | grep -E -o 'https?://[^"]+mp3' | uniq | head -n 1

This sensor gives me the url to the latest (weekly) podcast.
You can than make an automation to play it when you press an input button or whatever trigger you want.

- id: '1655028732393'
  alias: vroege vogels auto
  description: ''
  trigger:
  - platform: state
    entity_id:
    - input_button.vroege_vogels
  condition: []
  action:
  - service: media_player.play_media
    data:
      entity_id: media_player.radio_keuken
      media_content_id: "{{ states('sensor.laatste_vroege_vogels') }}"
      media_content_type: music

I have combined examples from others to what works for me. Perhaps there is still room for improvement and I would like to hear about it.
Hope it’s usefull to you.

1 Like

Wow, thanks man. There is no way I would have figured that out. I’ll give that a try for sure. Thanks so much for that.

Thanks, but unfortunately I cannot locate the podcast on an RSS / XML page or on a webpage with a link anywhere. I can see it in apple podcasts, within LMS and on a webpage for the latest episode, but nothing I can ‘scrape’ to get the link.

When i search for “www.abc.net.au podcast xml latest news” i get a few options.
Is this wat you are looking for?

https://www.abc.net.au/feeds/101858056/podcast.xml

btw if i’ts not a ‘real’ podcast that you can download an listen offline there isn’t an api and verry difficult to get a usable link.

1 Like

Yes… I think I have found the link there. Thanks for that.

Did you fixt this?

I was trying to do the same, but now i get the next error in my logs:
Error while executing automation automation.radio_zenders: not a valid value for dictionary value @ data[‘entity_id’]

Offcourse i changed my sensor name in to the “input_select” name that i’m using


entity_id: media_player.{{ states('input_select.chromecast_radio_station') }}

Thanks for the quick reply Kabala.
It’s working now, don’t know why it wasn’t working with the “entity_id”. Probaly to tired yesterday.
But one thing i do know, it isn’t working over here with the “item_id” number.
I do see the “id” numbers, but they would not work. I have to use the name of the playlist it self and then its working.

Working:

{% if is_state('input_select.radio_zenders', 'Veronica') %} 
 ["play", "Radio Veronica"] 

Not working:

{% if is_state('input_select.radio_zenders', 'Veronica') %}
["playlist", "play", "item_id:43"]

Also did try to change “item_id” with “id” and also did between " "

And if i send the “service call Query” i do get this:

query_result:
  playlists_loop:
    - playlist: Radio Veronica
      id: 43

this is my script for the radio stations in lms as a favorite

service: squeezebox.call_method
target:
  entity_id: media_player.{{states.input_select.lms_player.state}}
data:
  command: favorites
  parameters: >
    {% if is_state('input_select.chromecast_radio_station', 'ProFM') %}
      ["playlist", "play", "item_id:0"]
    {% elif is_state('input_select.chromecast_radio_station', 'KissFM') %}
      ["playlist", "play", "item_id:1"]
    {% elif is_state('input_select.chromecast_radio_station', 'EuropaFM') %}
      ["playlist", "play", "item_id:2"]
    {% elif is_state('input_select.chromecast_radio_station', 'RadioZu') %}
      ["playlist", "play", "item_id:3"]
    {% elif is_state('input_select.chromecast_radio_station', 'DigiFM') %}
      ["playlist", "play", "item_id:4"]
    {% elif is_state('input_select.chromecast_radio_station', 'MagicFM') %}
      ["playlist", "play", "item_id:5"]
    {% elif is_state('input_select.chromecast_radio_station', 'VirginRadio') %}
      ["playlist", "play", "item_id:6"]
    {% elif is_state('input_select.chromecast_radio_station', 'RadioPetrecere')
    %}
      ["playlist", "play", "item_id:7"]
    {% elif is_state('input_select.chromecast_radio_station', 'NationalFM') %}
      ["playlist", "play", "item_id:8"]
    {% elif is_state('input_select.chromecast_radio_station', 'WefunkRadio') %}
      ["playlist", "play", "item_id:9"]
    {% elif is_state('input_select.chromecast_radio_station', 'FunkyRadio') %}
      ["playlist", "play", "item_id:10"]
    {% elif is_state('input_select.chromecast_radio_station',
    'RadioFunkyThrills') %}
      ["playlist", "play", "item_id:11"]
    {% elif is_state('input_select.chromecast_radio_station', 'Bayern1') %}
      ["playlist", "play", "item_id:12"]
    {% elif is_state('input_select.chromecast_radio_station', 'Bayern3') %}
      ["playlist", "play", "item_id:13"]
    {% elif is_state('input_select.chromecast_radio_station', 'Charivari') %}
      ["playlist", "play", "item_id:14"]
    {% elif is_state('input_select.chromecast_radio_station', 'Energy') %}
      ["playlist", "play", "item_id:15"]
    {% elif is_state('input_select.chromecast_radio_station', 'AntenneBayern')
    %}
      ["playlist", "play", "item_id:16"]
    {% elif is_state('input_select.chromecast_radio_station', 'RadioMedias') %}
      ["playlist", "play", "item_id:17"]
    {% endif %}

That is not working here, this is mine. Only i did put mine in a automation:

alias: Radio Zenders
description: ""
trigger:
  - platform: state
    entity_id:
      - input_select.radio_zenders
  - platform: state
    entity_id:
      - input_select.speaker
condition: []
action:
  - service: squeezebox.call_method
    data_template:
      entity_id: media_player.{{ states('input_select.speaker') }}
      command: playlist
      parameters: |
        {% if is_state('input_select.radio_zenders', 'Veronica') %}
          ["play", "Radio Veronica"]
        {% elif is_state('input_select.radio_zenders', 'Veronica Rock') %}
          ["play", "Veronica Rock Hits Top 500"]
        {% elif is_state('input_select.radio_zenders', 'SLAM!') %}
          ["play", "SLAM!"]
        {% elif is_state('input_select.radio_zenders', 'Radio 538') %}
          ["play", "Radio 538"]
        {% elif is_state('input_select.radio_zenders', 'KINK') %}
          ["play", "KINK"]
        {% elif is_state('input_select.radio_zenders', '3FM') %}
          ["play", "3FM"]
        {% elif is_state('input_select.radio_zenders', 'Omrop Fryslân') %}
          ["play", "Omrop Fryslan"]
        {% endif %}
mode: single

Hi Anwen,
Is this still working at your end?
I used your code but with some other artist and album. The current playlist gets reset but nothing new added.
Is the Genre required or can I just leave it away?

Thanks,

Merc

Edit: got the album adding working but strange enough the playlist play command does not start the music. It is basically sitting there with the new album and not starting to play. Any idea?

Edit 2: used a different method and finalised it to what I actually wanted to do.
With this automation you can ask voice assistant to play an album by a specific artist on a specific music player.

alias: "Assist: Play music on Squeezebox"
description: Play music on Squeezebox
trigger:
  - platform: conversation
    command:
      - Play {album} by {artist} in {player}
    enabled: true

action:
  - service: squeezebox.call_method
    data:
      command: playlist
      parameters:
        - addalbum
        - ""
        - "{{trigger.slots.artist}}"
        - "{{trigger.slots.album}}"
    target:
      entity_id: media_player.{{trigger.slots.player}}
  - service: media_player.media_play
    data: {}
    target:
      entity_id: media_player.{{trigger.slots.player}}
mode: single
2 Likes