Media_player.play_media as a button

Hi all,

Trying to create som buttons in my UI to play local radiostations, I get it working by using the developer tools/service-command using media_player.play_media and the following data:

entity_id: media_player.livingroom_speaker
media_content_type: audio/mp3
media_content_id: 'https://http-live.sr.se/p4stockholm-mp3-192'

When I try to add it as a button in lovelace however it seems the syntax is different, with the following setup I get an error saying Failed to call service media_player/play_media required key not provided @data[‘media_content_id’]

type: button
tap_action:
  action: call-service
  service: media_player.play_media
  entity_id: media_player.livingroom_speaker
  data:
    media_content_type: audio/mp3
    media_content_id: 'https://http-live.sr.se/p4stockholm-mp3-192'
icon: 'mdi:radio'
name: SR P3
entity: media_player.livingroom_speaker

Any suggestions? Seems do have declared the media-content id, but maybe I’ve made a mistake with the indentation or something?

1 Like

For a lovelace tap action you need to use service_data instead of data and you probably also need to put the entity_id in the service_data block,but I’m not sure on this one.

2 Likes

That did it! You were correct on both accounts. Thanks!