Media_player: how to automate playback (which can successfully be initiated manually)

Hi everybody,

I am trying to create a “Christmas Mode” for my media_player.living_room, which is a Sony Songpal device. According to the docs, this is capable of anything media player services can do.

When I click on the entity, then “browse media” (or similar, my UI is in German), I am able to browse Plex > Music > Recommended > Recently Added > “Some Album” and click play. Music will play from the entity, as expected.

While this is playing, the entity will report

device_class: speaker
friendly_name: Living Room
supported_features: 152463
volume_level: 0.4099999964237213
is_volume_muted: false
media_position_updated_at: 2022-12-07T09:25:18.267110+00:00
app_id: 9AC194DC
app_name: Plex
media_content_id: /library/metadata/109855
media_content_type: music
media_duration: 293
media_position: 8
media_title: Home Alone Main Title (Somewhere in My Memory)
media_artist: John Williams
media_album_name: Home Alone
media_album_artist: John Williams

I assumed that I could write a script like this

  weihnachtsmusik:
    icon: "phu:christmas-wreath"
    alias: "Weihnachtsmusik Wohnzimmer"
    description: "Spiele Weihnachtsmusik im Wohnzimmer"
    sequence:
      - service: media_player.play_media
        data:
          media_content_id: /library/metadata/109855
          media_content_type: music
          announce: true
        target:
          entity_id: media_player.living_room

This is the same media_content_id and media_content_type as the entity reports when I manually start it. However, when I run this script, nothing will happen.

I noticed there is also an app_id and app_name reported by the state; however, I cannot pass these values to the script. When I manually do so, it will state that these additional arguments.

In developer-tools > service

service: media_player.play_media
data:
  media_content_id: /library/metadata/109855
  media_content_type: music
  enqueue: play
target:
  entity_id: media_player.living_room

This will actually stop playback when something is already playing on that speaker (but not play anything at all). When nothing is playing and I run this, nothing will change.

But this test below states Fehler beim Aufrufen des Diensts media_player.play_media. extra keys not allowed @ data['app_id']. Got None

service: media_player.play_media
data:
  media_content_id: /library/metadata/109855
  media_content_type: music
  enqueue: play
  app_id: CC1AD845 # <<< added this
target:
  entity_id: media_player.living_room

So what do I need to do in order to automate playing a particular album / song / whatever on my media player?

I was not able to use the songpal tool to find any additional information, because the script won’t work on my device. Hopefully, I can do this with media_player.play_media alone though…?

Thank you in advance for your help :slight_smile: