I only recently discovered Squeezebox/Logitech Media Server, and have built a piCoreplayer/server with a Raspberry Pi (and have two PCs using Squeezelite-X for players). Fun and highly recommended! I’ve been playing with how to integrate them into HA today, and figured out how to create some automations after a lot of trial and error, so I thought I’d share. The documentation about the API that can be found at http://HOST:PORT/html/docs/cli-api.html?player=
is a bit obtuse, but now that I have a start I can continue on from here.
I’m using my Magic Cube as a trigger in the following automations because it was an easy way to test what I was doing, but you can obviously use whatever you want. I’m going to get some NFC tags to play with soon.
Example automation that plays a local playlist called “My Local Playlist”:
alias: SQ Play Local Playlist
trigger:
platform: event
event_type: deconz_event
event_data:
id: mi_magic_cube
event: 2000 # slide side 2 up
action:
- service: squeezebox.call_method
data:
entity_id: media_player.picoreplayer
command: 'playlist'
parameters:
- play
- 'My Local Playlist'
Automation to pause the player (this acts like a toggle-if I pause the player, I can slide the cube another time to start it playing again):
alias: SQ pause toggle
trigger:
platform: event
event_type: deconz_event
event_data:
id: mi_magic_cube
event: 6000 # slide side 6 up
action:
- service: squeezebox.call_method
data:
entity_id: media_player.picoreplayer
command: 'pause'
This service call lists the first 20 playlists and shows the extid tag, which is needed for Spotify (or other external) playlists. You can see the info in the media player’s attribute query
.
service: squeezebox.call_query
data:
entity_id: media_player.picoreplayer
command: playlists
parameters:
- '0'
- '20'
- 'tags:E'
One entry extracted from the query attribute looks like this (this one is fake):
- id: 29753 playlist: 'Spotify: My Great Playlist' extid: 'spotify:playlist:48wQfF1DX9wR2KY45plZ'
Example automation that plays a Spotify playlist, whose big long id I got from the service call above:
alias: SQ Play My Spotify Playlist
trigger:
platform: event
event_type: deconz_event
event_data:
id: mi_magic_cube
event: 4000 # slide side 4 up
action:
- service: squeezebox.call_method
data:
entity_id: media_player.picoreplayer
command: 'playlist'
parameters:
- play
- 'spotify:playlist:48wQfF1DX9wR2KY45plZ'
This is just the tip of the iceberg, and may seem simplistic, but it wasn’t obvious to me at first how to even get started. I hope it gives someone else a bit of a start on how to use the API with HA.