Get Media ID from player and use as triger

Hi all,

Is there a way to get the tittle or name of the media that is currently playing on a media player?
I would like to use specific media as a trigger.

Thanks for the help!
kind regards,

kevin

yes, the easiest way is to create a template_sensor that will retrieve the media_player’s attribute

Hi, thanks for the response.
are thee docs related of how i could implement t in the template?

Open the States page and find your media_player in the list. Look at the right-hand column showing your player’s attributes. You’ll find attributes like media_title and media_author.

Let’s say you want to do something when media_title is “Best Jazz”. You can create a Template Binary Sensor that indicates on whenever the title is “Best Jazz”. You can then create an automation that is triggered whenever the binary_sensor is on and then proceeds to perform an action.

Alternately, you create an automation that is triggered directly by the media_title attribute using a Template Trigger.

1 Like

Try this:

- platform: template
  sensors:
    media_player_title:
      entity_id: media_player.house
      value_template: '{{((state_attr("media_player.house", "media_title")}}'
      friendly_name: Media Player Title

Replace house with the name of your media_player

1 Like

It works!

Thanks!

Follow up question,
Can i differentiate when music and when movies are played?

tnx for the help

Some media players have the ‘media_content_type’ attribute, which you would also have to create a template sensor for.

I know this is forever old, but this worked for me:

{{((state_attr("media_player.office_speaker", "media_title")))}}
1 Like